MCPcopy
hub / github.com/jackc/pgx / TestContextWatcherContextCancelled

Function TestContextWatcherContextCancelled

pgconn/ctxwatch/context_watcher_test.go:26–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func 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
52func TestContextWatcherUnwatchedBeforeContextCancelled(t *testing.T) {
53 cw := ctxwatch.NewContextWatcher(&testHandler{

Callers

nothing calls this directly

Calls 3

WatchMethod · 0.95
UnwatchMethod · 0.95
NewContextWatcherFunction · 0.92

Tested by

no test coverage detected