Skip to content

Commit 6dc740f

Browse files
committed
test: adjust a test to work with js/wasm's background goroutine
Fixes #34768 Change-Id: Ic73591f620cdee5bc7203483902e6ba98d2c442b Reviewed-on: https://go-review.googlesource.com/c/go/+/200438 Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 26ff21d commit 6dc740f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test/goprint.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@
99
package main
1010

1111
import (
12+
"log"
1213
"runtime"
1314
"time"
1415
)
1516

1617
func main() {
18+
numg0 := runtime.NumGoroutine()
19+
deadline := time.Now().Add(10 * time.Second)
1720
go println(42, true, false, true, 1.5, "world", (chan int)(nil), []int(nil), (map[string]int)(nil), (func())(nil), byte(255))
18-
for runtime.NumGoroutine() > 1 {
19-
time.Sleep(10*time.Millisecond)
21+
for {
22+
numg := runtime.NumGoroutine()
23+
if numg > numg0 {
24+
if time.Now().After(deadline) {
25+
log.Fatalf("%d goroutines > initial %d after deadline", numg, numg0)
26+
}
27+
runtime.Gosched()
28+
continue
29+
}
30+
break
2031
}
2132
}

0 commit comments

Comments
 (0)