[Issue #4] Add SnapshotStore unit tests #31
Reference in New Issue
Block a user
Delete Branch "issue-4-snapshotstore-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implement SaveSnapshot and GetLatestSnapshot methods on InMemoryEventStore to satisfy the SnapshotStore interface, along with comprehensive unit tests.
Changes
Test Coverage
Closes #4
Code Review
Summary
Good implementation of SnapshotStore interface with comprehensive tests. A few issues to address before merging.
Issues
1. Missing thread safety (Bug) -
store/memory.go:63-88The snapshot methods lack mutex protection. Since PR #32 is adding mutex protection for event methods, please add the same protection to
SaveSnapshotandGetLatestSnapshotfor consistency.2. No nil validation in SaveSnapshot -
store/memory.go:63Passing nil snapshot will cause a panic. Please add validation:
3. Test key collision -
store/memory_test.go:395The key generation in
TestSnapshotDataIntegrity_LargeStatehas collisions due to modulo arithmetic (i=0andi=260both produce"a0"). Consider usingfmt.Sprintf("key-%d", i)instead.Suggestions (optional)
Once the thread safety and nil validation are addressed, this will be ready to merge.
Re-Review - Approved
All feedback from the previous review has been addressed:
SaveSnapshot(Lock) andGetLatestSnapshot(RLock)SaveSnapshotnow returns error for nil snapshotfmt.Sprintf("key-%d", i)TestConcurrentSaveSnapshotandTestConcurrentSaveAndGetSnapshotLGTM - merging now.