Skip to content

Commit 5e13b42

Browse files
fpetkovskijnyi
authored andcommitted
Merge pull request thanos-io#8005 from pedro-stanaka/fix-e2e-maybe
Fixing E2E tests using headless Chrome
1 parent e99f22f commit 5e13b42

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

test/e2e/query_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,21 +1261,36 @@ func TestMain(m *testing.M) {
12611261
}
12621262

12631263
func checkNetworkRequests(t *testing.T, addr string) {
1264-
ctx, cancel := chromedp.NewContext(chromedpAllocator)
1264+
opts := append(chromedp.DefaultExecAllocatorOptions[:],
1265+
chromedp.Flag("headless", true),
1266+
chromedp.Flag("no-sandbox", true),
1267+
chromedp.Flag("disable-gpu", true),
1268+
)
1269+
allocCtx, cancel := chromedp.NewExecAllocator(chromedpAllocator, opts...)
1270+
defer cancel()
1271+
1272+
ctx, cancel := chromedp.NewContext(allocCtx)
12651273
t.Cleanup(cancel)
12661274

1275+
// make sure browser is already started
1276+
err := chromedp.Run(ctx)
1277+
testutil.Ok(t, err)
1278+
12671279
testutil.Ok(t, runutil.Retry(1*time.Minute, ctx.Done(), func() error {
12681280
var networkErrors []string
12691281

1282+
var newCtx context.Context
1283+
newCtx, newCancel := chromedp.NewContext(ctx)
1284+
t.Cleanup(newCancel)
12701285
// Listen for failed network requests and push them to an array.
1271-
chromedp.ListenTarget(ctx, func(ev interface{}) {
1286+
chromedp.ListenTarget(newCtx, func(ev interface{}) {
12721287
switch ev := ev.(type) {
12731288
case *network.EventLoadingFailed:
12741289
networkErrors = append(networkErrors, ev.ErrorText)
12751290
}
12761291
})
12771292

1278-
err := chromedp.Run(ctx,
1293+
err := chromedp.Run(newCtx,
12791294
network.Enable(),
12801295
chromedp.Navigate(addr),
12811296
chromedp.WaitVisible(`body`),

0 commit comments

Comments
 (0)