Skip to content
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

Merged
merged 6 commits into from
Nov 9, 2023
Merged

Checksum tests #9

merged 6 commits into from
Nov 9, 2023

Conversation

PaulisMatrix
Copy link

@PaulisMatrix PaulisMatrix commented Nov 6, 2023

No description provided.

@PaulisMatrix
Copy link
Author

@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}
Copy link
Owner

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

Copy link
Author

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 := ""

t.Errorf("invalid checksum: Got: %d, Want: %d", actualCheckSum, expectedCheckSum)
}
}
}
Copy link
Owner

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

Copy link
Author

@PaulisMatrix PaulisMatrix Nov 9, 2023

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?

Copy link
Owner

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Updated.


// corrupt the record by overriding few bytes with corruptedBytes
corruptedBytes := []byte{12, 90, 87, 101}
start, end := 17, 21
Copy link
Owner

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}
Copy link
Owner

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

Copy link
Author

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?

Copy link
Owner

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 😅

@avinassh avinassh merged commit 3b4e8d9 into avinassh:final Nov 9, 2023
3 checks passed
@PaulisMatrix PaulisMatrix deleted the checksum-tests branch November 9, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants