修复日志持久化可靠性与数据库安全默认值

This commit is contained in:
2026-07-13 11:27:34 +08:00
parent db325ec413
commit 6f37165256
10 changed files with 612 additions and 75 deletions
+35
View File
@@ -381,6 +381,41 @@ func TestQueueSubmitOwnsEntrySnapshot(t *testing.T) {
}
}
func TestQueueRetainsBatchUntilBackendRecovers(t *testing.T) {
backend := newQueueBackend(func(context.Context, string) (logger.Batch, error) {
return &fakeBatch{}, nil
})
backend.healthy.Store(false)
q := logger.NewQueueWithBackend(backend, 1, 1, 1, 10*time.Millisecond)
q.Start(context.Background())
q.Submit(&logger.LogEntry{RequestID: "retained"})
time.Sleep(50 * time.Millisecond)
if calls := backend.calls.Load(); calls != 0 {
t.Fatalf("PrepareBatch calls=%d while unhealthy", calls)
}
if stats := q.Stats(); stats.Failed != 0 || stats.Bytes == 0 {
t.Fatalf("unhealthy stats=%+v want retained bytes and no failure", stats)
}
backend.healthy.Store(true)
deadline := time.Now().Add(time.Second)
for backend.calls.Load() == 0 && time.Now().Before(deadline) {
time.Sleep(10 * time.Millisecond)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if err := q.Stop(ctx); err != nil {
t.Fatalf("Stop: %v", err)
}
if calls := backend.calls.Load(); calls != 1 {
t.Fatalf("PrepareBatch calls=%d want 1", calls)
}
if stats := q.Stats(); stats.Failed != 0 || stats.Bytes != 0 {
t.Fatalf("recovered stats=%+v", stats)
}
}
func TestQueueByteBudgetTracksOwnedEntrySnapshot(t *testing.T) {
batch := &fakeBatch{}
backend := newQueueBackend(func(context.Context, string) (logger.Batch, error) {