Skip to content

Commit

Permalink
test/e2e: do not share chromedp allocators (#6567)
Browse files Browse the repository at this point in the history
Tests crash sometimes now with:
```
panic: close of closed channel

goroutine 1793 [running]:
github.com/chromedp/chromedp.(*ExecAllocator).Allocate.func2()
	/home/runner/go/pkg/mod/github.com/chromedp/chromedp@v0.8.2/allocate.go:224 +0xca
created by github.com/chromedp/chromedp.(*ExecAllocator).Allocate
	/home/runner/go/pkg/mod/github.com/chromedp/chromedp@v0.8.2/allocate.go:210 +0xd05
```

context.Background() returns the same context for each call and chromedp
shares allocators using that context. If we are unfortunate then they
both try to close a channel at the same time.

Try to workaround this by allocating a context for each
checkNetworkRequests call.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
  • Loading branch information
GiedriusS authored Jul 28, 2023
1 parent 2790de4 commit 3e727a0
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/e2e/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1448,8 +1448,32 @@ 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

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 checkNetworkRequests(t *testing.T, addr string) {
ctx, cancel := chromedp.NewContext(context.Background())
ctx, cancel := chromedp.NewContext(new(emptyCtx))
t.Cleanup(cancel)

testutil.Ok(t, runutil.Retry(1*time.Minute, ctx.Done(), func() error {
Expand Down

0 comments on commit 3e727a0

Please sign in to comment.