Skip to content

Commit 8b228be

Browse files
committed
tests: query interrupt was both slow and possibly incorrect - added a timeout and use pytest.raises with a more interruptable query
1 parent a9b8ba2 commit 8b228be

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
import duckdb
22
import time
33
import pytest
4-
54
import platform
65
import threading
76
import _thread as thread
87

98

109
def send_keyboard_interrupt():
11-
# Wait a little, so we're sure the 'execute' has started
1210
time.sleep(0.1)
13-
# Send an interrupt to the main thread
1411
thread.interrupt_main()
1512

1613

1714
class TestQueryInterruption(object):
15+
1816
@pytest.mark.xfail(
1917
condition=platform.system() == "Emscripten",
2018
reason="Emscripten builds cannot use threads",
2119
)
22-
def test_query_interruption(self):
20+
@pytest.mark.timeout(15)
21+
def test_keyboard_interruption(self):
2322
con = duckdb.connect()
2423
thread = threading.Thread(target=send_keyboard_interrupt)
2524
# Start the thread
2625
thread.start()
2726
try:
28-
res = con.execute('select count(*) from range(100000000000)').fetchall()
29-
except RuntimeError:
30-
# If this is not reached, we could not cancel the query before it completed
31-
# indicating that the query interruption functionality is broken
32-
assert True
33-
except KeyboardInterrupt:
34-
pytest.fail()
35-
thread.join()
27+
with pytest.raises((KeyboardInterrupt, RuntimeError)):
28+
res = con.execute('select * from range(100000) t1,range(100000) t2').fetchall()
29+
finally:
30+
# Ensure the thread completes regardless of what happens
31+
thread.join()

0 commit comments

Comments
 (0)