(t *testing.T)
| 130 | } |
| 131 | |
| 132 | func TestMemoryReplayCacheConcurrentDistinctIDs(t *testing.T) { |
| 133 | now := replayCacheTestNow |
| 134 | setReplayCacheTestNow(t, &now) |
| 135 | const maxEntries, workers = 20, 100 |
| 136 | c := NewMemoryReplayCache(maxEntries) |
| 137 | |
| 138 | var accepted, full atomic.Int32 |
| 139 | var wg sync.WaitGroup |
| 140 | for i := range workers { |
| 141 | wg.Add(1) |
| 142 | go func() { |
| 143 | defer wg.Done() |
| 144 | err := c.Consume(fmt.Sprintf("id-%d", i), now.Add(time.Minute)) |
| 145 | switch { |
| 146 | case err == nil: |
| 147 | accepted.Add(1) |
| 148 | case errors.Is(err, ErrReplayCacheFull): |
| 149 | full.Add(1) |
| 150 | } |
| 151 | }() |
| 152 | } |
| 153 | wg.Wait() |
| 154 | assert.Check(t, is.Equal(int32(maxEntries), accepted.Load())) |
| 155 | assert.Check(t, is.Equal(int32(workers-maxEntries), full.Load())) |
| 156 | assert.Check(t, is.Len(c.entries, maxEntries)) |
| 157 | } |
| 158 | |
| 159 | func TestNewPassesReplayCache(t *testing.T) { |
| 160 | cache := NewMemoryReplayCache(1) |
nothing calls this directly
no test coverage detected