def test_status(self): # Make sure we can poll a fake pidfile for the unittest process with NamedTemporaryFile() as tf: writefile(tf.name, str(os.getpid())) self.assertTrue(daemon.status(tf.name, self.logger)) # This should fail since the pidfile is deleted self.assertFalse(daemon.status(tf.name, self.logger)) # We should get an EPERM trying to poll pid with NamedTemporaryFile() as tf: writefile(tf.name, '1') self.assertFalse(daemon.status(tf.name, self.logger))
def test_kill(self): child_pid = os.fork() if child_pid == 0: # Child - Sleep for 100 seconds. We'll be killed anyway, but in # the event that this test fails, we don't want to leave the # orphaned process around forever. time.sleep(100) self.fail() with NamedTemporaryFile() as tf: writefile(tf.name, str(child_pid)) self.assertTrue(daemon.kill(tf.name, self.logger)) # This should return true because there is no file and therefore # the service is already dead self.assertTrue(daemon.kill(tf.name, self.logger))
def test_read_pid(self): with NamedTemporaryFile() as tf: writefile(tf.name, '1234') self.assertEquals(daemon.read_pid(tf.name, self.logger), 1234) self.assertIsNone(daemon.read_pid(tf.name, self.logger))
def test_read_pid(self): with NamedTemporaryFile() as tf: writefile(tf.name, '1234') self.assertEqual(daemon.read_pid(tf.name, self.logger), 1234) self.assertIsNone(daemon.read_pid(tf.name, self.logger))