Skip to content

Commit

Permalink
Merge pull request thanos-io#8005 from pedro-stanaka/fix-e2e-maybe
Browse files Browse the repository at this point in the history
Fixing E2E tests using headless Chrome
  • Loading branch information
fpetkovski authored Dec 18, 2024
2 parents 80c89fd + e2cb509 commit b881f6c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ jobs:
matrix:
parallelism: [8]
index: [0, 1, 2, 3, 4, 5, 6, 7]
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
name: Thanos end-to-end tests
env:
GOBIN: /tmp/.bin
Expand Down
51 changes: 27 additions & 24 deletions test/e2e/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,46 +1248,49 @@ func TestSidecarQueryEvaluation(t *testing.T) {
}
}

// An emptyCtx is never canceled, has no values, and has no deadline. It is not
// struct{}, since vars of this type must have distinct addresses.
type emptyCtx int
var chromedpAllocator context.Context

func (*emptyCtx) Deadline() (deadline time.Time, ok bool) {
return
}

func (*emptyCtx) Done() <-chan struct{} {
return nil
}

func (*emptyCtx) Err() error {
return nil
}

func (*emptyCtx) Value(key any) any {
return nil
}

func (e *emptyCtx) String() string {
return "Context"
func TestMain(m *testing.M) {
execAlloc, execCancel := chromedp.NewExecAllocator(
context.Background(),
)
chromedpAllocator = execAlloc
rc := m.Run()
execCancel()
os.Exit(rc)
}

func checkNetworkRequests(t *testing.T, addr string) {
ctx, cancel := chromedp.NewContext(new(emptyCtx))
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.Flag("headless", true),
chromedp.Flag("no-sandbox", true),
chromedp.Flag("disable-gpu", true),
)
allocCtx, cancel := chromedp.NewExecAllocator(chromedpAllocator, opts...)
defer cancel()

ctx, cancel := chromedp.NewContext(allocCtx)
t.Cleanup(cancel)

// make sure browser is already started
err := chromedp.Run(ctx)
testutil.Ok(t, err)

testutil.Ok(t, runutil.Retry(1*time.Minute, ctx.Done(), func() error {
var networkErrors []string

var newCtx context.Context
newCtx, newCancel := chromedp.NewContext(ctx)
t.Cleanup(newCancel)
// Listen for failed network requests and push them to an array.
chromedp.ListenTarget(ctx, func(ev interface{}) {
chromedp.ListenTarget(newCtx, func(ev interface{}) {
switch ev := ev.(type) {
case *network.EventLoadingFailed:
networkErrors = append(networkErrors, ev.ErrorText)
}
})

err := chromedp.Run(ctx,
err := chromedp.Run(newCtx,
network.Enable(),
chromedp.Navigate(addr),
chromedp.WaitVisible(`body`),
Expand Down

0 comments on commit b881f6c

Please sign in to comment.