fix flaky TestDoOutgoingWebhookRequest/with_a_slow_response (#11712)

Avoid relying on `time.Sleep` to assert timeout behaviour.
Этот коммит содержится в:
Jesse Hallam
2019-07-31 14:25:17 -03:00
коммит произвёл GitHub
родитель ee007962f4
Коммит 53cae67ede

Просмотреть файл

@@ -724,15 +724,16 @@ func TestDoOutgoingWebhookRequest(t *testing.T) {
}) })
t.Run("with a slow response", func(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) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(timeout + time.Millisecond) // Don't actually handle the response, allowing the app to timeout.
io.Copy(w, strings.NewReader(`{"text": "Hello, World!"}`)) <-releaseHandler
})) }))
defer server.Close() defer server.Close()
defer close(releaseHandler)
th.App.HTTPService.(*httpservice.HTTPServiceImpl).RequestTimeout = timeout th.App.HTTPService.(*httpservice.HTTPServiceImpl).RequestTimeout = 500 * time.Millisecond
defer func() { defer func() {
th.App.HTTPService.(*httpservice.HTTPServiceImpl).RequestTimeout = httpservice.RequestTimeout th.App.HTTPService.(*httpservice.HTTPServiceImpl).RequestTimeout = httpservice.RequestTimeout
}() }()