1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-28 08:38:39 +02:00

remediate flaky timeout tests

This commit is contained in:
toimtoimtoim 2023-02-19 10:38:34 +02:00 committed by Martti T
parent a3998ac96a
commit 2c25767e45

View File

@ -375,7 +375,7 @@ func TestTimeoutWithFullEchoStack(t *testing.T) {
// NOTE: timeout middleware is first as it changes Response.Writer and causes data race for logger middleware if it is not first
e.Use(TimeoutWithConfig(TimeoutConfig{
Timeout: 15 * time.Millisecond,
Timeout: 100 * time.Millisecond,
}))
e.Use(Logger())
e.Use(Recover())
@ -403,8 +403,13 @@ func TestTimeoutWithFullEchoStack(t *testing.T) {
}
if tc.whenForceHandlerTimeout {
wg.Done()
// extremely short periods are not reliable for tests when it comes to goroutines. We can not guarantee in which
// order scheduler decides do execute: 1) request goroutine, 2) timeout timer goroutine.
// most of the time we get result we expect but Mac OS seems to be quite flaky
time.Sleep(50 * time.Millisecond)
// shutdown waits for server to shutdown. this way we wait logger mw to be executed
ctx, cancel := context.WithTimeout(context.Background(), 150*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
defer cancel()
server.Shutdown(ctx)
}