mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-21 23:29:38 +00:00
*: adjust WS connection RW deadlines
Yet another attempt to close #3378. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
5c995e71b5
commit
b947d09552
4 changed files with 14 additions and 14 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue