Files
xarmian 20544fdd44 perf(test): build the SQLite migration chain once per test binary (IDEA-1914) (#788)
* perf(test): build the SQLite migration chain once per test binary (IDEA-1914)

internal/server's -race suite spent ~30 minutes replaying all 69
migrations + 3 backfills per test (~2.7s each, 622 store-backed tests,
BUG-1913). Add internal/store/storetest, which runs the full migration
chain once into a checkpointed, sidecar-free template DB (sync.Once)
and hands every test a plain file copy opened via store.New. Wire it
into internal/server's testServer/testServer_Stop_DrainsRateLimiterCleanup
and internal/store's own testStore (duplicated inline there — an
import cycle rules out sharing storetest with store's white-box
tests). Postgres-mode tests are untouched.

internal/server -race: 1819s -> 183s.

* fix(test): plug template-dir leak and Cleanup race in storetest fixture

Codex round 2 on IDEA-1914: buildTemplate/buildSQLiteTemplate left the
MkdirTemp'd template dir on disk if store.New/checkpoint/journal_mode
failed after mkdir succeeded — now removed via a disarm-on-success
defer in both mirrored copies. Also guard Cleanup()/removeSQLiteTemplate
against racing an in-flight build+copy with a sync.RWMutex (read-locked
across build+copy, write-locked for removal) in both places.
2026-07-03 10:15:49 -04:00

26 lines
762 B
Go

package server
import (
"os"
"testing"
"github.com/PerpetualSoftware/pad/internal/store"
"github.com/PerpetualSoftware/pad/internal/store/storetest"
"golang.org/x/crypto/bcrypt"
)
// TestMain lowers the bcrypt cost for the whole package. Without this,
// the suite's many bootstrapFirstUser calls run bcrypt at the production
// cost under -race (~3s per call), pushing cumulative race-step time past
// the CI 30m timeout. See BUG-1371.
//
// It also tears down storetest's process-wide template DB (IDEA-1914)
// after the suite finishes, so the lazily-built template file doesn't
// linger past this binary's lifetime.
func TestMain(m *testing.M) {
store.SetBcryptCostForTesting(bcrypt.MinCost)
code := m.Run()
storetest.Cleanup()
os.Exit(code)
}