| 13 | ) |
| 14 | |
| 15 | func TestWaitBuffer_WaitFor_Blocks(t *testing.T) { |
| 16 | t.Parallel() |
| 17 | ctx := testutil.Context(t, testutil.WaitShort) |
| 18 | |
| 19 | wb := testutil.NewWaitBuffer() |
| 20 | done := make(chan struct{}) |
| 21 | go func() { |
| 22 | defer close(done) |
| 23 | _ = wb.WaitFor(ctx, "hello") |
| 24 | }() |
| 25 | |
| 26 | // Write the signal after the goroutine is blocking. |
| 27 | _, err := wb.Write([]byte("hello")) |
| 28 | require.NoError(t, err) |
| 29 | |
| 30 | select { |
| 31 | case <-done: |
| 32 | case <-ctx.Done(): |
| 33 | t.Fatal("WaitFor did not unblock after signal was written") |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func TestWaitBuffer_WaitFor_AlreadyPresent(t *testing.T) { |
| 38 | t.Parallel() |