Skip to content

Commit fc1065b

Browse files
authored
Merge pull request #471 from minrk/test-timeout
use signal.alarm for test timeout
2 parents 382e943 + 8dca90f commit fc1065b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

ipyparallel/tests/clienttest.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import print_function
33

44
import os
5-
import sys
5+
import signal
66
import time
77

88
import pytest
@@ -156,8 +156,20 @@ def _wait_for(self, f, timeout=10):
156156
if not f():
157157
print("Warning: Awaited condition never arrived")
158158

159+
test_timeout = 30
160+
159161
def setUp(self):
160162
BaseZMQTestCase.setUp(self)
163+
if hasattr(signal, 'SIGALRM'):
164+
# use sigalarm for test timeout
165+
def _sigalarm(sig, frame):
166+
raise TimeoutError(
167+
f"test did not finish in {self.test_timeout} seconds"
168+
)
169+
170+
signal.signal(signal.SIGALRM, _sigalarm)
171+
signal.alarm(self.test_timeout)
172+
161173
add_engines(self.engine_count, total=True)
162174

163175
self.client = self.connect_client()
@@ -176,10 +188,8 @@ def tearDown(self):
176188

177189
# allow flushing of incoming messages to prevent crash on socket close
178190
self.client.wait(timeout=2)
179-
# time.sleep(2)
180191
self.client.close()
181192
BaseZMQTestCase.tearDown(self)
182-
# this will be redundant when pyzmq merges PR #88
183-
# self.context.term()
184-
# print tempfile.TemporaryFile().fileno(),
185-
# sys.stdout.flush()
193+
if hasattr(signal, 'SIGALRM'):
194+
signal.alarm(0)
195+
signal.signal(signal.SIGALRM, signal.SIG_DFL)

0 commit comments

Comments
 (0)