Skip to content

Commit 21d88d8

Browse files
committedJun 3, 2015
tests: use a different event loop for each test
1 parent e5f16b2 commit 21d88d8

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed
 

Diff for: ‎artiq/test/pc_rpc.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ def _asyncio_echo(self):
7373
remote.close_rpc()
7474

7575
def _loop_asyncio_echo(self):
76-
loop = asyncio.get_event_loop()
76+
loop = asyncio.new_event_loop()
Has a conversation. Original line has a conversation.
77+
asyncio.set_event_loop(loop)
7778
loop.run_until_complete(self._asyncio_echo())
79+
loop.close()
7880

7981
def test_asyncio_echo(self):
8082
self._run_server_and_test(self._loop_asyncio_echo)
@@ -96,7 +98,8 @@ def echo(self, x):
9698

9799

98100
def run_server():
99-
loop = asyncio.get_event_loop()
101+
loop = asyncio.new_event_loop()
102+
asyncio.set_event_loop(loop)
100103
try:
101104
echo = Echo()
102105
server = pc_rpc.Server({"test": echo})

Diff for: ‎artiq/test/scheduler.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ def _get_basic_steps(rid, expid, priority=0, flush=False):
5555

5656

5757
class SchedulerCase(unittest.TestCase):
58+
def setUp(self):
59+
self.loop = asyncio.new_event_loop()
60+
asyncio.set_event_loop(self.loop)
61+
5862
def test_steps(self):
63+
loop = self.loop
5964
scheduler = Scheduler(0, _handlers)
6065
expid = _get_expid("EmptyExperiment")
6166

@@ -70,7 +75,6 @@ def notify(notifier, mod):
7075
done.set()
7176
scheduler.notifier.publish = notify
7277

73-
loop = asyncio.get_event_loop()
7478
scheduler.start()
7579

7680
# Verify that a timed experiment far in the future does not
@@ -91,6 +95,7 @@ def notify(notifier, mod):
9195
loop.run_until_complete(scheduler.stop())
9296

9397
def test_pause(self):
98+
loop = self.loop
9499
scheduler = Scheduler(0, _handlers)
95100
expid_bg = _get_expid("BackgroundExperiment")
96101
expid = _get_expid("EmptyExperiment")
@@ -113,7 +118,6 @@ def notify(notifier, mod):
113118
done.set()
114119
scheduler.notifier.publish = notify
115120

116-
loop = asyncio.get_event_loop()
117121
scheduler.start()
118122
scheduler.submit("main", expid_bg, -99, None, False)
119123
loop.run_until_complete(background_running.wait())
@@ -122,6 +126,7 @@ def notify(notifier, mod):
122126
loop.run_until_complete(scheduler.stop())
123127

124128
def test_flush(self):
129+
loop = self.loop
125130
scheduler = Scheduler(0, _handlers)
126131
expid = _get_expid("EmptyExperiment")
127132

@@ -147,10 +152,12 @@ def notify(notifier, mod):
147152
done.set()
148153
scheduler.notifier.publish = notify
149154

150-
loop = asyncio.get_event_loop()
151155
scheduler.start()
152156
scheduler.submit("main", expid, 0, None, False)
153157
loop.run_until_complete(first_preparing.wait())
154158
scheduler.submit("main", expid, 1, None, True)
155159
loop.run_until_complete(done.wait())
156160
loop.run_until_complete(scheduler.stop())
161+
162+
def tearDown(self):
163+
self.loop.close()

Diff for: ‎artiq/test/sync_struct.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ def do_recv(self):
3535
or "Finished" not in self.test_dict.keys():
3636
yield from asyncio.sleep(0.5)
3737

38+
def setUp(self):
39+
self.loop = asyncio.new_event_loop()
40+
asyncio.set_event_loop(self.loop)
41+
3842
def test_recv(self):
39-
self.loop = loop = asyncio.new_event_loop()
40-
asyncio.set_event_loop(loop)
43+
loop = self.loop
4144
publisher = asyncio.Future()
4245
test_dict = asyncio.Future()
4346
asyncio.async(start_server(publisher, test_dict))
@@ -55,8 +58,8 @@ def test_recv(self):
5558
test_port))
5659
loop.run_until_complete(self.do_recv())
5760
self.assertEqual(self.test_dict, test_vector)
58-
59-
def tearDown(self):
6061
self.loop.run_until_complete(self.subscriber.close())
6162
self.loop.run_until_complete(self.publisher.stop())
63+
64+
def tearDown(self):
6265
self.loop.close()

Diff for: ‎artiq/test/worker.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def _call_worker(worker, expid):
4040

4141

4242
def _run_experiment(experiment):
43+
loop = asyncio.new_event_loop()
44+
asyncio.set_event_loop(loop)
Has a conversation. Original line has a conversation.
4345
expid = {
4446
"file": sys.modules[__name__].__file__,
4547
"experiment": experiment,
@@ -50,8 +52,8 @@ def _run_experiment(experiment):
5052
}
5153

5254
worker = Worker(handlers)
53-
loop = asyncio.get_event_loop()
5455
loop.run_until_complete(_call_worker(worker, expid))
56+
loop.close()
5557

5658

5759
class WatchdogCase(unittest.TestCase):

0 commit comments

Comments
 (0)
Please sign in to comment.