2
0

Fix panic when closing conn during cancellable query

fixes #29
This commit is contained in:
Jack Christensen
2020-04-07 19:38:21 -05:00
parent e4f3224f4c
commit 5d2be99c25
3 changed files with 31 additions and 0 deletions
+11
View File
@@ -59,6 +59,17 @@ func TestContextWatcherMultipleWatchPanics(t *testing.T) {
require.Panics(t, func() { cw.Watch(ctx2) }, "Expected panic when Watch called multiple times")
}
func TestContextWatcherUnwatchIsAlwaysSafe(t *testing.T) {
cw := ctxwatch.NewContextWatcher(func() {}, func() {})
cw.Unwatch() // unwatch when not / never watching
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cw.Watch(ctx)
cw.Unwatch()
cw.Unwatch() // double unwatch
}
func TestContextWatcherStress(t *testing.T) {
var cancelFuncCalls int64
var cleanupFuncCalls int64