Skip to content

Commit 65dfbdd

Browse files
committed
wasm: Add dial timeout test
1 parent 6840778 commit 65dfbdd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: ws_js_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,19 @@ func TestWasm(t *testing.T) {
3636
err = c.Close(websocket.StatusNormalClosure, "")
3737
assert.Success(t, err)
3838
}
39+
40+
func TestWasmDialTimeout(t *testing.T) {
41+
t.Parallel()
42+
43+
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
44+
defer cancel()
45+
46+
beforeDial := time.Now()
47+
_, _, err := websocket.Dial(ctx, "ws://example.com:9893", &websocket.DialOptions{
48+
Subprotocols: []string{"echo"},
49+
})
50+
assert.Error(t, err)
51+
if time.Since(beforeDial) >= time.Second {
52+
t.Fatal("wasm context dial timeout is not working", time.Since(beforeDial))
53+
}
54+
}

0 commit comments

Comments
 (0)