aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRobinFrcd <29704178+RobinFrcd@users.noreply.github.com>2020-08-08 00:52:47 +0200
committerGitHub <noreply@github.com>2020-08-08 01:52:47 +0300
commit3a0362a6028b949016cd2a67bbeeab9b8d8bf50c (patch)
tree28be91f83e270b4ff461c39cef3047e68cd778bc /tests
parentdocs: add eugenetriguba as a contributor (#17) (diff)
downloadtaskipy2-3a0362a6028b949016cd2a67bbeeab9b8d8bf50c.zip
Propagate SIGTERM to child processes (#19)
SIGTERM sent to taskipy are handed over to task subprocess
Diffstat (limited to 'tests')
-rw-r--r--tests/fixtures/project_with_tasks_that_handle_interrupts/loop_with_sigint_handler.py12
-rw-r--r--tests/fixtures/project_with_tasks_that_handle_sigterm/loop_with_sigterm_handler.py18
-rw-r--r--tests/fixtures/project_with_tasks_that_handle_sigterm/pyproject.toml6
-rw-r--r--tests/test_taskipy.py14
4 files changed, 49 insertions, 1 deletions
diff --git a/tests/fixtures/project_with_tasks_that_handle_interrupts/loop_with_sigint_handler.py b/tests/fixtures/project_with_tasks_that_handle_interrupts/loop_with_sigint_handler.py
index 80f7b23..50ed139 100644
--- a/tests/fixtures/project_with_tasks_that_handle_interrupts/loop_with_sigint_handler.py
+++ b/tests/fixtures/project_with_tasks_that_handle_interrupts/loop_with_sigint_handler.py
@@ -1,11 +1,21 @@
+import signal
+import sys
import time
+
def main():
try:
while True:
- time.sleep(.1)
+ time.sleep(0.1)
except KeyboardInterrupt:
print('failing gracefully...')
+
+def sigterm_handler(sig, frame):
+ print('Shutdown gracefully with sigterm...')
+ sys.exit(123)
+
+
if __name__ == '__main__':
+ signal.signal(signal.SIGTERM, sigterm_handler)
main()
diff --git a/tests/fixtures/project_with_tasks_that_handle_sigterm/loop_with_sigterm_handler.py b/tests/fixtures/project_with_tasks_that_handle_sigterm/loop_with_sigterm_handler.py
new file mode 100644
index 0000000..508c17f
--- /dev/null
+++ b/tests/fixtures/project_with_tasks_that_handle_sigterm/loop_with_sigterm_handler.py
@@ -0,0 +1,18 @@
+import signal
+import sys
+import time
+
+
+def main():
+ while True:
+ time.sleep(0.1)
+
+
+def sigterm_handler(sig, frame):
+ print('Shutdown gracefully with sigterm...')
+ sys.exit(123)
+
+
+if __name__ == '__main__':
+ signal.signal(signal.SIGTERM, sigterm_handler)
+ main()
diff --git a/tests/fixtures/project_with_tasks_that_handle_sigterm/pyproject.toml b/tests/fixtures/project_with_tasks_that_handle_sigterm/pyproject.toml
new file mode 100644
index 0000000..1790d9b
--- /dev/null
+++ b/tests/fixtures/project_with_tasks_that_handle_sigterm/pyproject.toml
@@ -0,0 +1,6 @@
+[tool.poetry]
+name = "taskipy"
+description = "tasks runner for python projects"
+
+[tool.taskipy.tasks]
+run_loop_with_sigterm_handling = "python3 loop_with_sigterm_handler.py"
diff --git a/tests/test_taskipy.py b/tests/test_taskipy.py
index 5733006..37b322d 100644
--- a/tests/test_taskipy.py
+++ b/tests/test_taskipy.py
@@ -247,6 +247,20 @@ class InterruptingTaskTestCase(TaskipyTestCase):
self.assertEqual(exit_code, 130)
+ def test_sigterm_should_be_sent_to_subprocess(self):
+ cwd = self.create_test_dir_from_fixture('project_with_tasks_that_handle_sigterm')
+ process = self.start_taskipy_process('run_loop_with_sigterm_handling', cwd=cwd)
+
+ time.sleep(.2)
+
+ process.send_signal(signal.SIGTERM)
+
+ exit_code = process.wait()
+ stdout, _ = process.communicate()
+
+ self.assertEqual(exit_code, 123)
+ self.assertSubstr('sigterm', str(stdout))
+
class CustomRunnerTestCase(TaskipyTestCase):
def test_running_command_with_custom_runner(self):