Skip to content

Commit 0cd8c92

Browse files
committed
sysmon usleep(20us) will actually sleep 20ms on openbsd.
android emulator may be slow. last time bucket looks misleading.
1 parent 38aaf26 commit 0cd8c92

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/runtime/sysmon_test.go

+20-6
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ func (srv *busysrv) expect(bucket int, percent float64) bool {
102102
}
103103

104104
func (srv *busysrv) printf(ffn func(format string, args ...interface{})) {
105-
ffn("dialed %d times within %v\n", srv.bucketTotal, srv.end.Sub(srv.start))
106-
ffn("timeBucket\tcount\tpercent\n")
107-
for ms, cnt := range srv.bucket {
108-
ffn("[%2d,%2d)ms\t%d\t%.2f%%\n", ms, ms+1, cnt, float64(cnt)/float64(srv.bucketTotal)*100.0)
105+
ffn("dialed %d times within %v", srv.bucketTotal, srv.end.Sub(srv.start))
106+
ffn("timeBucket\tcount\tpercent")
107+
for bucket, cnt := range srv.bucket {
108+
percent := float64(cnt) / float64(srv.bucketTotal) * 100.0
109+
if bucket == len(srv.bucket)-1 {
110+
ffn("[%2d, ~)ms\t%d\t%.2f%%", bucket, cnt, percent)
111+
} else {
112+
ffn("[%2d,%2d)ms\t%d\t%.2f%%", bucket, bucket+1, cnt, percent)
113+
}
109114
}
110115
}
111116

@@ -116,6 +121,10 @@ func TestSysmonReadyNetpollWaitersASAP(t *testing.T) {
116121
if runtime.GOARCH == "wasm" {
117122
t.Skip("no sysmon on wasm yet")
118123
}
124+
if runtime.GOOS == "openbsd" {
125+
// usleep(20us) actually slept 20ms. see issue #17712.
126+
t.Skip("sysmon may oversleep on openbsd.")
127+
}
119128

120129
// sysmon may starve if host load is too high.
121130
np := runtime.GOMAXPROCS(0)
@@ -134,8 +143,13 @@ func TestSysmonReadyNetpollWaitersASAP(t *testing.T) {
134143
srv.stop()
135144
time.Sleep(time.Millisecond * 100)
136145

137-
// expect more than 80% dialings accomplished within 2ms.
138-
if !srv.expect(2, 80.0) {
146+
// expect more than 80% dialings accomplished within 2ms in general.
147+
// but android emulator may be slow, so more patience needed.
148+
bucket, percent := 2, 80.0
149+
if runtime.GOOS == "android" {
150+
bucket = 9
151+
}
152+
if !srv.expect(bucket, percent) {
139153
t.Fail()
140154
}
141155
srv.printf(t.Logf)

0 commit comments

Comments
 (0)