fix: 完成商务迁移复核与接口优化并清理历史资料
This commit is contained in:
@@ -76,3 +76,32 @@ func TestDataScopeAuditWriterUsesReloadedDatabase(t *testing.T) {
|
||||
t.Fatalf("audit log was written to retired database: %d", firstCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataScopeAuditCloseCancelsBlockedWrite(t *testing.T) {
|
||||
db := openDataScopeAuditTestDB(t, "data-scope-audit-blocked")
|
||||
entered := make(chan struct{})
|
||||
if err := db.Callback().Create().Before("gorm:create").Register("test:block", func(tx *gorm.DB) {
|
||||
close(entered)
|
||||
<-tx.Statement.Context.Done()
|
||||
tx.AddError(tx.Statement.Context.Err())
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w := newDataScopeAuditWriterWithOptions(&Data{gormDB: newReloadableDB(db)}, slog.New(slog.NewTextHandler(io.Discard, nil)), 8, 1, time.Hour)
|
||||
w.Enqueue(dataAccessLogPO{EventType: "blocked_write"})
|
||||
select {
|
||||
case <-entered:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("writer did not start")
|
||||
}
|
||||
w.Close()
|
||||
select {
|
||||
case <-w.done:
|
||||
default:
|
||||
t.Fatal("database write did not honor its deadline")
|
||||
}
|
||||
w.Enqueue(dataAccessLogPO{EventType: "after_close"})
|
||||
if len(w.queue) != 0 {
|
||||
t.Fatal("closed writer accepted a new event")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user