services/device/deviced/internal/impl/utiltest: remove source of Stop flakiness
There's a race between the app calling ShutdownOnSignals and the device
manager sending the app cycle manager a remote stop (which the test
logic may do after waiting for the ping). If the latter wins, the app
exits immediately since there's no signal listener registered. To
remove the race, we first register a shutdown listener before calling ping.
Change-Id: Ide2d04d82c45ae7cb9f051fcf9f764b6d478ae18
diff --git a/services/device/deviced/internal/impl/utiltest/app.go b/services/device/deviced/internal/impl/utiltest/app.go
index ab31297..e425083 100644
--- a/services/device/deviced/internal/impl/utiltest/app.go
+++ b/services/device/deviced/internal/impl/utiltest/app.go
@@ -139,9 +139,11 @@
// Some of our tests look for log files, so make sure they are flushed
// to ensure that at least the files exist.
ctx.FlushLog()
+
+ shutdownChan := signals.ShutdownOnSignals(ctx)
ping(ctx, *flagValue)
- <-signals.ShutdownOnSignals(ctx)
+ <-shutdownChan
if err := ioutil.WriteFile("testfile", []byte("goodbye world"), 0600); err != nil {
ctx.Fatalf("Failed to write testfile: %v", err)
}