fix: use in-memory SQLite for handler tests to fix CI timeout #93

Merged
sneak merged 1 commits from fix/test-timeout-90 into main 2026-03-25 20:11:34 +01:00

View File

@@ -12,7 +12,6 @@ import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
@@ -64,12 +63,20 @@ func newTestServer(
) *testServer {
t.Helper()
dbPath := filepath.Join(
t.TempDir(), "test.db",
)
return newTestServerWith(t, 0, "", "")
}
dbURL := "file:" + dbPath +
"?_journal_mode=WAL&_busy_timeout=5000"
func newTestServerWith(
t *testing.T,
hashcashBits int,
operName, operPassword string,
) *testServer {
t.Helper()
dbURL := fmt.Sprintf(
"file:test_%p?mode=memory&cache=shared",
t,
)
var srv *server.Server
@@ -95,7 +102,9 @@ func newTestServer(
cfg.DBURL = dbURL
cfg.Port = 0
cfg.HashcashBits = 0
cfg.HashcashBits = hashcashBits
cfg.OperName = operName
cfg.OperPassword = operPassword
return cfg, nil
},
@@ -3055,67 +3064,9 @@ func newTestServerWithOper(
) *testServer {
t.Helper()
dbPath := filepath.Join(
t.TempDir(), "test.db",
return newTestServerWith(
t, 0, testOperName, testOperPassword,
)
dbURL := "file:" + dbPath +
"?_journal_mode=WAL&_busy_timeout=5000"
var srv *server.Server
app := fxtest.New(t,
fx.Provide(
newTestGlobals,
logger.New,
func(
lifecycle fx.Lifecycle,
globs *globals.Globals,
log *logger.Logger,
) (*config.Config, error) {
cfg, err := config.New(
lifecycle, config.Params{ //nolint:exhaustruct
Globals: globs, Logger: log,
},
)
if err != nil {
return nil, fmt.Errorf(
"test config: %w", err,
)
}
cfg.DBURL = dbURL
cfg.Port = 0
cfg.HashcashBits = 0
cfg.OperName = testOperName
cfg.OperPassword = testOperPassword
return cfg, nil
},
newTestDB,
stats.New,
newTestHealthcheck,
newTestMiddleware,
newTestHandlers,
newTestServerFx,
),
fx.Populate(&srv),
)
app.RequireStart()
httpSrv := httptest.NewServer(srv)
t.Cleanup(func() {
httpSrv.Close()
app.RequireStop()
})
return &testServer{
httpServer: httpSrv,
t: t,
fxApp: app,
}
}
func TestOperCommandSuccess(t *testing.T) {