cmd/screentest: fix double-close bug
The closure in waitForEvent can be called more than once.
Make sure we only close the channel once.
Change-Id: I5bde4d970bbda238d4cd3414234d45c957420fbd
Reviewed-on: https://go-review.googlesource.com/c/website/+/631695
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/cmd/screentest/screentest.go b/cmd/screentest/screentest.go
index 3542f57..59902e1 100644
--- a/cmd/screentest/screentest.go
+++ b/cmd/screentest/screentest.go
@@ -735,13 +735,18 @@
func waitForEvent(eventName string) chromedp.ActionFunc {
return func(ctx context.Context) error {
ch := make(chan struct{})
+ closed := false
cctx, cancel := context.WithCancel(ctx)
defer cancel()
chromedp.ListenTarget(cctx, func(ev any) {
+
switch e := ev.(type) {
case *page.EventLifecycleEvent:
if e.Name == eventName {
- close(ch)
+ if !closed {
+ close(ch)
+ closed = true
+ }
}
}
})