Skip to content

Commit

Permalink
Re-enable stream ping tests
Browse files Browse the repository at this point in the history
Should not fail now that I've adjusted the chunk size.
  • Loading branch information
nhooyr committed Oct 9, 2019
1 parent b74c66b commit 09910a2
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,14 +1141,13 @@ func TestAutobahn(t *testing.T) {
err := c.PingWithPayload(ctx, string(p))
return assertCloseStatus(err, websocket.StatusProtocolError)
})
// See comment on the tenStreamedPings test.
// run(t, "streamPingPayload", func(ctx context.Context, c *websocket.Conn) error {
// err := assertStreamPing(ctx, c, 125)
// if err != nil {
// return err
// }
// return c.Close(websocket.StatusNormalClosure, "")
// })
run(t, "streamPingPayload", func(ctx context.Context, c *websocket.Conn) error {
err := assertStreamPing(ctx, c, 125)
if err != nil {
return err
}
return c.Close(websocket.StatusNormalClosure, "")
})
t.Run("unsolicitedPong", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1212,18 +1211,16 @@ func TestAutobahn(t *testing.T) {
return assertCloseStatus(err, websocket.StatusNormalClosure)
})

// Streamed pings tests are not useful with this implementation since we always
// use io.ReadFull. These tests cause failures when running with -race on my mac.
// run(t, "tenStreamedPings", func(ctx context.Context, c *websocket.Conn) error {
// for i := 0; i < 10; i++ {
// err := assertStreamPing(ctx, c, 125)
// if err != nil {
// return err
// }
// }
//
// return c.Close(websocket.StatusNormalClosure, "")
// })
run(t, "tenStreamedPings", func(ctx context.Context, c *websocket.Conn) error {
for i := 0; i < 10; i++ {
err := assertStreamPing(ctx, c, 125)
if err != nil {
return err
}
}

return c.Close(websocket.StatusNormalClosure, "")
})
})

// Section 3.
Expand Down Expand Up @@ -1964,11 +1961,17 @@ func assertStreamPing(ctx context.Context, c *websocket.Conn, l int) error {
if err != nil {
return fmt.Errorf("failed to write byte %d: %w", i, err)
}
err = c.BW().Flush()
if err != nil {
return fmt.Errorf("failed to flush byte %d: %w", i, err)
if i%32 == 0 {
err = c.BW().Flush()
if err != nil {
return fmt.Errorf("failed to flush at byte %d: %w", i, err)
}
}
}
err = c.BW().Flush()
if err != nil {
return fmt.Errorf("failed to flush: %v", err)
}
return assertReadFrame(ctx, c, websocket.OpPong, bytes.Repeat([]byte{0xFE}, l))
}

Expand Down

0 comments on commit 09910a2

Please sign in to comment.