diff options
| author | Pawel Stolowski <stolowski@gmail.com> | 2019-02-28 12:42:40 +0100 |
|---|---|---|
| committer | Pawel Stolowski <stolowski@gmail.com> | 2019-02-28 12:42:40 +0100 |
| commit | aa0788c7561456e73a6ad06f64d93d96327da22c (patch) | |
| tree | 41ab5fc3929784b3b35e77f26537f7d18ada75af | |
| parent | bd668150b246763616fcc45b78abf50f221d003e (diff) | |
Fix/improve udev mon test: stop udev mon from goroutine with a timeout. Simplify check around callbackChannel to only expect known number of calls.fix-udevmon-test
| -rw-r--r-- | overlord/ifacestate/udevmonitor/udevmon_test.go | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/overlord/ifacestate/udevmonitor/udevmon_test.go b/overlord/ifacestate/udevmonitor/udevmon_test.go index 3060ae3ebf..f29a948c98 100644 --- a/overlord/ifacestate/udevmonitor/udevmon_test.go +++ b/overlord/ifacestate/udevmonitor/udevmon_test.go @@ -58,6 +58,8 @@ func (s *udevMonitorSuite) TestDiscovery(c *C) { callbackChannel <- struct{}{} } removed := func(inf *hotplug.HotplugDeviceInfo) { + // we should see just one removal + c.Check(remInfo, IsNil) remInfo = inf callbackChannel <- struct{}{} } @@ -133,27 +135,38 @@ E: DEVTYPE=bzz } }() - // expect three add events - one from udev event, two from enumeration. - const numExpectedDevices = 3 + calls := 0 Loop: for { select { case <-callbackChannel: - if len(addInfos) == numExpectedDevices && remInfo != nil && enumerationDone { + calls++ + if calls == 5 { break Loop } case <-time.After(3 * time.Second): c.Error("Did not receive expected devices before timeout") break Loop - default: } } + c.Check(calls, Equals, 5) + c.Check(enumerationDone, Equals, true) + // expect three add events - one from udev event, two from enumeration. + c.Assert(addInfos, HasLen, 3) c.Assert(remInfo, NotNil) - c.Assert(addInfos, HasLen, numExpectedDevices) - c.Assert(enumerationDone, Equals, true) - c.Assert(udevmon.Stop(), IsNil) + stopChannel := make(chan struct{}) + defer close(stopChannel) + go func() { + c.Assert(udevmon.Stop(), IsNil) + stopChannel <- struct{}{} + }() + select { + case <-stopChannel: + case <-time.After(3 * time.Second): + c.Error("udev monitor did not stop before timeout") + } addInfo := addInfos[0] c.Assert(addInfo.DeviceName(), Equals, "name") |
