29 lines
730 B
Go
29 lines
730 B
Go
package app
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestLockDatabaseInstanceRejectsConcurrentOwnerAndReacquiresAfterUnlock(t *testing.T) {
|
|
dbPath := filepath.Join(t.TempDir(), "data", "conversations.db")
|
|
|
|
unlock, err := lockDatabaseInstance(dbPath)
|
|
if err != nil {
|
|
t.Fatalf("first lockDatabaseInstance failed: %v", err)
|
|
}
|
|
|
|
if _, err := lockDatabaseInstance(dbPath); err == nil || !strings.Contains(err.Error(), "另一个 CyberStrikeAI 服务实例正在运行") {
|
|
t.Fatalf("expected concurrent lock to be rejected with clear message, got: %v", err)
|
|
}
|
|
|
|
unlock()
|
|
|
|
unlock2, err := lockDatabaseInstance(dbPath)
|
|
if err != nil {
|
|
t.Fatalf("reacquiring lock after unlock failed: %v", err)
|
|
}
|
|
unlock2()
|
|
}
|