Files
Maciej Borzecki ac30266eb5 cmd/snap-bootstrap/triggerwatch: fix data race in tests (#13794)
go test -race complains about data race, which isn't entirely accurate as the
goroutine which may modify the data has exited by the time checks are done.
However, should we want to enable -race as part of the test suite, this fixes a
blocker.

```
==================
WARNING: DATA RACE
Read at 0x00c0000123a8 by goroutine 16:
  github.com/snapcore/snapd/cmd/snap-bootstrap/triggerwatch_test.(*triggerwatchSuite).TestNoDevsWaitKeyTimeout()
      /home/maciek/work/canonical/snapd/cmd/snap-bootstrap/triggerwatch/triggerwatch_test.go:118 +0x3e5
  runtime.call16()
      /usr/lib/go/src/runtime/asm_amd64.s:770 +0x42
  reflect.Value.Call()
      /usr/lib/go/src/reflect/value.go:380 +0xb5
  gopkg.in/check%2ev1.(*suiteRunner).forkTest.func1()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:775 +0x9c5
  gopkg.in/check%2ev1.(*suiteRunner).forkCall.func1()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:669 +0xe9

Previous write at 0x00c0000123a8 by goroutine 18:
  github.com/snapcore/snapd/cmd/snap-bootstrap/triggerwatch_test.(*mockTriggerDevice).WaitForTrigger()
      /home/maciek/work/canonical/snapd/cmd/snap-bootstrap/triggerwatch/triggerwatch_test.go:48 +0x44
  github.com/snapcore/snapd/cmd/snap-bootstrap/triggerwatch.Wait.gowrap2()
      /home/maciek/work/canonical/snapd/cmd/snap-bootstrap/triggerwatch/triggerwatch.go:112 +0x50

Goroutine 16 (running) created at:
  gopkg.in/check%2ev1.(*suiteRunner).forkCall()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:666 +0x5ba
  gopkg.in/check%2ev1.(*suiteRunner).forkTest()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:757 +0x155
  gopkg.in/check%2ev1.(*suiteRunner).runTest()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:812 +0x419
  gopkg.in/check%2ev1.(*suiteRunner).run()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:618 +0x3c6
  gopkg.in/check%2ev1.Run()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:92 +0x44
  gopkg.in/check%2ev1.RunAll()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:84 +0x124
  gopkg.in/check%2ev1.TestingT()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/run.go:72 +0x5d3
  github.com/snapcore/snapd/cmd/snap-bootstrap/triggerwatch_test.Test()
      /home/maciek/work/canonical/snapd/cmd/snap-bootstrap/triggerwatch/triggerwatch_test.go:35 +0x26
  testing.tRunner()
      /usr/lib/go/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /usr/lib/go/src/testing/testing.go:1742 +0x44

Goroutine 18 (finished) created at:
  github.com/snapcore/snapd/cmd/snap-bootstrap/triggerwatch.Wait()
      /home/maciek/work/canonical/snapd/cmd/snap-bootstrap/triggerwatch/triggerwatch.go:112 +0x94b
  github.com/snapcore/snapd/cmd/snap-bootstrap/triggerwatch_test.(*triggerwatchSuite).TestNoDevsWaitKeyTimeout()
      /home/maciek/work/canonical/snapd/cmd/snap-bootstrap/triggerwatch/triggerwatch_test.go:115 +0x21b
  runtime.call16()
      /usr/lib/go/src/runtime/asm_amd64.s:770 +0x42
  reflect.Value.Call()
      /usr/lib/go/src/reflect/value.go:380 +0xb5
  gopkg.in/check%2ev1.(*suiteRunner).forkTest.func1()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:775 +0x9c5
  gopkg.in/check%2ev1.(*suiteRunner).forkCall.func1()
      /home/maciek/work/canonical/snapd/vendor/gopkg.in/check.v1/check.go:669 +0xe9
==================
```

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-04-08 11:24:55 +02:00
..