Run the conformance kit against your setup, test your failure handling, and keep concurrency tests deterministic.
Give the kit your migrations and, if your store doesn't use the default
configuration, a function that builds it for a path. Every check runs in its own
temporary directory with its own probe tables (sqliteswift_probe*), so it never
touches real data. One parameterized test reports each check separately:
import SQLiteSwiftTesting
import Testing
@Test(arguments: SQLiteConformanceKit.Check.allCases)
func conformance(check: SQLiteConformanceKit.Check) async {
let kit = SQLiteConformanceKit(migrations: MyStore.migrations) { path in
var configuration = SQLiteConfiguration(path: path)
configuration.readerCount = 2 // as your store opens it
return configuration
}
let result = await kit.run(check)
#expect(result.outcome == .passed, "\(result.notes)")
}| Check | What it shows |
|---|---|
migrations |
Migrations apply once and in order; a failing one rolls back alone. |
schemaTooNew |
A newer database is refused and left untouched. |
compareAndSetConflict |
Compare-and-set reports every result; of two concurrent updates exactly one wins. |
commitFailure |
A COMMIT rejected while the transaction is open is a typed error, not an unknown outcome. |
commitOutcome |
Reported outcomes match what is durable. |
busyContention |
A second database on the file gets .busy after its timeout, then succeeds. |
cancellationInterrupt |
Cancellation interrupts, rolls back and leaves the database usable. |
operationLimits |
Deadlines and instruction budgets stop work with typed errors and roll writes back. |
walCheckpoint |
Checkpoints copy every frame back; .truncate empties the WAL. |
recoveryAfterAbortedWrite |
A crash image taken mid-write recovers to the last commit. |
diskFull |
A full disk fails the write with .full and the database keeps working. |
settingsVerification |
The settings read back match the configuration. |
fileIdentity |
The file identity is written, accepted on reopen and enforced. |
A check that doesn't apply to your setup is SQLiteConformanceKit/Outcome/skipped(_:)
with the reason: the file-based checks on an in-memory database, and commitFailure
without foreignKeys. New checks can arrive in minor releases; a test over
SQLiteConformanceKit/Check/allCases picks them up.
An unknown commit outcome is rare in production and hard to provoke. Arm it with
SQLiteSwift/SQLiteDatabase/injectFault(_:): the next write that commits throws
commitOutcomeUnknown, and nothing of it is durable.
try await database.injectFault(.commitOutcomeUnknown)
let outcome = await database.writeReportingOutcome { tx throws(SQLiteError) in
try tx.execute("INSERT INTO inputs (key) VALUES (?)", [.text(key)])
}
guard case .unknown = outcome else { Issue.record("expected an unknown outcome"); return }
let stored = try await database.resolveCommit { tx throws(SQLiteError) in
try tx.queryOne("SELECT 1 FROM inputs WHERE key = ?", [.text(key)]) != nil
}
#expect(!stored)SQLiteTemporaryDirectorygives each test its own directory and removes it on deinit, so tests run in parallel without sharing files.SQLiteManualClockstands still until you move it. Set it asSQLiteConfiguration.clockto test expiry without waiting.SQLiteTestLatchholds a transaction open at a known point. The closure callsSQLiteTestLatch/blockingWait(timeout:); the test awaitsSQLiteTestLatch/waitUntilEntered(timeout:), does what it needs while the transaction is open, then callsSQLiteTestLatch/open(). Both waits are bounded, so a mistake fails the test instead of hanging it.
let latch = SQLiteTestLatch()
let holder = Task {
try await database.write { _ throws(SQLiteError) in latch.blockingWait() }
}
#expect(await latch.waitUntilEntered())
// The write lock is held here.
latch.open()
try await holder.valueSQLiteCrashImage/capture(databasePath:to:dropSharedMemory:)copies a database's files as a crash or power loss would leave them, so you can open the copy and check what survived.