| 42 | } |
| 43 | |
| 44 | func TestLatchWait(t *testing.T) { |
| 45 | latch := asyncbuffer.NewLatch() |
| 46 | |
| 47 | // Start a goroutine that will wait |
| 48 | waitCompleted := make(chan bool, 1) |
| 49 | go func() { |
| 50 | latch.Wait() |
| 51 | waitCompleted <- true |
| 52 | }() |
| 53 | |
| 54 | // Give the goroutine a moment to start waiting |
| 55 | time.Sleep(10 * time.Millisecond) |
| 56 | |
| 57 | // Wait should not complete yet |
| 58 | select { |
| 59 | case <-waitCompleted: |
| 60 | t.Fatal("Wait should not complete before Release") |
| 61 | default: |
| 62 | // Expected |
| 63 | } |
| 64 | |
| 65 | // Release the latch |
| 66 | latch.Release() |
| 67 | |
| 68 | // Wait should complete now |
| 69 | select { |
| 70 | case <-waitCompleted: |
| 71 | // Expected |
| 72 | case <-time.After(100 * time.Millisecond): |
| 73 | t.Fatal("Wait should complete after Release") |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | func TestLatchMultipleWaiters(t *testing.T) { |
| 78 | latch := asyncbuffer.NewLatch() |