From eaf08892f5b8b34d668daf40f6ddfc37be43de29 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Thu, 28 Feb 2019 12:23:08 -0600 Subject: [PATCH] [Heartbeat] Fix flaky SSL test with retries. (#10789) Sometimes the httptest package when using fancy TLS options doesn't put the server up as fast as it should (at least that's the theory), and we hit before it's ready, causing a false test failure. This patch makes those tests more resilient. It's possible there's something else at work here, but this bug is only seen on CI, and impossible to repro on my laptop. Fixes https://github.com/elastic/beats/issues/10722 --- heartbeat/monitors/active/http/http_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/heartbeat/monitors/active/http/http_test.go b/heartbeat/monitors/active/http/http_test.go index bd5bd1f5dd40..c6ebef484d1b 100644 --- a/heartbeat/monitors/active/http/http_test.go +++ b/heartbeat/monitors/active/http/http_test.go @@ -27,7 +27,9 @@ import ( "net/url" "os" "path" + "reflect" "testing" + "time" "github.com/stretchr/testify/require" @@ -279,7 +281,16 @@ func runHTTPSServerCheck( mergedExtraConfig[k] = v } - event := testTLSRequest(t, server.URL, mergedExtraConfig) + // Sometimes the test server can take a while to start. Since we're only using this to test up statuses, + // we give it a few attempts to see if the server can come up before we run the real assertions. + var event *beat.Event + for i := 0; i < 10; i++ { + event = testTLSRequest(t, server.URL, mergedExtraConfig) + if v, err := event.GetValue("monitor.status"); err == nil && reflect.DeepEqual(v, "up") { + break + } + time.Sleep(time.Millisecond * 500) + } mapval.Test( t,