docs(database): scope the lock-prevention guarantee to intra-process access

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
カン 2026-04-28 12:08:01 +09:00 committed by 康厚超
parent ca49f5672a
commit b0cfc49c0d

View file

@ -14,20 +14,23 @@ import (
"gorm.io/gorm/logger" "gorm.io/gorm/logger"
) )
// TestInitDBConcurrencyConfig verifies that InitDB applies both settings that // TestInitDBConcurrencyConfig verifies that InitDB applies both settings used
// are proven by TestConcurrentWrites to prevent "database is locked": // by TestConcurrentWrites to reduce "database is locked" errors from
// concurrent access within this process:
// //
// 1. WAL journal mode — reduces the window during which a write lock is held // 1. WAL journal mode — reduces the window during which a write lock is held
// (readers no longer block writers and vice-versa). // (readers no longer block writers and vice-versa).
// 2. SetMaxOpenConns(1) — serialises all GORM writes through a single // 2. SetMaxOpenConns(1) — serialises all GORM writes through a single
// connection at the Go pool level, so SQLite write-lock contention cannot // connection at the Go pool level, which prevents the specific
// occur at all. // intra-process write-contention pattern exercised by these tests.
// //
// Chain of proof: // Chain of proof:
// //
// TestConcurrentWrites/with_fix_* proves SetMaxOpenConns(1) fixes the bug. // TestConcurrentWrites/with_fix_* shows SetMaxOpenConns(1) prevents the
// specific concurrent-write lock contention reproduced by that test.
// TestInitDBConcurrencyConfig/single_connection_pool proves InitDB calls it. // TestInitDBConcurrencyConfig/single_connection_pool proves InitDB calls it.
// Therefore InitDB fixes the bug. // Therefore InitDB applies the same mitigation for this process/pool,
// without implying that SQLite lock errors cannot occur in all scenarios.
func TestInitDBConcurrencyConfig(t *testing.T) { func TestInitDBConcurrencyConfig(t *testing.T) {
dbPath := filepath.Join(t.TempDir(), "test.db") dbPath := filepath.Join(t.TempDir(), "test.db")
if err := InitDB(dbPath); err != nil { if err := InitDB(dbPath); err != nil {