test

package
v1.56.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 53 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RetainAllRevisions is a retention window large enough that every revision
	// written during a test stays readable for the whole test.
	RetainAllRevisions GCRetentionWindow = GCRetentionWindow(90000 * time.Second)

	// DisableBackgroundGC is a run interval large enough that the background GC
	// worker never ticks during a test. It does not extend revision validity;
	// it only prevents aged-out data from being deleted at an arbitrary moment.
	// Tests that need collection to happen call datastore.RunGarbageCollection
	// directly, at a deterministic point.
	DisableBackgroundGC GCRunInterval = GCRunInterval(90000 * time.Second)
)
View Source
const (
	GCCategory               = "GC"
	WatchCategory            = "Watch"
	WatchSchemaCategory      = "WatchSchema"
	WatchCheckpointsCategory = "WatchCheckpoints"
	StatsCategory            = "Stats"
	TransactionCategory      = "Transaction"
	// ConcurrentWriteCategory marks tests that open two write transactions concurrently.
	// Datastores with a global write lock (e.g. memdb) must exclude this category.
	ConcurrentWriteCategory = "ConcurrentWrite"
	// MigrationCategory marks tests that check that database migrations apply
	// successfully and preserve the data written before them.
	MigrationCategory = "Migration"
)

Variables

This section is empty.

Functions

func All

func All(t *testing.T, tester DatastoreTester)

All runs all generic datastore tests on a DatastoreTester.

func AllWithExceptions added in v1.24.0

func AllWithExceptions(t *testing.T, tester DatastoreTester, except Categories)

AllWithExceptions runs all generic datastore tests on a DatastoreTester, except those specified test categories

func BulkDeleteRelationshipsTest added in v1.30.0

func BulkDeleteRelationshipsTest(t *testing.T, tester DatastoreTester)

func BulkUploadAlreadyExistsErrorTest added in v1.31.0

func BulkUploadAlreadyExistsErrorTest(t *testing.T, tester DatastoreTester)

func BulkUploadAlreadyExistsSameCallErrorTest added in v1.31.0

func BulkUploadAlreadyExistsSameCallErrorTest(t *testing.T, tester DatastoreTester)

func BulkUploadEditCaveat added in v1.34.0

func BulkUploadEditCaveat(t *testing.T, tester DatastoreTester)

func BulkUploadErrorsTest added in v1.22.0

func BulkUploadErrorsTest(t *testing.T, tester DatastoreTester)

func BulkUploadTest added in v1.22.0

func BulkUploadTest(t *testing.T, tester DatastoreTester)

func BulkUploadWithCaveats added in v1.40.0

func BulkUploadWithCaveats(t *testing.T, tester DatastoreTester)

func BulkUploadWithExpiration added in v1.40.0

func BulkUploadWithExpiration(t *testing.T, tester DatastoreTester)

func CaseSensitivityTest added in v1.54.0

func CaseSensitivityTest(t *testing.T, tester DatastoreTester)

