Skip to content

Commit 4156b3c

Browse files
committed
remediate flaky timeout tests
1 parent fb205d8 commit 4156b3c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

middleware/timeout_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func TestTimeoutWithFullEchoStack(t *testing.T) {
375375

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

0 commit comments

Comments
 (0)