From 53cae67edea498aa252cb989f49008984ad4451e Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Wed, 31 Jul 2019 14:25:17 -0300 Subject: [PATCH] fix flaky TestDoOutgoingWebhookRequest/with_a_slow_response (#11712) Avoid relying on `time.Sleep` to assert timeout behaviour. --- app/webhook_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/webhook_test.go b/app/webhook_test.go index f0c39b72b6..bf9a23a053 100644 --- a/app/webhook_test.go +++ b/app/webhook_test.go @@ -724,15 +724,16 @@ func TestDoOutgoingWebhookRequest(t *testing.T) { }) t.Run("with a slow response", func(t *testing.T) { - timeout := 100 * time.Millisecond + releaseHandler := make(chan interface{}) server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - time.Sleep(timeout + time.Millisecond) - io.Copy(w, strings.NewReader(`{"text": "Hello, World!"}`)) + // Don't actually handle the response, allowing the app to timeout. + <-releaseHandler })) defer server.Close() + defer close(releaseHandler) - th.App.HTTPService.(*httpservice.HTTPServiceImpl).RequestTimeout = timeout + th.App.HTTPService.(*httpservice.HTTPServiceImpl).RequestTimeout = 500 * time.Millisecond defer func() { th.App.HTTPService.(*httpservice.HTTPServiceImpl).RequestTimeout = httpservice.RequestTimeout }()