| 29 | } |
| 30 | |
| 31 | func TestStateTracker_Wait(t *testing.T) { |
| 32 | tracker := New(false) |
| 33 | |
| 34 | waiting := make(chan struct{}, 1) |
| 35 | ready := make(chan struct{}, 1) |
| 36 | go func() { |
| 37 | waiting <- struct{}{} |
| 38 | assert.True(t, tracker.Wait(context.Background(), true)) |
| 39 | ready <- struct{}{} |
| 40 | }() |
| 41 | |
| 42 | assert.True(t, len(ready) == 0, "should not yet be ready") |
| 43 | |
| 44 | tracker.Set(false) |
| 45 | assert.True(t, len(ready) == 0, "should not yet be ready") |
| 46 | |
| 47 | select { |
| 48 | case <-time.After(100 * time.Millisecond): |
| 49 | assert.Fail(t, "should be waiting by now") |
| 50 | case <-waiting: |
| 51 | } |
| 52 | tracker.Set(true) |
| 53 | |
| 54 | select { |
| 55 | case <-time.After(100 * time.Millisecond): |
| 56 | assert.Fail(t, "should be ready by now") |
| 57 | case <-ready: |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | func TestStateTracker_Listener(t *testing.T) { |
| 62 | var runCount uint32 |