Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions dokimi/tests/test_repo_batch_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ def test_compare_with_a_model_refuses_only_a_mixed_row_of_that_model(setup):

_CTRL_C_DRIVER = """
import os, signal, sys, threading
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
sys.path.insert(0, sys.argv[1])
from repo_eval_fixture import FakeRunner, fake_harness, make_repo
Expand All @@ -272,11 +273,27 @@ def test_compare_with_a_model_refuses_only_a_mixed_row_of_that_model(setup):
container.DockerRunner = lambda *a, **k: fake
os.environ["FAKE_ACTION"] = "fix"
both, real = threading.Barrier(2), repo_runner.run_cell
cancelled, real_shutdown = threading.Event(), ThreadPoolExecutor.shutdown
def shutdown(self, wait=True, *, cancel_futures=False):
real_shutdown(self, wait=wait, cancel_futures=cancel_futures)
if cancel_futures:
cancelled.set()
ThreadPoolExecutor.shutdown = shutdown
submitted, real_map = threading.Event(), ThreadPoolExecutor.map
def pool_map(self, *args, **kwargs):
results = real_map(self, *args, **kwargs) # returns once every cell is submitted and its thread has started
submitted.set()
return results
ThreadPoolExecutor.map = pool_map
def run_cell(ctx, task, arm, rep, *args, **kwargs):
if rep <= 2:
both.wait(30)
if rep == 1:
if not submitted.wait(30): # an interrupt inside submit() is a slow thread start, not the Ctrl-C under test
os._exit(3)
signal.pthread_kill(threading.main_thread().ident, signal.SIGINT)
Comment thread
antonwolfy marked this conversation as resolved.
Resolved
if not cancelled.wait(30): # no worker is free to take a queued cell until the main thread has cancelled them
os._exit(4)
return real(ctx, task, arm, rep, *args, **kwargs)
repo_runner.run_cell = run_cell
signal.signal(signal.SIGINT, signal.default_int_handler)
Expand Down
Loading