From b977e305d28c385cc208425edc5af26055534f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 7 Apr 2019 18:49:53 +0200 Subject: [PATCH] fix regression when using Run twice on the first ctx We don't want to always set c.first, as that can change the field from true to false. --- context.go | 4 ++-- context_test.go | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) 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) + } }