Skip to content

Commit

Permalink
net/http: use t.Deadline instead of an arbitrary timeout in TestServe…
Browse files Browse the repository at this point in the history
…rConnState

Updates #37322

Change-Id: I3b8369cd9e0ed5e4b3136cedaa2f70698ead2270
Reviewed-on: https://go-review.googlesource.com/c/go/+/222957
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
  • Loading branch information
Bryan C. Mills committed Mar 11, 2020
1 parent 035c018 commit 0e3ace4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/net/http/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4135,10 +4135,19 @@ func TestServerConnState(t *testing.T) {

doRequests()

timer := time.NewTimer(5 * time.Second)
stateDelay := 5 * time.Second
if deadline, ok := t.Deadline(); ok {
// Allow an arbitrarily long delay.
// This test was observed to be flaky on the darwin-arm64-corellium builder,
// so we're increasing the deadline to see if it starts passing.
// See https://golang.org/issue/37322.
const arbitraryCleanupMargin = 1 * time.Second
stateDelay = time.Until(deadline) - arbitraryCleanupMargin
}
timer := time.NewTimer(stateDelay)
select {
case <-timer.C:
t.Errorf("Timed out waiting for connection to change state.")
t.Errorf("Timed out after %v waiting for connection to change state.", stateDelay)
case <-complete:
timer.Stop()
}
Expand Down

0 comments on commit 0e3ace4

Please sign in to comment.