mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
Fix unit test
This commit is contained in:
parent
9cd4ededf1
commit
539ff2aae1
1 changed files with 19 additions and 7 deletions
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -28,6 +29,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServerRegisterName(t *testing.T) {
|
func TestServerRegisterName(t *testing.T) {
|
||||||
|
|
@ -217,14 +220,14 @@ func TestServerWebsocketReadLimit(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "limit with small request - should succeed",
|
name: "limit with small request - should succeed",
|
||||||
readLimit: 2048,
|
readLimit: 4096, // generous limit to comfortably allow JSON overhead
|
||||||
testSize: 500, // Small request data
|
testSize: 256, // reasonably small payload
|
||||||
shouldFail: false,
|
shouldFail: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "limit with large request - should fail",
|
name: "limit with large request - should fail",
|
||||||
readLimit: 2048,
|
readLimit: 256, // tight limit to trigger server-side read limit
|
||||||
testSize: 5000, // Large request data that should exceed limit
|
testSize: 1024, // payload that will exceed the limit including JSON overhead
|
||||||
shouldFail: true,
|
shouldFail: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -261,9 +264,18 @@ func TestServerWebsocketReadLimit(t *testing.T) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected error for request size %d with limit %d, but got none", tc.testSize, tc.readLimit)
|
t.Fatalf("expected error for request size %d with limit %d, but got none", tc.testSize, tc.readLimit)
|
||||||
}
|
}
|
||||||
// Check if it's the expected message size limit error
|
// Be tolerant about the exact error surfaced by gorilla/websocket.
|
||||||
if !strings.Contains(err.Error(), "message too big") {
|
// Prefer a CloseError with code 1009, but accept ErrReadLimit or an error string containing 1009/message too big.
|
||||||
t.Fatalf("expected 'message too big' error, got: %v", err)
|
var cerr *websocket.CloseError
|
||||||
|
if errors.As(err, &cerr) {
|
||||||
|
if cerr.Code != websocket.CloseMessageTooBig {
|
||||||
|
t.Fatalf("unexpected websocket close code: have %d want %d (err=%v)", cerr.Code, websocket.CloseMessageTooBig, err)
|
||||||
|
}
|
||||||
|
} else if !errors.Is(err, websocket.ErrReadLimit) &&
|
||||||
|
!strings.Contains(strings.ToLower(err.Error()), "1009") &&
|
||||||
|
!strings.Contains(strings.ToLower(err.Error()), "message too big") {
|
||||||
|
// Not the error we expect from exceeding the message size limit.
|
||||||
|
t.Fatalf("unexpected error for read limit violation: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Expecting success
|
// Expecting success
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue