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

Function TestContextWatcherMultipleWatchPanics

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

Source from the content-addressed store, hash-verified

65}
66
67func TestContextWatcherMultipleWatchPanics(t *testing.T) {
68 cw := ctxwatch.NewContextWatcher(&testHandler{handleCancel: func(context.Context) {}, handleUnwatchAfterCancel: func() {}})
69
70 ctx, cancel := context.WithCancel(t.Context())
71 defer cancel()
72 cw.Watch(ctx)
73 defer cw.Unwatch()
74
75 ctx2, cancel2 := context.WithCancel(t.Context())
76 defer cancel2()
77 require.Panics(t, func() { cw.Watch(ctx2) }, "Expected panic when Watch called multiple times")
78}
79
80func TestContextWatcherUnwatchWhenNotWatchingIsSafe(t *testing.T) {
81 cw := ctxwatch.NewContextWatcher(&testHandler{handleCancel: func(context.Context) {}, handleUnwatchAfterCancel: func() {}})

Callers

nothing calls this directly

Calls 3

WatchMethod · 0.95
UnwatchMethod · 0.95
NewContextWatcherFunction · 0.92

Tested by

no test coverage detected