MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / TestSimultaneousRequests

Function TestSimultaneousRequests

rate/rate_test.go:233–264  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

231}
232
233func TestSimultaneousRequests(t *testing.T) {
234 const (
235 limit = 1
236 burst = 5
237 numRequests = 15
238 )
239 var (
240 wg sync.WaitGroup
241 numOK = uint32(0)
242 )
243
244 // Very slow replenishing bucket.
245 lim := NewLimiter(limit, burst)
246
247 // Tries to take a token, atomically updates the counter and decreases the wait
248 // group counter.
249 f := func() {
250 defer wg.Done()
251 if ok := lim.Allow(); ok {
252 atomic.AddUint32(&numOK, 1)
253 }
254 }
255
256 wg.Add(numRequests)
257 for range numRequests {
258 go f()
259 }
260 wg.Wait()
261 if numOK != burst {
262 t.Errorf("numOK = %d, want %d", numOK, burst)
263 }
264}
265
266func TestLongRunningQPS(t *testing.T) {
267 // The test runs for a few (fake) seconds executing many requests

Callers

nothing calls this directly

Calls 4

AllowMethod · 0.95
NewLimiterFunction · 0.85
WaitMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected