MCPcopy Create free account
hub / github.com/crewjam/saml / TestMemoryReplayCacheConcurrentDistinctIDs

Function TestMemoryReplayCacheConcurrentDistinctIDs

samlsp/replay_cache_test.go:132–157  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

130}
131
132func 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
159func TestNewPassesReplayCache(t *testing.T) {
160 cache := NewMemoryReplayCache(1)

Callers

nothing calls this directly

Calls 4

ConsumeMethod · 0.95
setReplayCacheTestNowFunction · 0.85
NewMemoryReplayCacheFunction · 0.85
LenMethod · 0.80

Tested by

no test coverage detected