fix(server): suppress expected websocket close write errors

This commit is contained in:
richjohnrambo
2026-10-11 22:50:54 +08:00
parent 1e0b4c181d
commit c219ef6455
2 changed files with 38 additions and 2 deletions
+25
View File
@@ -37,6 +37,31 @@ func TestClassifyWSError(t *testing.T) {
}
}
func TestShouldLogWSWriteError(t *testing.T) {
tests := []struct {
reason string
want bool
}{
{reason: "close_normal", want: false},
{reason: "close_going_away", want: false},
{reason: "closed", want: false},
{reason: "eof", want: false},
{reason: "broken_pipe", want: false},
{reason: "connection_reset", want: false},
{reason: "timeout", want: true},
{reason: "close_abnormal", want: true},
{reason: "other", want: true},
}
for _, tc := range tests {
t.Run(tc.reason, func(t *testing.T) {
if got := shouldLogWSWriteError(tc.reason); got != tc.want {
t.Fatalf("shouldLogWSWriteError(%q)=%v want %v", tc.reason, got, tc.want)
}
})
}
}
func TestWebSocketOutboundQueueTiming(t *testing.T) {
sess := &Session{proto: WEBSOCK, send: make(chan any, 2)}
payload := []byte("message")