隔离原生测试数据目录并记录全后端及恢复竞争检测结果
This commit is contained in:
1 parent
3b254496b0
commit
7ba4046135
13 files changed
+54
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user