CaseSensitivityTest verifies that object IDs are treated as case-sensitive: resources and subjects that differ only in letter case are distinct relationships. This is a regression test for datastores whose default collation is case-insensitive (e.g. MySQL's latin1_swedish_ci), which would otherwise collide "Foo" with "foo".

func CaveatNotFoundTest added in v1.16.2

func CaveatNotFoundTest(t *testing.T, tester DatastoreTester)

CaveatNotFound tests to ensure that an unknown caveat returns the expected error.

func CaveatSnapshotReadsTest added in v1.14.0

func CaveatSnapshotReadsTest(t *testing.T, tester DatastoreTester)

func CaveatedRelationshipFilterTest added in v1.14.0

func CaveatedRelationshipFilterTest(t *testing.T, tester DatastoreTester)

func CaveatedRelationshipWatchTest added in v1.14.0

func CaveatedRelationshipWatchTest(t *testing.T, tester DatastoreTester)

func CheckRevisionsTest added in v1.35.0

func CheckRevisionsTest(t *testing.T, tester DatastoreTester)

func ConcurrentRevisionsTest added in v1.29.1

func ConcurrentRevisionsTest(t *testing.T, tester DatastoreTester)

ConcurrentRevisionsTest asserts that concurrent calls to HeadRevision move the revision forward

func ConcurrentWriteDeadlockTest added in v1.55.0

func ConcurrentWriteDeadlockTest(t *testing.T, tester DatastoreTester)

ConcurrentWriteDeadlockTest reproduces https://github.com/authzed/spicedb/issues/3172: many concurrent WriteRelationships targeting the same resource object contend for the same locks and some backends (e.g. MySQL under SERIALIZABLE) abort transactions with a deadlock. The datastore's write retry loop must back off between attempts so the contending writers spread out; otherwise the retries keep re-colliding and exhaust the retry budget. Every writer must eventually succeed.

func ConcurrentWriteRevisionVisibilityTest added in v1.56.1

func ConcurrentWriteRevisionVisibilityTest(t *testing.T, tester DatastoreTester)

ConcurrentWriteRevisionVisibilityTest covers revision visibility when two write transactions overlap: transaction A opens first but is held open while transaction B starts and commits, and only then does A write and commit.

  • each transaction's write must be visible when reading at its own returned revision (read-your-writes)
  • when the two revisions are comparable, the later revision must see the earlier write, and the earlier revision must NOT see the later write
  • when the two revisions are concurrent (e.g. Postgres snapshots of overlapping transactions), neither write may be visible at the other's revision
  • the head revision must see every committed write

This test is safe even for datastores that serialize write transactions with a global lock (e.g. memdb): transaction A performs no reads or writes until transaction B has fully committed, so the two never contend for the write lock.

func ConcurrentWriteSerializationTest

func ConcurrentWriteSerializationTest(t *testing.T, tester DatastoreTester)

ConcurrentWriteSerializationTest uses goroutines and channels to deterministically set up a deadlocking dependency between exactly two transactions: one reads a set of resources and then writes, while a second writes an overlapping resource, so the backend must serialize (or abort and retry) one of them. The datastore must resolve the conflict and let both writes complete in bounded time. Unlike ConcurrentWriteDeadlockTest, which floods the same object with many uncoordinated writers to exercise the retry/backoff budget under heavy contention, this test orchestrates a single, precise read-then-write vs. write conflict via channels.

func CounterCaseSensitivityTest added in v1.54.0

func CounterCaseSensitivityTest(t *testing.T, tester DatastoreTester)

CounterCaseSensitivityTest verifies that relationship counter names are treated as case-sensitive: counters whose names differ only in letter case are distinct. Counter names are not constrained to lowercase by the API (unlike definition, relation, and caveat names), so this is a reachable regression test for datastores whose default collation is case-insensitive (e.g. MySQL's utf8mb4_0900_ai_ci), which would otherwise collide "casecounter" with "CaseCounter".

func CreateAlreadyExistingTest added in v1.12.0

func CreateAlreadyExistingTest(t *testing.T, tester DatastoreTester)

CreateAlreadyExistingTest tests creating a relationship twice.

func CreateDeleteTouchTest added in v1.24.0

func CreateDeleteTouchTest(t *testing.T, tester DatastoreTester)

CreateDeleteTouchTest tests writing a relationship, deleting it, and then touching it.

func CreateTouchDeleteTouchTest added in v1.24.0

func CreateTouchDeleteTouchTest(t *testing.T, tester DatastoreTester)

CreateTouchDeleteTouchTest tests writing a relationship, touching it, deleting it, and then touching it.

func DeleteAllDataTest added in v1.35.0

func DeleteAllDataTest(t *testing.T, tester DatastoreTester)

func DeleteAlreadyDeletedTest added in v1.12.0

func DeleteAlreadyDeletedTest(t *testing.T, tester DatastoreTester)

DeleteAlreadyDeletedTest tests the deletion of an already-deleted relationship.

func DeleteCaveatedTupleTest added in v1.30.0

func DeleteCaveatedTupleTest(t *testing.T, tester DatastoreTester)

DeleteCaveatedTupleTest tests deleting a relationship with a caveat.

func DeleteNotExistantTest added in v1.12.0

func DeleteNotExistantTest(t *testing.T, tester DatastoreTester)

DeleteNotExistantTest tests the deletion of a non-existant relationship.

func DeleteOneThousandIndividualInOneCallTest added in v1.30.0

func DeleteOneThousandIndividualInOneCallTest(t *testing.T, tester DatastoreTester)

DeleteOneThousandIndividualInOneCallTest tests deleting 1000 relationships, individually.

func DeleteRelationshipsTest

func DeleteRelationshipsTest(t *testing.T, tester DatastoreTester)

DeleteRelationshipsTest tests whether or not the requirements for deleting relationships hold for a particular datastore.

func DeleteRelationshipsWithVariousFiltersTest added in v1.30.0

func DeleteRelationshipsWithVariousFiltersTest(t *testing.T, tester DatastoreTester)

DeleteRelationshipsWithVariousFiltersTest tests deleting relationships with various filters.

func DeleteWithInvalidPrefixTest added in v1.40.0

func DeleteWithInvalidPrefixTest(t *testing.T, tester DatastoreTester)

DeleteWithInvalidPrefixTest tests deleting relationships with an invalid object prefix.

func DeleteWithLimitTest added in v1.30.0

func DeleteWithLimitTest(t *testing.T, tester DatastoreTester)

DeleteWithLimitTest tests deleting relationships with a limit.

func DeleteWithPrefixTest added in v1.44.0

func DeleteWithPrefixTest(t *testing.T, tester DatastoreTester)

DeleteWithPrefixTest tests deleting relationships with a prefix.

func EmptyNamespaceDeleteTest

func EmptyNamespaceDeleteTest(t *testing.T, tester DatastoreTester)

EmptyNamespaceDeleteTest tests deleting an empty namespace in the datastore.

func GCProcessRunTest added in v1.40.0

func GCProcessRunTest(t *testing.T, tester DatastoreTester)

GCProcessRunTest tests whether the custom GC process runs for the datastore. For datastores that do not have custom GC processes, will no-op. TODO: rewrite using synctest

func HeadRevisionSchemaHashTest added in v1.53.0

func HeadRevisionSchemaHashTest(t *testing.T, tester DatastoreTester)

HeadRevisionSchemaHashTest verifies that HeadRevision returns the correct schema hash after writing a stored schema, and that updating the schema changes the hash.

func InvalidReadsTest

func InvalidReadsTest(t *testing.T, tester DatastoreTester)

InvalidReadsTest tests whether or not the requirements for reading via invalid revisions hold for a particular datastore.

func LimitTest added in v1.21.0

func LimitTest(t *testing.T, tester DatastoreTester)

func MigrationTest added in v1.56.1

func MigrationTest(t *testing.T, tester DatastoreTester)

MigrationTest verifies every migration of the datastore engine, in order, against an empty, unmigrated database:

  1. Each migration is applied one at a time, verifying that it applies cleanly and that the recorded version advances to it.
  2. Once the datastore reaches the engine's verifiable migration (the earliest one the current code can operate against), SpiceDB's schema service is served against it and a schema is written and read back through the WriteSchema and ReadSchema APIs.
  3. Before each remaining migration a new schema is written; after the migration that schema must still be readable, verifying that each migration preserves the data written through the API before it.

func MixedWriteOperationsTest added in v1.40.0

func MixedWriteOperationsTest(t *testing.T, tester DatastoreTester)

MixedWriteOperationsTest tests a WriteRelationships call with mixed operations.

func MultipleReadsInRWTTest

func MultipleReadsInRWTTest(t *testing.T, tester DatastoreTester)

func NamespaceDeleteInvalidNamespaceTest added in v1.40.0

func NamespaceDeleteInvalidNamespaceTest(t *testing.T, tester DatastoreTester)

NamespaceDeleteInvalidNamespaceTest tests deleting an invalid namespace in the datastore.

func NamespaceDeleteNoRelationshipsTest added in v1.47.1

func NamespaceDeleteNoRelationshipsTest(t *testing.T, tester DatastoreTester)

func NamespaceDeleteTest

func NamespaceDeleteTest(t *testing.T, tester DatastoreTester)

NamespaceDeleteTest tests whether or not the requirements for deleting namespaces hold for a particular datastore.

func NamespaceMultiDeleteTest added in v1.14.0

func NamespaceMultiDeleteTest(t *testing.T, tester DatastoreTester)

func NamespaceNotFoundTest added in v1.16.2

func NamespaceNotFoundTest(t *testing.T, tester DatastoreTester)

NamespaceNotFoundTest tests to ensure that an unknown namespace returns the expected error.

func NamespaceWriteTest

func NamespaceWriteTest(t *testing.T, tester DatastoreTester)

NamespaceWriteTest tests whether or not the requirements for writing namespaces hold for a particular datastore.

func ObjectIDsTest added in v1.20.0

func ObjectIDsTest(t *testing.T, tester DatastoreTester)

func OnlyGCTests added in v1.40.0

func OnlyGCTests(t *testing.T, tester DatastoreTester)

func OptimizedRevisionSchemaHashTest added in v1.53.0

func OptimizedRevisionSchemaHashTest(t *testing.T, tester DatastoreTester)

OptimizedRevisionSchemaHashTest verifies that OptimizedRevision returns the correct schema hash after a schema has been written, and that the hash updates when the schema changes. This is critical for the stored-schema cache to be hit on the common consistency paths (MinimizeLatency / AtLeastAsFresh), which route through OptimizedRevision rather than HeadRevision.

func OrderedLimitTest added in v1.21.0

func OrderedLimitTest(t *testing.T, tester DatastoreTester)

func OrderingTest added in v1.21.0

func OrderingTest(t *testing.T, tester DatastoreTester)

func QuantizedRevisionStaysReadableTest added in v1.56.2

func QuantizedRevisionStaysReadableTest(t *testing.T, tester DatastoreTester)

QuantizedRevisionStaysReadableTest asserts that OptimizedRevision never hands out a revision that CheckRevision would reject, i.e. quantization must stay smaller than the GC retention window. TODO: rewrite using synctest

func QueryRelationshipsWithVariousFiltersTest added in v1.30.0

func QueryRelationshipsWithVariousFiltersTest(t *testing.T, tester DatastoreTester)

QueryRelationshipsWithVariousFiltersTest tests various relationship filters for query relationships.

func ReadYourConcurrentWritesTest added in v1.56.2

func ReadYourConcurrentWritesTest(t *testing.T, tester DatastoreTester)

ReadYourConcurrentWritesTest asserts what ReadYourWritesTest does, for writes that commit together.

One write at a time never shares a commit timestamp, so a datastore that drops the tiebreaker between writes at the same timestamp still answers correctly there. Keeping writes in flight makes them share a timestamp, so the tiebreaker has to survive into the revision.

The failure it catches is a lost read-your-writes: the ZedToken names a revision that sorts below the write it came from, so a check carrying that token cannot see it.

func ReadYourWritesTest added in v1.56.2

func ReadYourWritesTest(t *testing.T, tester DatastoreTester)

ReadYourWritesTest asserts that a write is visible at the revision resolved from its own ZedToken. That is the path a permission check takes right after a write: the write's revision becomes a token, the consistency middleware turns the token back into a revision, and the data is read there.

Both consistency modes that carry a token are covered:

  • at_exact_snapshot resolves to the token's revision, so the read sees that write and nothing later.
  • at_least_as_fresh resolves to the token's revision or the optimized revision, whichever is later, so the read never precedes the write.

The sequence repeats because each pass lands at a different offset in the quantization window, and one offset does not cover the others.

func ReadyStateWhenPausedTest added in v1.56.1

func ReadyStateWhenPausedTest(t *testing.T, tester DatastoreTester)

ReadyStateWhenPausedTest asserts that ReadyState fails within a bounded time once the datastore's backing store stops responding. It also asserts that the same call, passed through the ctxPrxy, is also bounded.

func RecreateRelationshipsAfterDeleteWithFilter added in v1.31.0

func RecreateRelationshipsAfterDeleteWithFilter(t *testing.T, tester DatastoreTester)

func RegisterMigrationTestConfig added in v1.56.1

func RegisterMigrationTestConfig(engineKey string, provider func(t *testing.T) string)

RegisterMigrationTestConfig registers a config provider for a datastore engine defined outside this repository, enabling MigrationTest for it. The provider returns the URI of an empty database that has had no migrations applied The engine must be migratable, registered in datastore.BuilderForEngine, and its datastore must implement datastore.EngineIdentifiable.

func RegisterRelationshipCountersInParallelTest added in v1.40.0

func RegisterRelationshipCountersInParallelTest(t *testing.T, tester DatastoreTester)

func RelationshipCaveatFilteringTest added in v1.43.0

func RelationshipCaveatFilteringTest(t *testing.T, tester DatastoreTester)

RelationshipCaveatFilteringTest tests filtering relationships by caveat.

func RelationshipCounterOverExpiredTest added in v1.40.0

func RelationshipCounterOverExpiredTest(t *testing.T, tester DatastoreTester)

func RelationshipCountersTest added in v1.34.0

func RelationshipCountersTest(t *testing.T, tester DatastoreTester)

func RelationshipCountersWithOddFilterTest added in v1.45.0

func RelationshipCountersWithOddFilterTest(t *testing.T, tester DatastoreTester)

func RelationshipExpirationTest added in v1.40.0

func RelationshipExpirationTest(t *testing.T, tester DatastoreTester)

RelationshipExpirationTest tests expiration on relationships.

func ResumeTest added in v1.21.0

func ResumeTest(t *testing.T, tester DatastoreTester)

func RetryTest added in v1.22.0

func RetryTest(t *testing.T, tester DatastoreTester)

func ReverseQueryCursorTest added in v1.35.0

func ReverseQueryCursorTest(t *testing.T, tester DatastoreTester)

func ReverseQueryFilteredOverMultipleValuesCursorTest added in v1.40.0

func ReverseQueryFilteredOverMultipleValuesCursorTest(t *testing.T, tester DatastoreTester)

func RevisionGCTest added in v1.18.0

func RevisionGCTest(t *testing.T, tester DatastoreTester)

RevisionGCTest makes sure revision GC takes place, revisions out-side of the GC window are invalid, and revisions inside the GC window are valid. TODO: rewrite using synctest if possible

func RevisionQuantizationTest

func RevisionQuantizationTest(t *testing.T, tester DatastoreTester)

RevisionQuantizationTest tests that revision quantization works correctly

func RevisionSerializationTest added in v1.14.0

func RevisionSerializationTest(t *testing.T, tester DatastoreTester)

RevisionSerializationTest tests whether the revisions generated by this datastore can be serialized and sent through the dispatch layer.

func SequentialRevisionsTest added in v1.29.1

func SequentialRevisionsTest(t *testing.T, tester DatastoreTester)

SequentialRevisionsTest asserts that calls to HeadRevision move the revision forward

func SimpleTest

func SimpleTest(t *testing.T, tester DatastoreTester)

SimpleTest tests whether or not the requirements for simple reading and writing of relationships hold for a particular datastore.

func SnapshotReadStabilityTest added in v1.56.2

func SnapshotReadStabilityTest(t *testing.T, tester DatastoreTester)

SnapshotReadStabilityTest asserts that the revision returned by OptimizedRevision behaves like a snapshot: reads at it are repeatable, and they never observe a write committed after it.

func StableNamespaceReadWriteTest added in v1.13.0

func StableNamespaceReadWriteTest(t *testing.T, tester DatastoreTester)

StableNamespaceReadWriteTest tests writing a namespace to the datastore and reading it back, ensuring that it does not change in any way and that the deserialized data matches that stored.

func StatsTest

func StatsTest(t *testing.T, tester DatastoreTester)

func StoredSchemaAssertHashPreconditionTest added in v1.54.0

func StoredSchemaAssertHashPreconditionTest(t *testing.T, tester DatastoreTester)

StoredSchemaAssertHashPreconditionTest verifies that WithSchemaHashPrecondition causes the datastore to abort the transaction if the stored schema hash does not match.

func StoredSchemaConcurrentSchemaWinsTest added in v1.54.0

func StoredSchemaConcurrentSchemaWinsTest(t *testing.T, tester DatastoreTester)

StoredSchemaConcurrentSchemaWinsTest verifies the safety invariant for concurrent schema and relationship writes: after a schema write commits, any relationship write carrying the old hash fails immediately. The mechanism differs by datastore:

  • Postgres/MySQL: the rel write holds FOR SHARE until commit; the schema write (FOR UPDATE) blocks until all in-flight rel writes release, so no rel write commits against a stale schema.
  • CRDB: FOR SHARE is best-effort under SERIALIZABLE isolation; correctness is provided by CRDB's serializable conflict detection at commit time instead of explicit locking.

func StoredSchemaLargeTest added in v1.53.0

func StoredSchemaLargeTest(t *testing.T, tester DatastoreTester)

StoredSchemaLargeTest generates a large schema (>2MB) with 4000 types, each having 20 relations, writes it, reads it back, and verifies the exact match.

func StoredSchemaMultipleRevisionsTest added in v1.53.0

func StoredSchemaMultipleRevisionsTest(t *testing.T, tester DatastoreTester)

StoredSchemaMultipleRevisionsTest writes multiple schema versions and verifies each revision can still be read independently.

func StoredSchemaNotFoundTest added in v1.53.0

func StoredSchemaNotFoundTest(t *testing.T, tester DatastoreTester)

StoredSchemaNotFoundTest tests that reading a stored schema when none exists returns ErrSchemaNotFound.

func StoredSchemaPhaseMigrationTest added in v1.53.0

func StoredSchemaPhaseMigrationTest(t *testing.T, tester DatastoreTester)

StoredSchemaPhaseMigrationTest tests reading and writing schema through all four schema mode phases, simulating a live migration from legacy to unified storage. Each phase creates a new DataLayer on the same underlying datastore. For phases 2-4, it first reads the schema written by the previous phase to verify continuity, then writes an updated schema and verifies the change is reflected.

func StoredSchemaReadInWriteTxMemoizedTest added in v1.54.0

func StoredSchemaReadInWriteTxMemoizedTest(t *testing.T, tester DatastoreTester)

StoredSchemaReadInWriteTxMemoizedTest verifies that, in new-read schema modes, ReadSchema called multiple times in the same write transaction returns consistent results.

func StoredSchemaReadWithinTransactionTest added in v1.53.0

func StoredSchemaReadWithinTransactionTest(t *testing.T, tester DatastoreTester)

StoredSchemaReadWithinTransactionTest tests that ReadStoredSchema works within a read-write transaction and sees the schema written in the same transaction.

func StoredSchemaRevisionTest added in v1.53.0

func StoredSchemaRevisionTest(t *testing.T, tester DatastoreTester)

StoredSchemaRevisionTest writes three schema versions, then reads all of them back (including older revisions after newer ones have been written) to verify that each revision returns the correct content.

func StoredSchemaStableTextTest added in v1.53.0

func StoredSchemaStableTextTest(t *testing.T, tester DatastoreTester)

StoredSchemaStableTextTest verifies that a schema with multiple namespaces and caveats produces stable text when definitions are sorted before generation, regardless of the initial ordering of definitions.

func StoredSchemaUpdateTest added in v1.53.0

func StoredSchemaUpdateTest(t *testing.T, tester DatastoreTester)

StoredSchemaUpdateTest tests that overwriting a stored schema replaces it completely.

func StoredSchemaViaDataLayerTest added in v1.54.0

func StoredSchemaViaDataLayerTest(t *testing.T, tester DatastoreTester)

StoredSchemaViaDataLayerTest exercises the DataLayer's ReadSchema inside write transactions in both legacy (ReadLegacyWriteLegacy) and new (ReadNewWriteNew) schema modes. In new mode, ReadSchema calls ReadStoredSchemaHash before fetching the full blob — a path not exercised by the raw-datastore tests above.

func StoredSchemaWriteReadTest added in v1.53.0

func StoredSchemaWriteReadTest(t *testing.T, tester DatastoreTester)

StoredSchemaWriteReadTest tests basic write and read of a stored schema, including both namespace and caveat definitions.

func StoredSchemaWriteSucceedsUnderRelWriteTrafficTest added in v1.54.0

func StoredSchemaWriteSucceedsUnderRelWriteTrafficTest(t *testing.T, tester DatastoreTester)

StoredSchemaWriteSucceedsUnderRelWriteTrafficTest verifies that a schema write can complete under continuous relationship write traffic. The DB's lock queue prevents starvation: once a FOR UPDATE (schema write) is queued, new FOR SHARE (rel write) requests queue behind it, so the schema write drains the current holders and proceeds in bounded time.

func TouchAlreadyExistingCaveatedTest added in v1.22.0

func TouchAlreadyExistingCaveatedTest(t *testing.T, tester DatastoreTester)

TouchAlreadyExistingCaveatedTest tests touching the caveat name.

func TouchAlreadyExistingTest added in v1.12.0

func TouchAlreadyExistingTest(t *testing.T, tester DatastoreTester)

TouchAlreadyExistingTest tests touching a relationship twice.

func TypedTouchAlreadyExistingTest added in v1.31.0

func TypedTouchAlreadyExistingTest(t *testing.T, tester DatastoreTester)

TypedTouchAlreadyExistingTest tests touching a relationship twice, when valid type information is provided.

func TypedTouchAlreadyExistingWithCaveatTest added in v1.31.0

func TypedTouchAlreadyExistingWithCaveatTest(t *testing.T, tester DatastoreTester)

TypedTouchAlreadyExistingWithCaveatTest tests touching the caveat context.

func UniqueIDTest added in v1.46.0

func UniqueIDTest(t *testing.T, tester DatastoreTester)

func UpdateRelationshipCounterTest added in v1.34.0

func UpdateRelationshipCounterTest(t *testing.T, tester DatastoreTester)

func UseAfterCloseTest added in v1.27.0

func UseAfterCloseTest(t *testing.T, tester DatastoreTester)

func VerifyUpdates added in v1.30.0

func VerifyUpdates(
	t *testing.T,
	require *require.Assertions,
	testUpdates [][]tuple.RelationshipUpdate,
	changes <-chan datastore.RevisionChanges,
	errchan <-chan error,
	expectDisconnect bool,
)

func VerifyUpdatesWithMetadata added in v1.38.0

func VerifyUpdatesWithMetadata(
	t *testing.T,
	require *require.Assertions,
	testUpdates []updateWithMetadata,
	changes <-chan datastore.RevisionChanges,
	errchan <-chan error,
	expectDisconnect bool,
)

func WatchCancelTest

func WatchCancelTest(t *testing.T, tester DatastoreTester)

WatchCancelTest tests whether or not the requirements for cancelling watches hold for a particular datastore.

func WatchEmissionStrategyTest added in v1.39.0

func WatchEmissionStrategyTest(t *testing.T, tester DatastoreTester)

func WatchEmitsCheckpointAfterWriteWithChangesTest added in v1.54.0

func WatchEmitsCheckpointAfterWriteWithChangesTest(t *testing.T, tester DatastoreTester)

WatchEmitsCheckpointAfterWriteWithChangesTest verifies that when a consumer asks for checkpoints, every revision returned by WriteRelationships must eventually be observable as a checkpoint.

func WatchObservesEveryReturnedRevisionTest added in v1.54.0

func WatchObservesEveryReturnedRevisionTest(t *testing.T, tester DatastoreTester)

WatchObservesEveryReturnedRevisionTest verifies this contract: if WriteRelationships returns revision X, a watch consumer eventually observes revision X on the watch stream — even when the write produced no actual changes (e.g., a TOUCH that exactly matches an existing relationship).

func WatchRelationshipsAndSchemaAndCheckpointsTest added in v1.54.0

func WatchRelationshipsAndSchemaAndCheckpointsTest(t *testing.T, tester DatastoreTester)

func WatchRelationshipsAndSchemaChangesTest added in v1.54.0

func WatchRelationshipsAndSchemaChangesTest(t *testing.T, tester DatastoreTester)

func WatchSchemaTest added in v1.29.0

func WatchSchemaTest(t *testing.T, tester DatastoreTester)

func WatchTest

func WatchTest(t *testing.T, tester DatastoreTester)

WatchTest tests whether or not the requirements for watching changes hold for a particular datastore.

func WatchWithDeleteTest added in v1.29.0

func WatchWithDeleteTest(t *testing.T, tester DatastoreTester)

func WatchWithExpirationTest added in v1.40.0

func WatchWithExpirationTest(t *testing.T, tester DatastoreTester)

func WatchWithMetadataTest added in v1.38.0

func WatchWithMetadataTest(t *testing.T, tester DatastoreTester)

func WatchWithTouchTest added in v1.22.0

func WatchWithTouchTest(t *testing.T, tester DatastoreTester)

func WriteAndReadInRWT added in v1.43.0

func WriteAndReadInRWT(t *testing.T, tester DatastoreTester)

func WriteCaveatedRelationshipTest added in v1.14.0

func WriteCaveatedRelationshipTest(t *testing.T, tester DatastoreTester)

func WriteDeleteWriteTest added in v1.12.0

func WriteDeleteWriteTest(t *testing.T, tester DatastoreTester)

WriteDeleteWriteTest tests writing a relationship, deleting it, and then writing it again.

func WriteReadDeleteCaveatTest added in v1.14.0

func WriteReadDeleteCaveatTest(t *testing.T, tester DatastoreTester)

Types

type Categories added in v1.24.0

type Categories map[string]struct{}

func WithCategories added in v1.24.0

func WithCategories(cats ...string) Categories

func (Categories) ConcurrentWrite added in v1.54.0

func (c Categories) ConcurrentWrite() bool

func (Categories) GC added in v1.24.0

func (c Categories) GC() bool

func (Categories) Migration added in v1.56.1

func (c Categories) Migration() bool

func (Categories) Stats added in v1.33.0

func (c Categories) Stats() bool

func (Categories) Transaction added in v1.43.0

func (c Categories) Transaction() bool

func (Categories) Watch added in v1.24.0

func (c Categories) Watch() bool

func (Categories) WatchCheckpoints added in v1.29.0

func (c Categories) WatchCheckpoints() bool

func (Categories) WatchSchema added in v1.29.0

func (c Categories) WatchSchema() bool

type DatastoreTester

type DatastoreTester interface {
	// New creates a new datastore instance for a single test.
	New(tb testing.TB, revisionParameters RevisionParameters, watchBufferLength uint16) (datastore.Datastore, error)
}

DatastoreTester provides a generic datastore suite a means of initializing a particular datastore.

func PausableTester added in v1.56.1

PausableTester grants a DatastoreTester the ability to create a pausable datastore, so that the suite's pause-dependent tests run instead of skipping. Engines whose backing store cannot be frozen are returned unchanged.

type DatastoreTesterFunc

type DatastoreTesterFunc func(tb testing.TB, revisionParameters RevisionParameters, watchBufferLength uint16) (datastore.Datastore, error)

func (DatastoreTesterFunc) New

func (f DatastoreTesterFunc) New(tb testing.TB, revisionParameters RevisionParameters, watchBufferLength uint16) (datastore.Datastore, error)

type GCRetentionWindow added in v1.56.1

type GCRetentionWindow time.Duration

GCRetentionWindow is how far into the past revisions remain readable.

Revisions older than it are rejected as stale, whether or not their data has actually been deleted yet. This is the knob that governs revision validity.

It is a defined type rather than a plain time.Duration so that it cannot be passed where a GCRunInterval is expected.

type GCRunInterval added in v1.56.1

type GCRunInterval time.Duration

GCRunInterval is how often the background GC worker wakes up to delete data that has aged out of the retention window.

It affects disk usage only: it never changes which revisions are readable. A datastore whose worker never ticks still rejects revisions older than its GCRetentionWindow, because validity is computed from the window and the current clock rather than from what has physically been deleted.

It is a defined type rather than a plain time.Duration so that it cannot be passed where a GCRetentionWindow is expected.

type PausableDatastoreTester added in v1.56.1

type PausableDatastoreTester interface {
	// NewPausable returns a datastore along with a function that freezes its
	// backing store. Nothing that runs concurrently with the suite may share that backing
	// store, since freezing it would stall those tests too.
	NewPausable(t testing.TB) (datastore.Datastore, PauseFunc)
}

type PauseFunc added in v1.56.1

type PauseFunc func(t testing.TB)

type RevisionParameters added in v1.56.1

type RevisionParameters struct {
	// Quantization is the boundary interval to which revisions are rounded.
	// Zero disables quantization.
	Quantization time.Duration

	// GCRunInterval is how often the background GC worker runs.
	GCRunInterval GCRunInterval

	// GCRetentionWindow is how far into the past revisions remain readable.
	GCRetentionWindow GCRetentionWindow
}

RevisionParameters configures the revision-related behavior of a datastore under test. Build one with DefaultRevisionParameters and override only what the test actually exercises.

func DefaultRevisionParameters added in v1.56.1

func DefaultRevisionParameters() RevisionParameters

DefaultRevisionParameters returns the parameters appropriate for a test that is not itself about revisions or garbage collection: quantization off, the background GC worker disabled, and every revision retained.

This keeps unrelated tests insulated from both sources of nondeterminism — a GC pass firing mid-test, and a revision going stale underneath an assertion.

func (RevisionParameters) WithGCRetentionWindow added in v1.56.1

func (rp RevisionParameters) WithGCRetentionWindow(window GCRetentionWindow) RevisionParameters

WithGCRetentionWindow returns a copy with the retention window set. Use this when the test needs revisions to go stale within its lifetime.

func (RevisionParameters) WithGCRunInterval added in v1.56.1

func (rp RevisionParameters) WithGCRunInterval(interval GCRunInterval) RevisionParameters

WithGCRunInterval returns a copy with the background GC run interval set. Use this only when the test asserts that the worker actually ran.

func (RevisionParameters) WithQuantization added in v1.56.1

func (rp RevisionParameters) WithQuantization(quantization time.Duration) RevisionParameters

WithQuantization returns a copy with the revision quantization set.

type TesterFactory added in v1.50.0

type TesterFactory struct {
	// contains filtered or unexported fields
}

TesterFactory creates DatastoreTesters with a known retryable error for use in RetryTest.

func NewTesterFactory added in v1.50.0

func NewTesterFactory(retryErr error) *TesterFactory

NewTesterFactory creates a TesterFactory with the given retryable error.

func (*TesterFactory) NewTester added in v1.50.0

func (f *TesterFactory) NewTester(tester DatastoreTester) DatastoreTester

NewTester wraps a DatastoreTester and adds a retryable error for use in RetryTest.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL