Skip to content

Commit

Permalink
Fix leaked temp dirs when run TestConcurrentCancel (#1272)
Browse files Browse the repository at this point in the history
When executing the command:
```
go test -run ^TestConcurrentCancel$ github.com/chromedp/chromedp -count=1 -v -race
```
panic appears:
```
leaked 38 temporary dirs under /var/folders/hj/d_p08kpd495fj0zprd5m51500000gp/T/chromedp-test3640163383
```
  • Loading branch information
alexandear committed Mar 2, 2023
1 parent 448735f commit 29a0edd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions chromedp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,21 @@ func TestConcurrentCancel(t *testing.T) {
ExecPath("/do-not-run-chrome"))
defer cancel()

var wg sync.WaitGroup
// 50 is enough for 'go test -race' to easily spot issues.
for i := 0; i < 50; i++ {
wg.Add(2)
ctx, cancel := NewContext(allocCtx)
go cancel()
go Run(ctx)
go func() {
cancel()
wg.Done()
}()
go func() {
_ = Run(ctx)
wg.Done()
}()
}
wg.Wait()
}

func TestListenBrowser(t *testing.T) {
Expand Down

0 comments on commit 29a0edd

Please sign in to comment.