@@ -19,31 +19,25 @@ import (
1919 "github.com/authzed/spicedb/pkg/zedtoken"
2020)
2121
22- // readYourWritesIterations is how many times ReadYourWritesTest repeats its
23- // write-then-read sequence within a single run .
22+ // readYourWritesIterations is how many write-then-read rounds
23+ // ReadYourWritesTest runs .
2424const readYourWritesIterations = 50
2525
26- // ReadYourWritesTest asserts that a write is visible at the revision the API's
27- // consistency rules select for that write's own ZedToken.
26+ // ReadYourWritesTest asserts that a write is visible at the revision resolved
27+ // from its own ZedToken.
28+ // That is the path a permission check takes right after a write: the write's
29+ // revision becomes a token, the consistency middleware turns the token back
30+ // into a revision, and the data is read there.
2831//
29- // It walks the same path as a permission check issued immediately after a
30- // write: the revision the write returns is encoded into a ZedToken, the
31- // consistency middleware turns that token back into a revision, and the data
32- // is read at that revision.
33- // A datastore that resolves or serves that revision incorrectly loses
34- // read-your-writes for every caller that round-trips a ZedToken.
32+ // Both consistency modes that carry a token are covered:
3533//
36- // Both token-carrying consistency modes are covered:
34+ // - at_exact_snapshot resolves to the token's revision, so the read sees that
35+ // write and nothing later.
36+ // - at_least_as_fresh resolves to the token's revision or the optimized
37+ // revision, whichever is later, so the read never precedes the write.
3738//
38- // - at_exact_snapshot resolves to exactly the token's revision, so the read
39- // sees the world as of that write and nothing later.
40- // - at_least_as_fresh resolves to the later of the token's revision and the
41- // datastore's optimized revision, so the read never lands before the write.
42- //
43- // The sequence is repeated against one datastore, because the revision a write
44- // lands on depends on wall-clock timing, quantization boundaries and the
45- // datastore's own commit ordering: a single pass lands at one arbitrary offset
46- // into the quantization window and misses whatever the next offset exposes.
39+ // The sequence repeats because each pass lands at a different offset in the
40+ // quantization window, and one offset does not cover the others.
4741func ReadYourWritesTest (t * testing.T , tester DatastoreTester ) {
4842 // Quantization decides which half of at_least_as_fresh does the work.
4943 // With no window the optimized revision has already caught up to the write
@@ -184,34 +178,30 @@ func readYourWrites(t *testing.T, tester DatastoreTester, quantization time.Dura
184178// ReadYourConcurrentWritesTest keeps in flight at once.
185179const readYourConcurrentWritesWriters = 16
186180
187- // readYourConcurrentWritesRounds is how many times ReadYourConcurrentWritesTest
188- // repeats that concurrent round.
181+ // readYourConcurrentWritesRounds is how many times
182+ // ReadYourConcurrentWritesTest repeats that round.
189183const readYourConcurrentWritesRounds = 8
190184
191- // concurrentWrite is one writer's result from a round of
192- // ReadYourConcurrentWritesTest, recorded in the goroutine that made the write
193- // and asserted on afterwards by the test goroutine.
185+ // concurrentWrite is one writer's result, recorded in the goroutine that wrote
186+ // it and asserted on later by the test goroutine.
194187type concurrentWrite struct {
195188 rel tuple.Relationship
196189 rev datastore.Revision
197190 err error
198191}
199192
200- // ReadYourConcurrentWritesTest asserts that a write is visible at the revision
201- // its own ZedToken names when it was committed alongside other writes .
193+ // ReadYourConcurrentWritesTest asserts what ReadYourWritesTest does, for
194+ // writes that commit together .
202195//
203- // ReadYourWritesTest issues its writes one at a time, so each one is alone in
204- // whatever batch the datastore commits it in. A datastore that builds a
205- // revision out of a commit timestamp and then drops the tiebreaker ordering
206- // writes that share that timestamp still answers correctly there, because the
207- // tiebreaker is always zero. Keeping several writes in flight removes that
208- // condition: writes do share a commit timestamp, and the tiebreaker has to
209- // survive into the revision for the answers to stay right.
196+ // One write at a time never shares a commit timestamp, so a datastore that
197+ // drops the tiebreaker between writes at the same timestamp still answers
198+ // correctly there.
199+ // Keeping writes in flight makes them share a timestamp, so the tiebreaker has
200+ // to survive into the revision.
210201//
211- // The failure this catches is a lost read-your-writes. WriteRelationships
212- // returns a ZedToken whose revision sorts below the write it names, so a
213- // CheckPermission carrying that token cannot see the relationship the caller
214- // just wrote.
202+ // The failure it catches is a lost read-your-writes: the ZedToken names a
203+ // revision that sorts below the write it came from, so a check carrying that
204+ // token cannot see it.
215205func ReadYourConcurrentWritesTest (t * testing.T , tester DatastoreTester ) {
216206 req := require .New (t )
217207
0 commit comments