Skip to content

Commit 75e6c30

Browse files
fix(test): add busy_timeout to SQLite and avoid race in TestMonitorService_UpdateAllStatuses
1 parent fed2fd6 commit 75e6c30

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎internal/model/model.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func NewRepository(dbFile string) (*IPRepository, error) {
7777

7878
// Modo tradicional (DELETE): garante apenas o arquivo .db único, sem gerar .db-wal ou .db-shm
7979
_, _ = db.Exec("PRAGMA journal_mode=DELETE;")
80+
_, _ = db.Exec("PRAGMA busy_timeout=5000;")
8081

8182
_, err = db.Exec(`CREATE TABLE IF NOT EXISTS ips (
8283
id INTEGER PRIMARY KEY AUTOINCREMENT,

‎internal/service/service_test.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,14 @@ func TestMonitorService_UpdateAllStatuses(t *testing.T) {
200200

201201
svc := service.NewMonitorService(repo)
202202

203-
_ = svc.AddIP("127.0.0.1")
204-
_ = svc.AddIP("192.0.2.1") // IP RFC 5737 de teste não roteável (deve ficar offline)
203+
err = repo.AddDevice(model.IPDevice{IP: "127.0.0.1", Name: "Localhost", Method: "PING", ThresholdMs: 1000})
204+
if err != nil {
205+
t.Fatalf("Erro ao adicionar host 1: %v", err)
206+
}
207+
err = repo.AddDevice(model.IPDevice{IP: "192.0.2.1", Name: "RFC Test", Method: "PING", ThresholdMs: 1000})
208+
if err != nil {
209+
t.Fatalf("Erro ao adicionar host 2: %v", err)
210+
}
205211

206212
overview, err := svc.UpdateAllStatuses()
207213
if err != nil {

0 commit comments

Comments
 (0)