mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 00:14:00 +00:00
fix(multiplayer): bound websocket writes
This commit is contained in:
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -25,6 +26,24 @@ func TestWebSocketReaderRejectsOversizedControlFrame(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebSocketWriterDoesNotBlockForeverOnSlowClient(t *testing.T) {
|
||||
sender, receiver := net.Pipe()
|
||||
defer sender.Close()
|
||||
defer receiver.Close()
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
done <- writeWebSocketFrameWithDeadline(sender, 0x1, bytes.Repeat([]byte{'x'}, maxWebSocketFrame), 20*time.Millisecond)
|
||||
}()
|
||||
select {
|
||||
case err := <-done:
|
||||
if err == nil {
|
||||
t.Fatal("write to a non-reading client unexpectedly succeeded")
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("write to a non-reading client blocked past its deadline")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebSocketHandshakeRequiresRFC6455Version(t *testing.T) {
|
||||
service := &Service{}
|
||||
request := httptest.NewRequest(http.MethodGet, "/v1/events", nil)
|
||||
|
||||
Reference in New Issue
Block a user