archive
/
catfish
Archived
1
Fork 0

Add tests for successful and fatal exit codes

This commit is contained in:
Jake Howard 2018-12-19 17:26:09 +00:00
parent 711db92b8e
commit 895e159502
Signed by: jake
GPG Key ID: 57AFB45680EDD477
5 changed files with 46 additions and 6 deletions

View File

@ -1,3 +1,4 @@
web: python -m http.server $PORT
bg: python src/dummy_program.py
temp: python src/die_soon.py
die: python src/die_soon.py
exit: python src/exit_soon.py

11
example/src/die_soon.py Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env python3
import time
print("Started") # noqa: T001
time.sleep(1)
print("Ended") # noqa: T001
exit(1)

11
example/src/exit_soon.py Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env python3
import time
print("Started") # noqa: T001
time.sleep(1)
print("Ended") # noqa: T001
exit(1)

View File

@ -15,7 +15,7 @@ class ProjectTestCase(BaseTestCase):
Project("/nonexistent")
def test_read_processes(self):
self.assertEqual(len(self.project.processes), 3)
self.assertEqual(len(self.project.processes), 4)
web_process = self.project.processes[0]
self.assertEqual(web_process.name, "web")
self.assertEqual(web_process.command, "python -m http.server $PORT")
@ -27,10 +27,15 @@ class ProjectTestCase(BaseTestCase):
self.assertEqual(bg_process.project, self.project)
bg_process = self.project.processes[2]
self.assertEqual(bg_process.name, "temp")
self.assertEqual(bg_process.name, "die")
self.assertEqual(bg_process.command, "python src/die_soon.py")
self.assertEqual(bg_process.project, self.project)
bg_process = self.project.processes[3]
self.assertEqual(bg_process.name, "exit")
self.assertEqual(bg_process.command, "python src/exit_soon.py")
self.assertEqual(bg_process.project, self.project)
def test_get_process(self):
self.assertEqual(self.project.get_process("web").name, "web")
self.assertEqual(self.project.get_process("bg").name, "bg")

View File

@ -69,14 +69,26 @@ class ProcessWorkerTestCase(BaseWorkerTestCase):
self.assertFalse(is_process_running(initial_pid))
self.assertTrue(is_process_running(new_process.pid))
def test_process_restart_on_0_exit(self):
def test_process_restart_on_1_exit(self):
response = send_to_server(
PayloadType.PROCESS, {"path": str(self.project.root), "process": "temp"}
PayloadType.PROCESS, {"path": str(self.project.root), "process": "die"}
)
initial_pid = response["pid"]
wait_for_process_terminate(initial_pid)
time.sleep(2)
new_process = find_running_process_for(self.project.get_process("temp"))
new_process = find_running_process_for(self.project.get_process("die"))
self.assertNotEqual(new_process.pid, initial_pid)
self.assertFalse(is_process_running(initial_pid))
self.assertTrue(is_process_running(new_process.pid))
def test_process_restart_on_0_exit(self):
response = send_to_server(
PayloadType.PROCESS, {"path": str(self.project.root), "process": "exit"}
)
initial_pid = response["pid"]
wait_for_process_terminate(initial_pid)
time.sleep(2)
new_process = find_running_process_for(self.project.get_process("exit"))
self.assertNotEqual(new_process.pid, initial_pid)
self.assertFalse(is_process_running(initial_pid))
self.assertTrue(is_process_running(new_process.pid))