| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | "time" |
| 7 | ) |
| 8 | |
| 9 | // TestStragglerDrainWaitsForAbandonedGoroutines pins the turn boundary: the |
| 10 | // next turn must not zero per-turn state while a batch goroutine still reads it. |
| 11 | func TestStragglerDrainWaitsForAbandonedGoroutines(t *testing.T) { |
| 12 | var s runStragglers |
| 13 | s.enter() |
| 14 | drained := make(chan struct{}) |
| 15 | go func() { |
| 16 | s.drain(context.Background(), time.Second) |
| 17 | close(drained) |
| 18 | }() |
| 19 | select { |
| 20 | case <-drained: |
| 21 | t.Fatal("drain returned while a batch goroutine was still live") |
| 22 | case <-time.After(20 * time.Millisecond): |
| 23 | } |
| 24 | s.leave() |
| 25 | select { |
| 26 | case <-drained: |
| 27 | case <-time.After(time.Second): |
| 28 | t.Fatal("drain did not return after the goroutine left") |
| 29 | } |
| 30 | } |
| 31 |