MCPcopy
hub / github.com/grafana/dskit / TestBlockingGate

Function TestBlockingGate

gate/gate_test.go:41–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestBlockingGate(t *testing.T) {
42 t.Run("not at concurrency limit", func(t *testing.T) {
43 ctx, cancel := context.WithCancel(context.Background())
44 defer cancel()
45
46 g := NewBlocking(1)
47 err1 := g.Start(ctx)
48 require.NoError(t, err1)
49
50 g.Done()
51 err2 := g.Start(ctx)
52 require.NoError(t, err2)
53 })
54
55 t.Run("at concurrency limit", func(t *testing.T) {
56 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
57 defer cancel()
58
59 g := NewBlocking(1)
60 err1 := g.Start(ctx)
61 err2 := g.Start(ctx)
62
63 require.NoError(t, err1)
64 require.ErrorIs(t, err2, context.DeadlineExceeded)
65 })
66}
67
68func TestInstrumentedGate(t *testing.T) {
69 t.Run("max concurrency", func(t *testing.T) {

Callers

nothing calls this directly

Calls 4

NewBlockingFunction · 0.85
RunMethod · 0.80
StartMethod · 0.65
DoneMethod · 0.65

Tested by

no test coverage detected