From 7b09e30cbe4a30d04564d5939ae6812cb072f631 Mon Sep 17 00:00:00 2001 From: Abhishek Singh Chauhan Date: Thu, 11 Feb 2021 14:21:02 +0530 Subject: [PATCH] e2e: Resolved Flaky tests (#3777) * added retry function Signed-off-by: Abhishek357 * fixed CI test Signed-off-by: Abhishek357 * restructured code Signed-off-by: Abhishek357 --- test/e2e/query_test.go | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/test/e2e/query_test.go b/test/e2e/query_test.go index c027abda22..e36b0c7952 100644 --- a/test/e2e/query_test.go +++ b/test/e2e/query_test.go @@ -368,31 +368,32 @@ func checkNetworkRequests(t *testing.T, addr string) { ctx, cancel := chromedp.NewContext(context.Background()) t.Cleanup(cancel) - var networkErrors []string + testutil.Ok(t, runutil.Retry(1*time.Minute, ctx.Done(), func() error { + var networkErrors []string + + // Listen for failed network requests and push them to an array. + chromedp.ListenTarget(ctx, func(ev interface{}) { + switch ev := ev.(type) { + case *network.EventLoadingFailed: + networkErrors = append(networkErrors, ev.ErrorText) + } + }) + + err := chromedp.Run(ctx, + network.Enable(), + chromedp.Navigate(addr), + chromedp.WaitVisible(`body`), + ) - // Listen for failed network requests and push them to an array. - chromedp.ListenTarget(ctx, func(ev interface{}) { - switch ev := ev.(type) { - case *network.EventLoadingFailed: - networkErrors = append(networkErrors, ev.ErrorText) + if err != nil { + return err } - }) - - err := chromedp.Run(ctx, - network.Enable(), - chromedp.Navigate(addr), - chromedp.WaitVisible(`body`), - ) - testutil.Ok(t, err) - err = func() error { if len(networkErrors) > 0 { - return fmt.Errorf("some network requests failed: %s", strings.Join(networkErrors, "; ")) + err = fmt.Errorf("some network requests failed: %s", strings.Join(networkErrors, "; ")) } - return nil - }() - - testutil.Ok(t, err) + return err + })) } func mustURLParse(t *testing.T, addr string) *url.URL {