Skip to content

Commit

Permalink
Fix flaky TestConnPrepareContext
Browse files Browse the repository at this point in the history
TestConnPrepareContext checks it receives an context.DeadlineExceeded. However,
the context isn't necessarily always expired. This causes most of the test runs
to fail for me, only occasionally succeeding. This change ensures the context
used in the test is actually context.DeadlineExceeded. The negative duration
causes the context package to return an already canceled context.
  • Loading branch information
mjl- committed Oct 19, 2021
1 parent 26399a7 commit 2b4fa17
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ func TestConnPrepareContext(t *testing.T) {
{
name: "context.WithTimeout exceeded",
ctx: func() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), time.Microsecond)
return context.WithTimeout(context.Background(), -time.Minute)
},
sql: "SELECT 1",
err: context.DeadlineExceeded,
Expand Down

0 comments on commit 2b4fa17

Please sign in to comment.