Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
DE0CH committed Dec 19, 2022
1 parent fbb766a commit 4f98bd6
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ def target_runner(experiment, scenario):

killed = False


def test_no_hang():
p = Process(target=start_irace)
q = Queue()
p = Process(target=start_irace, args=(q,))
p.start()
Timer(1, sigterm_process, args=(p,)).start()
Timer(2, sigkill_process, args=(p,)).start()
sleep(3)
Timer(0.1, sigterm_process, args=(p,)).start()
Timer(0.2, sigkill_process, args=(p,)).start()
sleep(0.3)
assert not killed

def sigterm_process(p):
Expand All @@ -47,7 +49,22 @@ def sigkill_process(p):
global killed
killed = True

def start_irace():
def start_irace(q):
tuner = irace(scenario, params, target_runner)
tuner.set_initial(defaults)
best_conf = tuner.run()
try:
best_conf = tuner.run()
except:
q.put(0)

def test_correct_exit():
q = Queue()
p = Process(target=start_irace, args=(q,))
p.start()
Timer(0.1, sigterm_process, args=(p,)).start()
Timer(0.2, sigkill_process, args=(p,)).start()
sleep(0.3)
assert not q.empty()

if __name__ == '__main__':
test_correct_exit()

0 comments on commit 4f98bd6

Please sign in to comment.