...

Source file src/nhooyr.io/websocket/main_test.go

Documentation: nhooyr.io/websocket

     1  package websocket_test
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"runtime"
     7  	"testing"
     8  )
     9  
    10  func goroutineStacks() []byte {
    11  	buf := make([]byte, 512)
    12  	for {
    13  		m := runtime.Stack(buf, true)
    14  		if m < len(buf) {
    15  			return buf[:m]
    16  		}
    17  		buf = make([]byte, len(buf)*2)
    18  	}
    19  }
    20  
    21  func TestMain(m *testing.M) {
    22  	code := m.Run()
    23  	if runtime.GOOS != "js" && runtime.NumGoroutine() != 1 ||
    24  		runtime.GOOS == "js" && runtime.NumGoroutine() != 2 {
    25  		fmt.Fprintf(os.Stderr, "goroutine leak detected, expected 1 but got %d goroutines\n", runtime.NumGoroutine())
    26  		fmt.Fprintf(os.Stderr, "%s\n", goroutineStacks())
    27  		os.Exit(1)
    28  	}
    29  	os.Exit(code)
    30  }
    31  

View as plain text