Keep each test database when the pool replaces its connection (closes #209)
check / check (push) Waiting to run
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. The new package internal/dbtest has NewURL. 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:
@@ -5,7 +5,6 @@
|
||||
package server_test
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -19,6 +18,7 @@ import (
|
||||
"sneak.berlin/go/neoirc/internal/broker"
|
||||
"sneak.berlin/go/neoirc/internal/config"
|
||||
"sneak.berlin/go/neoirc/internal/db"
|
||||
"sneak.berlin/go/neoirc/internal/dbtest"
|
||||
"sneak.berlin/go/neoirc/internal/globals"
|
||||
"sneak.berlin/go/neoirc/internal/handlers"
|
||||
"sneak.berlin/go/neoirc/internal/healthcheck"
|
||||
@@ -241,10 +241,7 @@ func newApp(
|
||||
stats.New,
|
||||
),
|
||||
fx.Decorate(func(cfg *config.Config) *config.Config {
|
||||
// A random name, so that no other test can share it.
|
||||
cfg.DBURL = fmt.Sprintf(
|
||||
"file:%s?mode=memory&cache=shared", rand.Text(),
|
||||
)
|
||||
cfg.DBURL = dbtest.NewURL(t)
|
||||
cfg.Port = port
|
||||
|
||||
return cfg
|
||||
|
||||
Reference in New Issue
Block a user