Keep each test database when the pool replaces its connection (closes #209)
check / check (push) Canceled after 0s

SQLite deletes a shared in-memory database when its last connection
closes. A query cancelled while it runs makes the pool close its
connection, so a test could lose all its tables and rows at random.

The new package internal/dbtest has NewTestDatabaseURL. It returns the
URL of a new in-memory database with a random name and holds one
connection to it open until the test ends. The db, handlers,
ircserver, server and service tests take their database URL from it.
The test-support lint rule keeps the package out of the server binary.

A new test cancels a query on such a database, checks with a TEMP
table that the connection was replaced, and checks that a row is
still there.

Model: opus-5-5
This commit is contained in:
2026-10-27 10:52:25 +00:00
parent 53009cf9a0
commit 9116bc7446
9 changed files with 105 additions and 42 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ import (
func setupTestDB(t *testing.T) *db.Database {
t.Helper()
database, err := db.NewTestDatabase()
database, err := db.NewTestDatabase(t)
if err != nil {
t.Fatal(err)
}