-
-
Notifications
You must be signed in to change notification settings - Fork 94
Fix PostgreSQL read_stream_backwards guard clause and add backwards read tests #464
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
Fix PostgreSQL read_stream_backwards guard clause and add backwards read tests #464
Conversation
Co-authored-by: alexeyzimarev <2821205+alexeyzimarev@users.noreply.github.com>
|
@copilot Add tests to StoreReadTests (Eventuous.Tests.Persistence.Base.Store) for reading backwards that test with a legit position and reads some events, and with a position and count that would return nothing. Since StoreReadTests is abstract, find its implementations and add calls to the base class |
Co-authored-by: alexeyzimarev <2821205+alexeyzimarev@users.noreply.github.com>
Added backwards read tests to StoreReadTests base class in commit 5619006. The tests cover:
These tests are automatically inherited by PostgreSQL, SQL Server, and EventStore implementations via the [InheritsTests] attribute. |
Test Results 51 files + 34 51 suites +34 33m 24s ⏱️ + 23m 40s Results for commit 8d62403. ± Comparison against base commit a8ce44a. This pull request removes 5 and adds 30 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||||||
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
User description
The guard clause in
read_stream_backwardsincorrectly mixed page size with position validation, causing valid backwards reads to return empty results.Example of the bug:
if 10 < 10 + 3 then return;→ returns nothingChanges:
Replaced incorrect guard:
With proper validation matching SQL Server implementation (PR #431):
The function now correctly validates position bounds without conflating page size with position checks.
Tests Added:
Added comprehensive backwards read tests to the base
StoreReadTestsclass that are automatically inherited by all event store implementations (PostgreSQL, SQL Server, EventStore):ShouldReadBackwardsFromEnd: Tests reading backwards from the end of the stream with valid positionShouldReadBackwardsFromMiddle: Tests reading backwards from the middle of the stream with valid positionShouldReturnEmptyWhenReadingBackwardsFromBeyondStreamEnd: Tests that reading from position beyond stream head returns emptyShouldReturnEmptyWhenReadingBackwardsFromNegativePosition: Tests that reading from negative position returns emptyThese tests validate both the fix and ensure backwards reads work correctly across all implementations.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
PR Type
Bug fix, Tests, Enhancement
Description
Fix PostgreSQL
read_stream_backwardsguard clause validation logicAdd comprehensive backwards read tests to base
StoreReadTestsclassImprove error handling in SQL event store read operations
StreamReadPosition.EndReadFromStreamExceptionfor consistencyModernize test infrastructure in registration tests
WebHostBuilderwithHostBuilderandUseTestServer()Align SQL Server backwards read implementation with PostgreSQL fix
Diagram Walkthrough
File Walkthrough
Read.cs
Add comprehensive backwards read testssrc/Core/test/Eventuous.Tests.Persistence.Base/Store/Read.cs
ShouldThrowWhenReadingForwardsFromNegativePositiontest forforward reads with negative position
ShouldReadBackwardsFromEndtest validating backwards read fromstream end (position 9, count 3)
ShouldReadBackwardsFromMiddletest validating backwards readfrom middle (position 10, count 5)
ShouldReturnWhenReadingBackwardstest for reading beyond streamhead
ShouldThrowWhenReadingBackwardsFromNegativePositiontest forbackwards reads with negative position
5_ReadStreamBackwards.sql
Fix backwards read position validation logicsrc/Postgres/src/Eventuous.Postgresql/Scripts/5_ReadStreamBackwards.sql
validation
select s.stream_idtoselect s.version, s.stream_idtoproperly capture current version
_from_positionto_current_versionwhen positionexceeds stream head
_current_version < _from_position +_countwith proper bounds checks6_ReadStreamForwards.sql
Add negative position validationsrc/Postgres/src/Eventuous.Postgresql/Scripts/6_ReadStreamForwards.sql
5_ReadStreamBackwards.sql
Align backwards read with PostgreSQL implementationsrc/SqlServer/src/Eventuous.SqlServer/Scripts/5_ReadStreamBackwards.sql
to current version
clarity
@from_position = @current_versionwhen positionexceeds stream head
SqlEventStoreBase.cs
Add input validation and improve error handlingsrc/Relational/src/Eventuous.Sql.Base/SqlEventStoreBase.cs
StreamReadPosition.EndinReadEventsmethodReadEventsBackwardsmethodReadFromStreamExceptionRegistrationTests.cs
Modernize registration tests infrastructuresrc/Postgres/test/Eventuous.Tests.Postgres/Registrations/RegistrationTests.cs
WebHostBuilderwithHostBuilderandUseTestServer()Should_resolve_store_with_manual_registrationtestShould_resolve_store_with_extensionstestusingstatements for proper resource disposalRegistrationTests.cs
Modernize registration tests infrastructuresrc/SqlServer/test/Eventuous.Tests.SqlServer/Registrations/RegistrationTests.cs
WebHostBuilderwithHostBuilderandUseTestServer()Should_resolve_store_with_manual_registrationtestShould_resolve_store_with_extensionstestusingstatements for proper resource disposalCompositionHandlerTests.cs
Reduce visibility and clean up test classessrc/Core/test/Eventuous.Tests.Subscriptions/CompositionHandlerTests.cs
TestDependency.Valuefrom auto-property to expression-bodiedproperty
TestHandlerclass visibility from public to internalCompositionWrapperclass visibility from public to internalCompositionWrapperconstructor parameter frominnerHandlerto_(unused parameter)