mirror of
https://github.com/golang/go
synced 2024-11-26 13:28:27 -07:00
net/http: deflake TestServerCancelsReadHeaderTimeoutWhenIdle
Return errors instead of calling t.Fatalf for timing-sensitive failure modes. Scale the Sleep call to the timeout (so that it isn't too short for the longer durations). Fixes #54891. Change-Id: I574e85e121becdda9ab8ee6bfd37c18a549d366d Reviewed-on: https://go-review.googlesource.com/c/go/+/430955 Reviewed-by: Joel Sing <joel@sing.id.au> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
2addbf3f2a
commit
a9ca741d31
@ -5872,23 +5872,23 @@ func TestServerCancelsReadHeaderTimeoutWhenIdle(t *testing.T) {
|
||||
defer conn.Close()
|
||||
|
||||
if _, err := conn.Write([]byte("GET / HTTP/1.1\r\nHost: e.com\r\n\r\n")); err != nil {
|
||||
t.Fatalf("writing first request failed: %v", err)
|
||||
return fmt.Errorf("writing first request failed: %v", err)
|
||||
}
|
||||
|
||||
if _, err := ReadResponse(br, nil); err != nil {
|
||||
t.Fatalf("first response (before timeout) failed: %v", err)
|
||||
return fmt.Errorf("first response (before timeout) failed: %v", err)
|
||||
}
|
||||
|
||||
// wait for longer than the server's ReadHeaderTimeout, and then send
|
||||
// another request
|
||||
time.Sleep(timeout + 10*time.Millisecond)
|
||||
time.Sleep(timeout * 3 / 2)
|
||||
|
||||
if _, err := conn.Write([]byte("GET / HTTP/1.1\r\nHost: e.com\r\n\r\n")); err != nil {
|
||||
t.Fatalf("writing second request failed: %v", err)
|
||||
return fmt.Errorf("writing second request failed: %v", err)
|
||||
}
|
||||
|
||||
if _, err := ReadResponse(br, nil); err != nil {
|
||||
t.Fatalf("second response (after timeout) failed: %v", err)
|
||||
return fmt.Errorf("second response (after timeout) failed: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user