forked from TrueCloudLab/neoneo-go
rpcsrv: fix TestWSClientsLimit
Made connections in parallel to check the limit and attempt to make one more connection beyond the limit. Only "default" test case is failing, because default number of connections is 64 (quite large for slow runners). The failure reason is: * given ~1 second for [dealing + request] per connection (time is taken from the test log) * by the moment 65-th connection is reached, some connections from the start of the test have died due to inactivity (this process literally takes 1 minute) Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
parent
0280ceefe6
commit
698bdc7eea
1 changed files with 26 additions and 13 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -604,25 +605,37 @@ func TestWSClientsLimit(t *testing.T) {
|
||||||
dialer := websocket.Dialer{HandshakeTimeout: 5 * time.Second}
|
dialer := websocket.Dialer{HandshakeTimeout: 5 * time.Second}
|
||||||
url := "ws" + strings.TrimPrefix(httpSrv.URL, "http") + "/ws"
|
url := "ws" + strings.TrimPrefix(httpSrv.URL, "http") + "/ws"
|
||||||
wss := make([]*websocket.Conn, effectiveClients)
|
wss := make([]*websocket.Conn, effectiveClients)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
for i := 0; i < len(wss)+1; i++ {
|
// Dial effectiveClients connections in parallel
|
||||||
|
for i := 0; i < effectiveClients; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
j := i
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
ws, r, err := dialer.Dial(url, nil)
|
ws, r, err := dialer.Dial(url, nil)
|
||||||
if r != nil && r.Body != nil {
|
if r != nil {
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
}
|
}
|
||||||
if i < effectiveClients {
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
wss[i] = ws
|
wss[j] = ws
|
||||||
// Check that it's completely ready.
|
|
||||||
doSomeWSRequest(t, ws)
|
doSomeWSRequest(t, ws)
|
||||||
} else {
|
}()
|
||||||
require.Error(t, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
// Attempt one more connection, which should fail
|
||||||
|
_, r, err := dialer.Dial(url, nil)
|
||||||
|
require.Error(t, err, "The connection beyond the limit should fail")
|
||||||
|
if r != nil {
|
||||||
|
r.Body.Close()
|
||||||
}
|
}
|
||||||
// Check connections are still alive (it actually is necessary to add
|
// Check connections are still alive (it actually is necessary to add
|
||||||
// some use of wss to keep connections alive).
|
// some use of wss to keep connections alive).
|
||||||
for i := 0; i < len(wss); i++ {
|
for _, ws := range wss {
|
||||||
doSomeWSRequest(t, wss[i])
|
doSomeWSRequest(t, ws)
|
||||||
|
ws.Close()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue