Skip to content

Commit

Permalink
e2e: Resolved Flaky tests (#3777)
Browse files Browse the repository at this point in the history
* added retry function

Signed-off-by: Abhishek357 <[email protected]>

* fixed CI test

Signed-off-by: Abhishek357 <[email protected]>

* restructured code

Signed-off-by: Abhishek357 <[email protected]>
  • Loading branch information
Abhishek357 authored Feb 11, 2021
1 parent a540df6 commit 7b09e30
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions test/e2e/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7b09e30

Please sign in to comment.