From e6a7e0e8e6fe579058a23bef78e03a17172d6ed6 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 19 Oct 2023 01:56:06 -0700 Subject: [PATCH] main_test.go: Add to detect goroutine leaks Updates #330 --- main_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 main_test.go diff --git a/main_test.go b/main_test.go new file mode 100644 index 00000000..336be71c --- /dev/null +++ b/main_test.go @@ -0,0 +1,17 @@ +package websocket_test + +import ( + "fmt" + "os" + "runtime" + "testing" +) + +func TestMain(m *testing.M) { + code := m.Run() + if runtime.NumGoroutine() != 1 { + fmt.Fprintf(os.Stderr, "goroutine leak detected, expected 1 but got %d goroutines\n", runtime.NumGoroutine()) + os.Exit(1) + } + os.Exit(code) +}