MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestLatchMultipleWaiters

Function TestLatchMultipleWaiters

asyncbuffer/latch_test.go:77–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75}
76
77func TestLatchMultipleWaiters(t *testing.T) {
78 latch := asyncbuffer.NewLatch()
79 const numWaiters = 10
80
81 var wg sync.WaitGroup
82 waitersCompleted := make(chan int, numWaiters)
83
84 // Start multiple waiters
85 for i := range numWaiters {
86 wg.Add(1)
87 go func(id int) {
88 defer wg.Done()
89 latch.Wait()
90 waitersCompleted <- id
91 }(i)
92 }
93
94 // Give goroutines time to start waiting
95 time.Sleep(10 * time.Millisecond)
96
97 // No waiters should complete yet
98 assert.Empty(t, waitersCompleted)
99
100 // Release the latch
101 latch.Release()
102
103 // All waiters should complete
104 wg.Wait()
105 close(waitersCompleted)
106
107 // Verify all waiters completed
108 completed := make([]int, 0, numWaiters)
109 for id := range waitersCompleted {
110 completed = append(completed, id)
111 }
112 assert.Len(t, completed, numWaiters)
113}
114
115func TestLatchMultipleReleases(t *testing.T) {
116 latch := asyncbuffer.NewLatch()

Callers

nothing calls this directly

Calls 6

WaitMethod · 0.95
ReleaseMethod · 0.95
NewLatchFunction · 0.92
AddMethod · 0.80
WaitMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected