(t *testing.T)
| 24 | } |
| 25 | |
| 26 | func TestContextWatcherContextCancelled(t *testing.T) { |
| 27 | canceledChan := make(chan struct{}) |
| 28 | cleanupCalled := false |
| 29 | cw := ctxwatch.NewContextWatcher(&testHandler{ |
| 30 | handleCancel: func(context.Context) { |
| 31 | canceledChan <- struct{}{} |
| 32 | }, handleUnwatchAfterCancel: func() { |
| 33 | cleanupCalled = true |
| 34 | }, |
| 35 | }) |
| 36 | |
| 37 | ctx, cancel := context.WithCancel(context.Background()) |
| 38 | cw.Watch(ctx) |
| 39 | cancel() |
| 40 | |
| 41 | select { |
| 42 | case <-canceledChan: |
| 43 | case <-time.NewTimer(time.Second).C: |
| 44 | t.Fatal("Timed out waiting for cancel func to be called") |
| 45 | } |
| 46 | |
| 47 | cw.Unwatch() |
| 48 | |
| 49 | require.True(t, cleanupCalled, "Cleanup func was not called") |
| 50 | } |
| 51 | |
| 52 | func TestContextWatcherUnwatchedBeforeContextCancelled(t *testing.T) { |
| 53 | cw := ctxwatch.NewContextWatcher(&testHandler{ |
nothing calls this directly
no test coverage detected