Fix flaky tests.
Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com>
This commit is contained in:
parent
71ca237478
commit
3c8675bb8b
5 changed files with 33 additions and 15 deletions
|
@ -70,6 +70,8 @@ func testShutdown(t *testing.T, router *tcp.Router) {
|
|||
|
||||
epConfig.LifeCycle.RequestAcceptGraceTimeout = 0
|
||||
epConfig.LifeCycle.GraceTimeOut = ptypes.Duration(5 * time.Second)
|
||||
epConfig.RespondingTimeouts.ReadTimeout = ptypes.Duration(5 * time.Second)
|
||||
epConfig.RespondingTimeouts.WriteTimeout = ptypes.Duration(5 * time.Second)
|
||||
|
||||
entryPoint, err := NewTCPEntryPoint(context.Background(), &static.EntryPoint{
|
||||
// We explicitly use an IPV4 address because on Alpine, with an IPV6 address
|
||||
|
@ -97,6 +99,11 @@ func testShutdown(t *testing.T, router *tcp.Router) {
|
|||
err = request.Write(conn)
|
||||
require.NoError(t, err)
|
||||
|
||||
reader := bufio.NewReader(conn)
|
||||
// Wait for first byte in response.
|
||||
_, err = reader.Peek(1)
|
||||
require.NoError(t, err)
|
||||
|
||||
go entryPoint.Shutdown(context.Background())
|
||||
|
||||
// Make sure that new connections are not permitted anymore.
|
||||
|
@ -123,7 +130,7 @@ func testShutdown(t *testing.T, router *tcp.Router) {
|
|||
|
||||
// And make sure that the connection we had opened before shutting things down is still operational
|
||||
|
||||
resp, err := http.ReadResponse(bufio.NewReader(conn), request)
|
||||
resp, err := http.ReadResponse(reader, request)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
}
|
||||
|
@ -133,22 +140,17 @@ func startEntrypoint(entryPoint *TCPEntryPoint, router *tcp.Router) (net.Conn, e
|
|||
|
||||
entryPoint.SwitchRouter(router)
|
||||
|
||||
var conn net.Conn
|
||||
var err error
|
||||
var epStarted bool
|
||||
for i := 0; i < 10; i++ {
|
||||
conn, err = net.Dial("tcp", entryPoint.listener.Addr().String())
|
||||
conn, err := net.Dial("tcp", entryPoint.listener.Addr().String())
|
||||
if err != nil {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
epStarted = true
|
||||
break
|
||||
|
||||
return conn, err
|
||||
}
|
||||
if !epStarted {
|
||||
return nil, errors.New("entry point never started")
|
||||
}
|
||||
return conn, err
|
||||
|
||||
return nil, errors.New("entry point never started")
|
||||
}
|
||||
|
||||
func TestReadTimeoutWithoutFirstByte(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue