jet / equinox

.NET event sourcing library with CosmosDB, DynamoDB, EventStoreDB, message-db, SqlStreamStore and integration test backends. Focused at stream level; see https://github.com/jet/propulsion for cross-stream projections/subscriptions/reactions
https://github.com/jet/dotnet-templates
Apache License 2.0
472 stars 68 forks source link

fix(Cache): Correct concurrent request coalescing #452

Closed bartelink closed 7 months ago

bartelink commented 7 months ago

Fixes the condition for the swap, which has a race condition that can mean delivering the value we've just literally determined to be too old Reduce a test timeout to hopefully reduce flakiness Also fixes an oversight: even if a concurrent request was too old for the maxAge, it can still serve as the base state for an incremental load (not a big deal in the normal case; only the very first load would be suboptimal)

bartelink commented 7 months ago

And yes, the tests should not be using Task.Delay to engineer overlaps and/or expirations. The more correct (and, in retrospect, obvious) approach is to maximise use of TimeProvider and/or events, in order to make them quicker, more deterministic and correct (would really appreciate a PR regarding that; it's unfortunately too far down my overall list of priorities at the moment...)