修复日志持久化可靠性与数据库安全默认值
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user