-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
50 lines (43 loc) · 1.16 KB
/
Copy pathmain_test.go
File metadata and controls
50 lines (43 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package blazewave_test
import (
"fmt"
"os"
"runtime"
"testing"
)
func goroutineStacks() []byte {
buf := make([]byte, 512)
for {
m := runtime.Stack(buf, true)
if m < len(buf) {
return buf[:m]
}
buf = make([]byte, len(buf)*2)
}
}
func TestMain(m *testing.M) {
code := m.Run()
// Get current goroutine count
goroutineCount := runtime.NumGoroutine()
// Define expected goroutine counts for different scenarios
var expectedCount int
if runtime.GOOS == "js" {
expectedCount = 2
} else {
expectedCount = 1
}
// Check for goroutine leak
if goroutineCount > expectedCount {
// For heartbeat tests, we expect more goroutines due to timer pools
// Allow up to 50 goroutines for heartbeat-related tests
if goroutineCount > 50 {
fmt.Fprintf(os.Stderr, "goroutine leak detected, expected %d but got %d goroutines\n", expectedCount, goroutineCount)
fmt.Fprintf(os.Stderr, "%s\n", goroutineStacks())
os.Exit(1)
} else {
// Log but don't fail for heartbeat tests
fmt.Fprintf(os.Stderr, "note: %d goroutines detected (expected %d), but this is normal for heartbeat tests with timer pools\n", goroutineCount, expectedCount)
}
}
os.Exit(code)
}