The ring drops the oldest event once it reaches capacity. We push more than the ring can hold and verify the front is gone, the back is intact, and FindByID can no longer locate the dropped events.
(t *testing.T)
| 64 | // than the ring can hold and verify the front is gone, the back is intact, |
| 65 | // and FindByID can no longer locate the dropped events. |
| 66 | func TestRingDropsOldestPastCapacity(t *testing.T) { |
| 67 | debug.SetEnabled(true) |
| 68 | t.Cleanup(func() { debug.SetEnabled(false) }) |
| 69 | debug.Clear() |
| 70 | |
| 71 | const N = 600 // ring capacity is 500 |
| 72 | var firstID, lastID uint64 |
| 73 | for i := 0; i < N; i++ { |
| 74 | id := debug.Recordf("src", debug.LevelInfo, "msg %d", i) |
| 75 | if i == 0 { |
| 76 | firstID = id |
| 77 | } |
| 78 | lastID = id |
| 79 | } |
| 80 | |
| 81 | snap := debug.Snapshot() |
| 82 | if len(snap) > N { |
| 83 | t.Errorf("snapshot len = %d, expected <= ring capacity (%d)", len(snap), N) |
| 84 | } |
| 85 | if len(snap) == N { |
| 86 | t.Error("ring didn't drop any events — capacity not enforced") |
| 87 | } |
| 88 | |
| 89 | if snap[0].ID == firstID { |
| 90 | t.Error("oldest event should have been dropped from the ring") |
| 91 | } |
| 92 | if snap[len(snap)-1].ID != lastID { |
| 93 | t.Errorf("newest event missing; last ID is %d, want %d", snap[len(snap)-1].ID, lastID) |
| 94 | } |
| 95 | |
| 96 | if _, ok := debug.FindByID(firstID); ok { |
| 97 | t.Error("FindByID returned a dropped event") |
| 98 | } |
| 99 | if _, ok := debug.FindByID(lastID); !ok { |
| 100 | t.Error("FindByID can't find the most recent event") |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // Pair walks both directions: a request emits → response correlates back. |
| 105 | // Calling Pair on either ID returns the other. |
nothing calls this directly
no test coverage detected