diff --git a/context.go b/context.go index 9d457e1..08d824a 100644 --- a/context.go +++ b/context.go @@ -114,13 +114,13 @@ func Run(ctx context.Context, actions ...Action) error { if c == nil || c.Allocator == nil { return ErrInvalidContext } - c.first = c.Browser == nil - if c.first { + if c.Browser == nil { browser, err := c.Allocator.Allocate(ctx) if err != nil { return err } c.Browser = browser + c.first = true } if c.Target == nil { if err := c.newSession(ctx); err != nil { diff --git a/context_test.go b/context_test.go index 94b69d1..402d097 100644 --- a/context_test.go +++ b/context_test.go @@ -41,4 +41,10 @@ func TestTargets(t *testing.T) { // Cancelling the second context should close the second tab alone. cancel2() wantTargets(ctx1, 1) + + // We used to have a bug where Run would reset the first context as if + // it weren't the first, breaking its cancellation. + if err := Run(ctx1); err != nil { + t.Fatal(err) + } }