Skip to content

Commit

Permalink
wasm: Add dial timeout test
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed Jan 9, 2021
1 parent 6840778 commit 65dfbdd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ws_js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,19 @@ func TestWasm(t *testing.T) {
err = c.Close(websocket.StatusNormalClosure, "")
assert.Success(t, err)
}

func TestWasmDialTimeout(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()

beforeDial := time.Now()
_, _, err := websocket.Dial(ctx, "ws://example.com:9893", &websocket.DialOptions{
Subprotocols: []string{"echo"},
})
assert.Error(t, err)
if time.Since(beforeDial) >= time.Second {
t.Fatal("wasm context dial timeout is not working", time.Since(beforeDial))
}
}

0 comments on commit 65dfbdd

Please sign in to comment.