Add tests for successful and fatal exit codes
This commit is contained in:
parent
711db92b8e
commit
895e159502
5 changed files with 46 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
||||||
web: python -m http.server $PORT
|
web: python -m http.server $PORT
|
||||||
bg: python src/dummy_program.py
|
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
11
example/src/die_soon.py
Executable 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
11
example/src/exit_soon.py
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
print("Started") # noqa: T001
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
print("Ended") # noqa: T001
|
||||||
|
|
||||||
|
exit(1)
|
|
@ -15,7 +15,7 @@ class ProjectTestCase(BaseTestCase):
|
||||||
Project("/nonexistent")
|
Project("/nonexistent")
|
||||||
|
|
||||||
def test_read_processes(self):
|
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]
|
web_process = self.project.processes[0]
|
||||||
self.assertEqual(web_process.name, "web")
|
self.assertEqual(web_process.name, "web")
|
||||||
self.assertEqual(web_process.command, "python -m http.server $PORT")
|
self.assertEqual(web_process.command, "python -m http.server $PORT")
|
||||||
|
@ -27,10 +27,15 @@ class ProjectTestCase(BaseTestCase):
|
||||||
self.assertEqual(bg_process.project, self.project)
|
self.assertEqual(bg_process.project, self.project)
|
||||||
|
|
||||||
bg_process = self.project.processes[2]
|
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.command, "python src/die_soon.py")
|
||||||
self.assertEqual(bg_process.project, self.project)
|
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):
|
def test_get_process(self):
|
||||||
self.assertEqual(self.project.get_process("web").name, "web")
|
self.assertEqual(self.project.get_process("web").name, "web")
|
||||||
self.assertEqual(self.project.get_process("bg").name, "bg")
|
self.assertEqual(self.project.get_process("bg").name, "bg")
|
||||||
|
|
|
@ -69,14 +69,26 @@ class ProcessWorkerTestCase(BaseWorkerTestCase):
|
||||||
self.assertFalse(is_process_running(initial_pid))
|
self.assertFalse(is_process_running(initial_pid))
|
||||||
self.assertTrue(is_process_running(new_process.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(
|
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"]
|
initial_pid = response["pid"]
|
||||||
wait_for_process_terminate(initial_pid)
|
wait_for_process_terminate(initial_pid)
|
||||||
time.sleep(2)
|
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.assertNotEqual(new_process.pid, initial_pid)
|
||||||
self.assertFalse(is_process_running(initial_pid))
|
self.assertFalse(is_process_running(initial_pid))
|
||||||
self.assertTrue(is_process_running(new_process.pid))
|
self.assertTrue(is_process_running(new_process.pid))
|
||||||
|
|
Reference in a new issue