From f0d77eb1ceed2afc99c819cd9e56494b2082ca9d Mon Sep 17 00:00:00 2001 From: Ben Hoyt Date: Fri, 18 Aug 2023 14:48:06 +1200 Subject: [PATCH] Use reaper to run shutdown command if reaper is running Currently the TestRebootHelper test fails intermittently with the following failure: daemon_test.go:773: c.Assert(err, IsNil) ... value *os.SyscallError = &os.SyscallError{Syscall:"wait", Err:0xa} ("wait: no child processes") This is because we're running the reaper, but systemdModeReboot doesn't use or know about the reaper. So avoid starting/stopping the reaper in the setup and teardown; daemon.New and Daemon.Stop -- via the service manager) starts/stop it in any case. And set the FakeCommand withReaper flag to false here as the reaper isn't running there now. Fixes #186 --- internals/daemon/daemon_test.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/internals/daemon/daemon_test.go b/internals/daemon/daemon_test.go index ee30710a..fb701131 100644 --- a/internals/daemon/daemon_test.go +++ b/internals/daemon/daemon_test.go @@ -38,7 +38,6 @@ import ( "github.com/canonical/pebble/internals/overlord/restart" "github.com/canonical/pebble/internals/overlord/standby" "github.com/canonical/pebble/internals/overlord/state" - "github.com/canonical/pebble/internals/reaper" "github.com/canonical/pebble/internals/systemd" "github.com/canonical/pebble/internals/testutil" ) @@ -60,8 +59,6 @@ type daemonSuite struct { var _ = Suite(&daemonSuite{}) func (s *daemonSuite) SetUpTest(c *C) { - err := reaper.Start() - c.Assert(err, IsNil) s.pebbleDir = c.MkDir() s.statePath = filepath.Join(s.pebbleDir, ".pebble.state") systemdSdNotify = func(notif string) error { @@ -75,8 +72,6 @@ func (s *daemonSuite) TearDownTest(c *C) { s.notified = nil s.authorized = false s.err = nil - err := reaper.Stop() - c.Assert(err, IsNil) } func (s *daemonSuite) newDaemon(c *C) *Daemon { @@ -804,7 +799,7 @@ func (s *daemonSuite) TestRestartShutdownWithSigtermInBetween(c *C) { }() rebootNoticeWait = 150 * time.Millisecond - cmd := testutil.FakeCommand(c, "shutdown", "", true) + cmd := testutil.FakeCommand(c, "shutdown", "", false) defer cmd.Restore() d := s.newDaemon(c) @@ -836,7 +831,7 @@ func (s *daemonSuite) TestRestartShutdown(c *C) { rebootWaitTimeout = 100 * time.Millisecond rebootNoticeWait = 150 * time.Millisecond - cmd := testutil.FakeCommand(c, "shutdown", "", true) + cmd := testutil.FakeCommand(c, "shutdown", "", false) defer cmd.Restore() d := s.newDaemon(c)