-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checksum tests #9
Conversation
@avinassh, Can you pls check this small PR once? Tests for the checksum operation! |
@@ -184,7 +183,7 @@ func (d *DiskStore) Delete(key string) error { | |||
|
|||
// mark as tombstone | |||
h.MarkTombStone() | |||
r := Record{Header: h, Key: key, Value: "", RecordSize: headerSize + h.KeySize + h.ValueSize} | |||
r := Record{Header: h, Key: key, Value: value, RecordSize: headerSize + h.KeySize + h.ValueSize} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey, did this cause a regression? Why did we change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No any regression. Just used the var defined on line 181:
value := ""
disk_store_test.go
Outdated
t.Errorf("invalid checksum: Got: %d, Want: %d", actualCheckSum, expectedCheckSum) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you tell me the intention behind this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added explicit tests to check for valid and invalid checksums both. Is it overkill?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, because I feel these are not doing anything. Can you think of a case where this test can help catch a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Updated.
disk_store_test.go
Outdated
|
||
// corrupt the record by overriding few bytes with corruptedBytes | ||
corruptedBytes := []byte{12, 90, 87, 101} | ||
start, end := 17, 21 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can avoid hard coding these and consider last 4 bytes
r3 := Record{Header: h3, Key: k3, Value: v3, RecordSize: headerSize + h3.KeySize + h3.ValueSize} | ||
r3.Header.CheckSum = r3.CalculateCheckSum() | ||
|
||
tests := []Record{r1, r2, r3} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 3 records? it seems all three iterations doing same thing and testing for same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considered 3 different records to test for different lengths of k,v pairs. Should I change to use only one k,v pair?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it is fine, I'd rather keep it 😅
No description provided.