Skip to content

Commit

Permalink
remediate flaky timeout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aldas committed Feb 19, 2023
1 parent a3998ac commit 2c25767
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions middleware/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 2c25767

Please sign in to comment.