Skip to content

Commit

Permalink
Handle interrupted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oysols committed Feb 19, 2021
1 parent d436c8a commit 0de7cff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions minimalci/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import functools
import time
from signal import SIGKILL, SIGTERM
import signal


SENSORED = "********"
Expand All @@ -26,6 +27,11 @@ def global_kill_signal_handler(signum: int, frame: FrameType) -> None:
global_kill_signal.set()


def set_sigterm_sigint_global_kill_signal_handler() -> None:
signal.signal(signal.SIGTERM, global_kill_signal_handler)
signal.signal(signal.SIGINT, global_kill_signal_handler)


class ProcessError(Exception):
def __init__(self, message: str, stdout: Optional[bytes] = None, stderr: Optional[bytes] = None, exit_code: Optional[int] = None):
self.stdout = stdout
Expand Down
8 changes: 3 additions & 5 deletions minimalci/taskrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import sys
import traceback
import argparse
import signal

from .executors import global_kill_signal_handler
from .executors import set_sigterm_sigint_global_kill_signal_handler
from .tasks import Task, State


Expand Down Expand Up @@ -118,8 +117,7 @@ def run(self) -> None:
state.logdir = Path(args.logdir)
state.identifier = args.identifier

# Kill executor processes and cleanly exit on SIGTERM
signal.signal(signal.SIGTERM, global_kill_signal_handler)
signal.signal(signal.SIGINT, global_kill_signal_handler)
# Kill executor processes and cleanly exit on SIGTERM/SIGINT
set_sigterm_sigint_global_kill_signal_handler()

run_all_tasks_in_file(args.file, state)
4 changes: 3 additions & 1 deletion tests/test_executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import subprocess
import time
import sys
import signal

sys.path.append(".")
from minimalci.executors import Local, LocalContainer, global_kill_signal, ProcessError, Stash
from minimalci.executors import Local, LocalContainer, global_kill_signal, ProcessError, Stash, set_sigterm_sigint_global_kill_signal_handler


def test_stash() -> None:
Expand Down Expand Up @@ -68,6 +69,7 @@ def run_catch(exe: LocalContainer, catch_signal_stash: Stash) -> None:


if __name__ == "__main__":
set_sigterm_sigint_global_kill_signal_handler()
test_docker_exec_signal_handling()
test_stash()
test_temp_path()
Expand Down

0 comments on commit 0de7cff

Please sign in to comment.