Example #1
0
 def test_sighup_supervisord_nop_if_not_running(self):
     pid = random.randint(2, 99)
     snap = self.make_dir()
     self.patch(os, "environ", {"SNAP": snap})
     self.patch(snappy, "get_supervisord_pid").return_value = pid
     mock_kill = self.patch(os, "kill")
     mock_kill.side_effect = ProcessLookupError()
     # the command doesn't fail
     snappy.sighup_supervisord()
     mock_kill.assert_called_once_with(pid, signal.SIGHUP)
Example #2
0
 def test_sighup_supervisord_waits_until_no_error(self):
     pid = random.randint(2, 99)
     snap = self.make_dir()
     self.patch(os, "environ", {"SNAP": snap})
     self.patch(snappy, "get_supervisord_pid").return_value = pid
     mock_kill = self.patch(os, "kill")
     self.patch(time, "sleep")  # Speed up the test.
     mock_process = MagicMock()
     mock_process.stdout.read.side_effect = [b"error:", b""]
     mock_popen = self.patch(subprocess, "Popen")
     mock_popen.return_value = mock_process
     snappy.sighup_supervisord()
     self.assertThat(mock_kill, MockCalledOnceWith(pid, signal.SIGHUP))
     self.assertEqual(2, mock_popen.call_count)
Example #3
0
 def test_sighup_supervisord_sends_SIGHUP(self):
     pid = random.randint(2, 99)
     snap = self.make_dir()
     self.patch(os, "environ", {"SNAP": snap})
     self.patch(snappy, "get_supervisord_pid").return_value = pid
     mock_kill = self.patch(os, "kill")
     self.patch(time, "sleep")  # Speed up the test.
     mock_process = MagicMock()
     mock_popen = self.patch(subprocess, "Popen")
     mock_popen.return_value = mock_process
     snappy.sighup_supervisord()
     mock_kill.assert_called_once_with(pid, signal.SIGHUP)
     mock_popen.assert_called_once_with(
         [os.path.join(snap, "bin", "run-supervisorctl"), "status"],
         stdout=subprocess.PIPE,
     )
     mock_process.wait.assert_called_once_with()
Example #4
0
 def test_sighup_supervisord_sends_SIGHUP(self):
     pid = random.randint(2, 99)
     snap = self.make_dir()
     self.patch(os, 'environ', {
         'SNAP': snap,
     })
     self.patch(snappy, 'get_supervisord_pid').return_value = pid
     mock_kill = self.patch(os, 'kill')
     self.patch(time, 'sleep')  # Speed up the test.
     mock_process = MagicMock()
     mock_popen = self.patch(subprocess, 'Popen')
     mock_popen.return_value = mock_process
     snappy.sighup_supervisord()
     self.assertThat(mock_kill, MockCalledOnceWith(pid, signal.SIGHUP))
     self.assertThat(mock_popen, MockCalledOnceWith([
         os.path.join(snap, 'bin', 'run-supervisorctl'), 'status'
     ], stdout=subprocess.PIPE))
     self.assertThat(mock_process.wait, MockCalledOnceWith())
Example #5
0
 def test_sighup_supervisord_waits_until_no_error(self):
     pid = random.randint(2, 99)
     snap = self.make_dir()
     self.patch(os, 'environ', {
         'SNAP': snap,
     })
     self.patch(snappy, 'get_supervisord_pid').return_value = pid
     mock_kill = self.patch(os, 'kill')
     self.patch(time, 'sleep')  # Speed up the test.
     mock_process = MagicMock()
     mock_process.stdout.read.side_effect = [
         b'error:',
         b'',
     ]
     mock_popen = self.patch(subprocess, 'Popen')
     mock_popen.return_value = mock_process
     snappy.sighup_supervisord()
     self.assertThat(mock_kill, MockCalledOnceWith(pid, signal.SIGHUP))
     self.assertEquals(2, mock_popen.call_count)