From be7c50a7101a6e3cbd39648814c9f1030980c0f6 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 3 Nov 2016 01:11:49 +0000 Subject: [PATCH] net/http: deflake TestServerSetKeepAlivesEnabledClosesConns Fixes #17754 Updates #9478 (details in here) Change-Id: Iae2c1ca05a18ed266b53b2594c22fc57fab33c5e Reviewed-on: https://go-review.googlesource.com/32587 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/net/http/export_test.go | 12 ++++++++++++ src/net/http/serve_test.go | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/net/http/export_test.go b/src/net/http/export_test.go index fbed45070c8..40f87dc8e94 100644 --- a/src/net/http/export_test.go +++ b/src/net/http/export_test.go @@ -186,3 +186,15 @@ func ExportHttp2ConfigureTransport(t *Transport) error { } var Export_shouldCopyHeaderOnRedirect = shouldCopyHeaderOnRedirect + +func (s *Server) ExportAllConnsIdle() bool { + s.mu.Lock() + defer s.mu.Unlock() + for c := range s.activeConn { + st, ok := c.curState.Load().(ConnState) + if !ok || st != StateIdle { + return false + } + } + return true +} diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go index f855c358221..fe63c6925f7 100644 --- a/src/net/http/serve_test.go +++ b/src/net/http/serve_test.go @@ -4875,6 +4875,9 @@ func TestServerSetKeepAlivesEnabledClosesConns(t *testing.T) { }) { t.Fatalf("idle count before SetKeepAlivesEnabled called = %v; want 1", idle0) } + if !waitCondition(2*time.Second, 10*time.Millisecond, ts.Config.ExportAllConnsIdle) { + t.Fatalf("test server has active conns") + } ts.Config.SetKeepAlivesEnabled(false)