Skip to content

Commit e2aaf25

Browse files
authored
test: keep the interrupt test's own Ctrl-C inside its try (#522)
The timer was started before the try, and its cancel and join ran in a finally, so a signal raised while the main thread waited in start() or in the cleanup left the test and stopped the whole pytest run (seen once on main, linux/amd64, Python 3.13, run 45959878115). Both loops (in process and in the child process) now catch it wherever it is raised from start() on. Closes #512
1 parent fba3d8e commit e2aaf25

1 file changed

Lines changed: 15 additions & 24 deletions

File tree

‎tests/test_python_function_interrupt.py‎

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,17 @@ def test_sigint_during_a_query_that_calls_python_is_a_keyboard_interrupt(
5757
interrupted = 0
5858
for delay in (0.05, 0.09, 0.13, 0.17, 0.21, 0.25, 0.29, 0.33):
5959
timer = threading.Timer(delay, os.kill, (os.getpid(), signal.SIGINT))
60-
timer.start()
60+
# everything from start() on is inside this try: an escaped signal would stop the whole test run (#512)
6161
try:
62-
db.query("sql", "SELECT sum(plus_one(n)) AS s FROM T").first()
63-
outcome = "completed"
62+
try:
63+
timer.start()
64+
db.query("sql", "SELECT sum(plus_one(n)) AS s FROM T").first()
65+
finally:
66+
timer.cancel()
67+
timer.join()
68+
time.sleep(0.05) # a signal sent just after the end is delivered here
6469
except KeyboardInterrupt:
65-
outcome = "interrupted"
6670
interrupted += 1
67-
finally:
68-
timer.cancel()
69-
timer.join()
70-
if outcome == "completed":
71-
try: # a signal sent just after the end is delivered here, still a KeyboardInterrupt
72-
time.sleep(0.05)
73-
except KeyboardInterrupt:
74-
interrupted += 1
7571
# the database works as before
7672
assert db.count_type("T") == 300_000
7773
assert interrupted >= 1
@@ -123,21 +119,16 @@ def test_a_statement_that_fails_otherwise_is_still_an_arcadedb_error(db):
123119
interrupted = 0
124120
for delay in (0.05, 0.15, 0.25, 0.35, 0.45, 0.55):
125121
timer = threading.Timer(delay, os.kill, (os.getpid(), signal.SIGINT))
126-
timer.start()
127122
try:
128-
db.query("sql", "SELECT sum(plus_one(n)) AS s FROM T").first()
129-
done = True
123+
try:
124+
timer.start()
125+
db.query("sql", "SELECT sum(plus_one(n)) AS s FROM T").first()
126+
finally:
127+
timer.cancel()
128+
timer.join()
129+
time.sleep(0.05)
130130
except KeyboardInterrupt:
131-
done = False
132131
interrupted += 1
133-
finally:
134-
timer.cancel()
135-
timer.join()
136-
if done:
137-
try:
138-
time.sleep(0.05)
139-
except KeyboardInterrupt:
140-
interrupted += 1
141132
assert db.count_type("T") == 150_000
142133
db.close()
143134
print("interrupted", interrupted)

0 commit comments

Comments
 (0)