隔离原生测试数据目录并记录全后端及恢复竞争检测结果

This commit is contained in:
xuans committed 2026-10-02 14:01:51 +08:00
1 parent 3b254496b0
commit 7ba4046135
13 files changed
+54

No files matched your search

+5
View File
@@ -60,6 +60,7 @@ func TestScertAdminSystemdUnitKeepsManualOnlyPolicy(t *testing.T) {
func TestControllerActivatesAndStopsResetPath(t *testing.T) {
cfg := config.Default(t.TempDir())
cfg.Paths.Data = t.TempDir()
cfg.SetupReady = true
cfg.Web.Hostname = "scert.example.test"
cfg.Server.Port = 8443
@@ -111,6 +112,7 @@ func TestExpiredLeaseIsInactive(t *testing.T) {
func TestResetCodeCanOnlyBeConsumedOnce(t *testing.T) {
cfg := config.Default(t.TempDir())
cfg.Paths.Data = t.TempDir()
cfg.SetupReady = true
cfg.Web.Hostname = "scert.example.test"
controller := New(cfg)
@@ -137,6 +139,7 @@ func TestResetCodeCanOnlyBeConsumedOnce(t *testing.T) {
func TestControllerWritesAndDestroysProtectedCodeFile(t *testing.T) {
cfg := config.Default(t.TempDir())
cfg.Paths.Data = t.TempDir()
cfg.SetupReady = true
cfg.Web.Hostname = "scert.example.test"
codePath := filepath.Join(t.TempDir(), "runtime", "reset-code")
@@ -172,6 +175,7 @@ func TestControllerWritesAndDestroysProtectedCodeFile(t *testing.T) {
func TestConsumeDestroysCodeFile(t *testing.T) {
cfg := config.Default(t.TempDir())
cfg.Paths.Data = t.TempDir()
cfg.SetupReady = true
cfg.Web.Hostname = "scert.example.test"
codePath := filepath.Join(t.TempDir(), "runtime", "reset-code")
@@ -217,6 +221,7 @@ func TestExpiredLeaseDestroysCodeFile(t *testing.T) {
func TestControllerDoesNotOverwriteExistingCodeFile(t *testing.T) {
cfg := config.Default(t.TempDir())
cfg.Paths.Data = t.TempDir()
cfg.SetupReady = true
cfg.Web.Hostname = "scert.example.test"
codePath := filepath.Join(t.TempDir(), "runtime", "reset-code")
@@ -326,6 +326,7 @@ func TestServiceRestoreVersionRollsBackFilesWhenStateUpdateFails(t *testing.T) {
func certificateTestConfig(root string) config.Config {
cfg := config.Default(root)
cfg.Paths.Config = filepath.Join(root, "conf")
cfg.Paths.Certificate = filepath.Join(root, "ssl")
cfg.Paths.Backup = filepath.Join(root, "backups")
cfg.DNS.Provider = "cloudflare"
@@ -87,6 +87,7 @@ func TestValidateConfigKeepsExternalDatabaseUsernameOutOfPersistedDSN(t *testing
func TestVerifyWritableSQLiteCleansTemporaryTable(t *testing.T) {
cfg := config.Default(t.TempDir()).Database
cfg.DSN = filepath.Join(t.TempDir(), "verification.db")
if err := VerifyWritable(t.Context(), cfg); err != nil {
t.Fatalf("SQLite 可写验证失败:%v", err)
}
@@ -2,6 +2,7 @@ package database
import (
"context"
"path/filepath"
"strings"
"testing"
@@ -10,6 +11,7 @@ import (
func TestDatabasePingAndSQLitePragmas(t *testing.T) {
cfg := config.Default(t.TempDir()).Database
cfg.DSN = filepath.Join(t.TempDir(), "runtime.db")
db, err := Open(context.Background(), cfg)
if err != nil {
t.Fatalf("打开 SQLite 失败:%v", err)
@@ -22,6 +22,7 @@ func TestSQLiteCanceledQueriesReleaseFiles(t *testing.T) {
}
t.Run(name, func(t *testing.T) {
cfg := config.Default(t.TempDir()).Database
cfg.DSN = filepath.Join(t.TempDir(), "close.db")
cfg.MaxOpenConns, cfg.MaxIdleConns = 1, 1
db, err := Open(t.Context(), cfg)
if err != nil {
@@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"path/filepath"
"sync"
"testing"
"time"
@@ -15,6 +16,7 @@ import (
func newSQLiteConcurrencyPools(t *testing.T) (*sql.DB, *sql.DB) {
t.Helper()
cfg := config.Default(t.TempDir()).Database
cfg.DSN = filepath.Join(t.TempDir(), "concurrency.db")
first := openSQLiteTestPool(t, cfg)
second := openSQLiteTestPool(t, cfg)
if _, err := first.ExecContext(t.Context(), "CREATE TABLE lock_probe (id INTEGER PRIMARY KEY, value INTEGER NOT NULL); INSERT INTO lock_probe VALUES (1, 0)"); err != nil {
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"errors"
"path/filepath"
"testing"
"time"
@@ -98,6 +99,7 @@ func TestSQLiteDeadlineAcrossExecutionPaths(t *testing.T) {
func TestSQLitePoolWaitHonorsContext(t *testing.T) {
cfg := config.Default(t.TempDir()).Database
cfg.DSN = filepath.Join(t.TempDir(), "pool-wait.db")
cfg.MaxOpenConns = 1
cfg.MaxIdleConns = 1
db := openSQLiteTestPool(t, cfg)
@@ -146,6 +148,7 @@ func TestSQLiteDeadlinePreservesQueryMetadata(t *testing.T) {
func TestSQLiteOpenDeadlineWhileChangingJournalMode(t *testing.T) {
cfg := config.Default(t.TempDir()).Database
cfg.DSN = filepath.Join(t.TempDir(), "journal-mode.db")
if err := ensureSQLiteDir(cfg.DSN); err != nil {
t.Fatal(err)
}
@@ -3,6 +3,7 @@ package database
import (
"context"
"database/sql"
"path/filepath"
"testing"
"git.pcux.cn/xuans/Scert/backend/internal/config"
@@ -44,6 +45,7 @@ func TestSQLitePoolConfiguresEveryConnection(t *testing.T) {
for _, name := range []string{"parallel_connections", "no_idle_connections", "replacement_connections", "uri_options"} {
t.Run(name, func(t *testing.T) {
cfg := config.Default(t.TempDir()).Database
cfg.DSN = filepath.Join(t.TempDir(), "pool.db")
cfg.MaxOpenConns = 4
cfg.MaxIdleConns = 4
if name == "no_idle_connections" {
@@ -6,6 +6,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
"testing"
@@ -29,6 +30,7 @@ func TestSQLiteProcessConcurrency(t *testing.T) {
return
}
cfg := config.Default(t.TempDir()).Database
cfg.DSN = filepath.Join(t.TempDir(), "process.db")
db := openSQLiteTestPool(t, cfg)
if _, err := db.ExecContext(t.Context(), "CREATE TABLE lock_probe (id INTEGER PRIMARY KEY, value INTEGER NOT NULL); INSERT INTO lock_probe VALUES (1, 0)"); err != nil {
t.Fatal(err)
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"path/filepath"
"runtime"
"sync"
"testing"
@@ -15,6 +16,7 @@ import (
// 覆盖真实连接间的写入与检查点竞争,不将概率性压力测试当成上游缺陷的确定性复现。
func TestSQLiteWALCheckpointIntegrity(t *testing.T) {
cfg := config.Default(t.TempDir()).Database
cfg.DSN = filepath.Join(t.TempDir(), "checkpoint.db")
cfg.MaxOpenConns, cfg.MaxIdleConns = 3, 3
db := openSQLiteTestPool(t, cfg)
ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second)