Revision 560cbec1 test/ganeti.utils_unittest.py
b/test/ganeti.utils_unittest.py | ||
---|---|---|
2393 | 2393 |
self.assertEqual(utils.FormatSeconds(3912.8), "1h 5m 13s") |
2394 | 2394 |
|
2395 | 2395 |
|
2396 |
class RunIgnoreProcessNotFound(unittest.TestCase): |
|
2397 |
@staticmethod |
|
2398 |
def _WritePid(fd): |
|
2399 |
os.write(fd, str(os.getpid())) |
|
2400 |
os.close(fd) |
|
2401 |
return True |
|
2402 |
|
|
2403 |
def test(self): |
|
2404 |
(pid_read_fd, pid_write_fd) = os.pipe() |
|
2405 |
|
|
2406 |
# Start short-lived process which writes its PID to pipe |
|
2407 |
self.assert_(utils.RunInSeparateProcess(self._WritePid, pid_write_fd)) |
|
2408 |
os.close(pid_write_fd) |
|
2409 |
|
|
2410 |
# Read PID from pipe |
|
2411 |
pid = int(os.read(pid_read_fd, 1024)) |
|
2412 |
os.close(pid_read_fd) |
|
2413 |
|
|
2414 |
# Try to send signal to process which exited recently |
|
2415 |
self.assertFalse(utils.IgnoreProcessNotFound(os.kill, pid, 0)) |
|
2416 |
|
|
2417 |
|
|
2396 | 2418 |
if __name__ == '__main__': |
2397 | 2419 |
testutils.GanetiTestProgram() |
Also available in: Unified diff