Keep each test database when the pool replaces its connection (closes #209)
check / check (push) Waiting to run

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.

NewTestDatabaseURL in internal/db returns the URL of a new in-memory
database with a random name. It holds one connection to it open until
the test ends. The db, handlers, ircserver, server and service tests
now take their database URL from it.

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:29:04 +00:00
parent 53009cf9a0
commit 2673cd4ab2
8 changed files with 85 additions and 42 deletions
+1 -9
View File
@@ -3,7 +3,6 @@ package ircserver_test
import (
"bufio"
"context"
"crypto/rand"
"database/sql"
"errors"
"fmt"
@@ -107,14 +106,7 @@ func newTestEnvWithResolver(
) *testEnv {
t.Helper()
// A random name, so that no other test environment, not
// even an earlier run of the same test, can share it.
dsn := fmt.Sprintf(
"file:%s?mode=memory&cache=shared",
rand.Text(),
)
conn, err := sql.Open("sqlite", dsn)
conn, err := sql.Open("sqlite", db.NewTestDatabaseURL(t))
if err != nil {
t.Fatalf("open db: %v", err)
}