Fixed ws dial input error being dropped

This commit is contained in:
bwilliams committed 2026-10-16 08:52:45 +01:00
1 parent 02e3d910a2
commit b714ee14d5
2 files changed
+38 -1

No files matched your search

+29
View File
@@ -3,6 +3,7 @@ package ws
import (
"bytes"
"context"
"errors"
"io"
"log/slog"
"net/http"
@@ -281,6 +282,34 @@ func TestDialStdin(t *testing.T) {
}
}
// Without --message, a failure reading stdin ends dial with an error, unlike
// the end of stdin.
func TestDialStdinError(t *testing.T) {
_, url := wsServer(t)
stdin, input := io.Pipe()
out := &syncBuffer{}
done := make(chan error, 1)
go func() {
done <- dial(context.Background(), stdin, out, dialSettings{
url: url,
timeout: time.Second,
})
}()
waitFor(t, out, `< {"type":"welcome"`)
input.CloseWithError(errors.New("disk on fire"))
select {
case err := <-done:
if err == nil || !strings.Contains(err.Error(), "reading input: disk on fire") {
t.Fatalf("dial = %v; want the input error", err)
}
case <-time.After(time.Second):
t.Fatal("dial did not return after the input error")
}
}
// Without --message, dial ends when the server closes the connection.
func TestDialStdinServerClose(t *testing.T) {
hub, url := wsServer(t)