MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestRecentErrorRingNewestFirstAndEviction

Function TestRecentErrorRingNewestFirstAndEviction

server/recent_errors_test.go:11–29  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestRecentErrorRingNewestFirstAndEviction(t *testing.T) {
12 r := newRecentErrorRing(3)
13 base := time.Unix(1700000000, 0)
14 for i := 0; i < 5; i++ { // 5 adds into a cap-3 ring: 0,1 evicted
15 r.add(RecentError{SQLState: "S", Message: "m", Time: base.Add(time.Duration(i) * time.Second), OrgID: string(rune('a' + i))})
16 }
17 got := r.snapshot(0) // all retained
18 if len(got) != 3 {
19 t.Fatalf("snapshot len = %d, want 3 (ring cap)", len(got))
20 }
21 // Newest first: last added (i=4, org 'e') is [0]; oldest retained (i=2, 'c') is [2].
22 if got[0].OrgID != "e" || got[1].OrgID != "d" || got[2].OrgID != "c" {
23 t.Fatalf("order = %s,%s,%s, want e,d,c (newest first, 0/1 evicted)", got[0].OrgID, got[1].OrgID, got[2].OrgID)
24 }
25 // limit clamps.
26 if l := r.snapshot(2); len(l) != 2 || l[0].OrgID != "e" {
27 t.Fatalf("snapshot(2) = %v, want 2 newest starting 'e'", l)
28 }
29}
30
31func TestRecentErrorRingNilSafe(t *testing.T) {
32 var r *recentErrorRing

Callers

nothing calls this directly

Calls 4

newRecentErrorRingFunction · 0.85
addMethod · 0.80
AddMethod · 0.80
snapshotMethod · 0.45

Tested by

no test coverage detected