(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func 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 | |
| 31 | func TestRecentErrorRingNilSafe(t *testing.T) { |
| 32 | var r *recentErrorRing |
nothing calls this directly
no test coverage detected