fix(server): stop the background compaction before the database is closed
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 2m35s

The compaction starts right away in NewServer and could still write to the SQLite files while a
test's temp dir was removed ("directory not empty" on the CI runner, TestWebhookTokenInURLOnlyAPIKey).
Server.Close stops it and waits for a running pass; tests call it before closing the store, and the
server calls it on shutdown before the deferred store.Close. v0.37.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sandrodachandClaude Opus 5.5 committed 2026-11-01 13:16:58 +01:00
1 parent 3fbe015c06
commit c56bd4d943
10 files changed
+43 -6

No files matched your search

+7
View File
@@ -46,6 +46,7 @@ func setupTestServer(t *testing.T) (*Server, *storage.Store, string) {
}
hub := ws.NewHub()
srv := NewServer(cfg, store, hub, nil)
t.Cleanup(srv.Close)
token, err := auth.GenerateToken(cfg.JWTSecret, user.ID, user.Email, user.DisplayName, user.TokenVersion, testSession(t, store, user.ID))
if err != nil {
@@ -71,6 +72,7 @@ func TestFirstBootSetupAndInviteRegistrationAndNonNullSlices(t *testing.T) {
AllowRegistration: false,
}
srv := NewServer(cfg, store, ws.NewHub(), nil)
t.Cleanup(srv.Close)
router := srv.Router()
// 1. Fresh DB must report needsSetup = true
@@ -455,6 +457,7 @@ func TestLoginWithUsernameAndDemoMode(t *testing.T) {
DemoMode: true,
}
srv := NewServer(cfg, store, ws.NewHub(), nil)
t.Cleanup(srv.Close)
router := srv.Router()
// 1. Check auth status reports demoMode: true
@@ -542,6 +545,7 @@ func TestSpaceMembersDirectInvitationAPI(t *testing.T) {
JWTSecret: "test-secret",
}
srv := NewServer(cfg, store, ws.NewHub(), nil)
t.Cleanup(srv.Close)
router := srv.Router()
adminUser, err := store.GetUserByLogin("admin")
@@ -771,6 +775,7 @@ func TestWebhookTriageBadgeAndIngestion(t *testing.T) {
AllowRegistration: false,
}
srv := NewServer(cfg, store, ws.NewHub(), nil)
t.Cleanup(srv.Close)
router := srv.Router()
// 1. Setup user
@@ -864,6 +869,7 @@ func TestSSEGlobalEndpoint(t *testing.T) {
AllowRegistration: false,
}
srv := NewServer(cfg, store, hub, nil)
t.Cleanup(srv.Close)
router := srv.Router()
setupBody := []byte(`{
@@ -1345,6 +1351,7 @@ func TestFirstBootSetupWithSampleData(t *testing.T) {
}
defer store.Close()
srv := NewServer(&config.Config{Port: "8080", DatabasePath: dbPath, JWTSecret: "test-jwt-secret-key"}, store, ws.NewHub(), nil)
t.Cleanup(srv.Close)
// Too short passwords are refused (FLAW-09)
short := httptest.NewRequest(http.MethodPost, "/api/v1/auth/setup", strings.NewReader(`{"email":"me@example.com","password":"secret"}`))