From b947d095520eb4fac026af423e28d33ed3abdbd8 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 2 Apr 2024 10:31:38 +0300 Subject: [PATCH] *: adjust WS connection RW deadlines Yet another attempt to close #3378. Signed-off-by: Anna Shaleva --- pkg/rpcclient/rpc_test.go | 4 ++-- pkg/rpcclient/wsclient_test.go | 12 ++++++------ pkg/services/rpcsrv/server_test.go | 4 ++-- pkg/services/rpcsrv/subscription_test.go | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/rpcclient/rpc_test.go b/pkg/rpcclient/rpc_test.go index 32d8d9ca8..9d6d4389f 100644 --- a/pkg/rpcclient/rpc_test.go +++ b/pkg/rpcclient/rpc_test.go @@ -1938,7 +1938,7 @@ func initTestServer(t *testing.T, resp string) *httptest.Server { ws, err := upgrader.Upgrade(w, req, nil) require.NoError(t, err) for { - err = ws.SetReadDeadline(time.Now().Add(2 * time.Second)) + err = ws.SetReadDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) _, p, err := ws.ReadMessage() if err != nil { @@ -1950,7 +1950,7 @@ func initTestServer(t *testing.T, resp string) *httptest.Server { t.Fatalf("Cannot decode request body: %s", req.Body) } response := wrapInitResponse(r, resp) - err = ws.SetWriteDeadline(time.Now().Add(2 * time.Second)) + err = ws.SetWriteDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) err = ws.WriteMessage(1, []byte(response)) if err != nil { diff --git a/pkg/rpcclient/wsclient_test.go b/pkg/rpcclient/wsclient_test.go index 02681fc40..78805fc15 100644 --- a/pkg/rpcclient/wsclient_test.go +++ b/pkg/rpcclient/wsclient_test.go @@ -163,7 +163,7 @@ func TestWSClientEvents(t *testing.T) { require.NoError(t, err) <-startSending for _, event := range events { - err = ws.SetWriteDeadline(time.Now().Add(2 * time.Second)) + err = ws.SetWriteDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) err = ws.WriteMessage(1, []byte(event)) if err != nil { @@ -308,7 +308,7 @@ func TestWSClientNonBlockingEvents(t *testing.T) { require.NoError(t, err) <-startSending for _, event := range events { - err = ws.SetWriteDeadline(time.Now().Add(2 * time.Second)) + err = ws.SetWriteDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) err = ws.WriteMessage(1, []byte(event)) if err != nil { @@ -738,14 +738,14 @@ func TestWSFilteredSubscriptions(t *testing.T) { var upgrader = websocket.Upgrader{} ws, err := upgrader.Upgrade(w, req, nil) require.NoError(t, err) - err = ws.SetReadDeadline(time.Now().Add(2 * time.Second)) + err = ws.SetReadDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) req := params.In{} err = ws.ReadJSON(&req) require.NoError(t, err) params := params.Params(req.RawParams) c.serverCode(t, ¶ms) - err = ws.SetWriteDeadline(time.Now().Add(2 * time.Second)) + err = ws.SetWriteDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) err = ws.WriteMessage(1, []byte(`{"jsonrpc": "2.0", "id": 1, "result": "0"}`)) require.NoError(t, err) @@ -793,7 +793,7 @@ func TestWSConcurrentAccess(t *testing.T) { ws, err := upgrader.Upgrade(w, req, nil) require.NoError(t, err) for { - err = ws.SetReadDeadline(time.Now().Add(2 * time.Second)) + err = ws.SetReadDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) _, p, err := ws.ReadMessage() if err != nil { @@ -819,7 +819,7 @@ func TestWSConcurrentAccess(t *testing.T) { case "getblockhash": response = fmt.Sprintf(`{"id":%s,"jsonrpc":"2.0","result":"0x157ca5e5b8cf8f84c9660502a3270b346011612bded1514a6847f877c433a9bb"}`, r.RawID) } - err = ws.SetWriteDeadline(time.Now().Add(2 * time.Second)) + err = ws.SetWriteDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) err = ws.WriteMessage(1, []byte(response)) if err != nil { diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index cf28d862c..4aa11876a 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -3473,10 +3473,10 @@ func doRPCCallOverWS(rpcCall string, url string, t *testing.T) []byte { c, r, err := dialer.Dial(url+"/ws", nil) require.NoError(t, err) defer r.Body.Close() - err = c.SetWriteDeadline(time.Now().Add(time.Second)) + err = c.SetWriteDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) require.NoError(t, c.WriteMessage(1, []byte(rpcCall))) - err = c.SetReadDeadline(time.Now().Add(time.Second)) + err = c.SetReadDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) _, body, err := c.ReadMessage() require.NoError(t, err) diff --git a/pkg/services/rpcsrv/subscription_test.go b/pkg/services/rpcsrv/subscription_test.go index fbc35bac1..48251a3f7 100644 --- a/pkg/services/rpcsrv/subscription_test.go +++ b/pkg/services/rpcsrv/subscription_test.go @@ -22,7 +22,7 @@ const testOverflow = false func wsReader(t *testing.T, ws *websocket.Conn, msgCh chan<- []byte, isFinished *atomic.Bool, readerToExitCh chan struct{}) { for !isFinished.Load() { - err := ws.SetReadDeadline(time.Now().Add(time.Second)) + err := ws.SetReadDeadline(time.Now().Add(5 * time.Second)) if isFinished.Load() { require.Error(t, err) break @@ -42,7 +42,7 @@ func wsReader(t *testing.T, ws *websocket.Conn, msgCh chan<- []byte, isFinished func callWSGetRaw(t *testing.T, ws *websocket.Conn, msg string, respCh <-chan []byte) *neorpc.Response { var resp = new(neorpc.Response) - require.NoError(t, ws.SetWriteDeadline(time.Now().Add(time.Second))) + require.NoError(t, ws.SetWriteDeadline(time.Now().Add(5*time.Second))) require.NoError(t, ws.WriteMessage(websocket.TextMessage, []byte(msg))) body := <-respCh @@ -556,11 +556,11 @@ func TestBadSubUnsub(t *testing.T) { } func doSomeWSRequest(t *testing.T, ws *websocket.Conn) { - require.NoError(t, ws.SetWriteDeadline(time.Now().Add(time.Second))) + require.NoError(t, ws.SetWriteDeadline(time.Now().Add(5*time.Second))) // It could be just about anything including invalid request, // we only care about server handling being active. require.NoError(t, ws.WriteMessage(websocket.TextMessage, []byte(`{"jsonrpc": "2.0", "method": "getversion", "params": [], "id": 1}`))) - err := ws.SetReadDeadline(time.Now().Add(time.Second)) + err := ws.SetReadDeadline(time.Now().Add(5 * time.Second)) require.NoError(t, err) _, _, err = ws.ReadMessage() require.NoError(t, err)