forked from M-Labs/artiq
tests: use a different event loop for each test
This commit is contained in:
parent
e5f16b29fd
commit
21d88d8345
@ -73,8 +73,10 @@ class RPCCase(unittest.TestCase):
|
||||
remote.close_rpc()
|
||||
|
||||
def _loop_asyncio_echo(self):
|
||||
loop = asyncio.get_event_loop()
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
loop.run_until_complete(self._asyncio_echo())
|
||||
loop.close()
|
||||
|
||||
def test_asyncio_echo(self):
|
||||
self._run_server_and_test(self._loop_asyncio_echo)
|
||||
@ -96,7 +98,8 @@ class Echo:
|
||||
|
||||
|
||||
def run_server():
|
||||
loop = asyncio.get_event_loop()
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
try:
|
||||
echo = Echo()
|
||||
server = pc_rpc.Server({"test": echo})
|
||||
|
@ -55,7 +55,12 @@ _handlers = {
|
||||
|
||||
|
||||
class SchedulerCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(self.loop)
|
||||
|
||||
def test_steps(self):
|
||||
loop = self.loop
|
||||
scheduler = Scheduler(0, _handlers)
|
||||
expid = _get_expid("EmptyExperiment")
|
||||
|
||||
@ -70,7 +75,6 @@ class SchedulerCase(unittest.TestCase):
|
||||
done.set()
|
||||
scheduler.notifier.publish = notify
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
scheduler.start()
|
||||
|
||||
# Verify that a timed experiment far in the future does not
|
||||
@ -91,6 +95,7 @@ class SchedulerCase(unittest.TestCase):
|
||||
loop.run_until_complete(scheduler.stop())
|
||||
|
||||
def test_pause(self):
|
||||
loop = self.loop
|
||||
scheduler = Scheduler(0, _handlers)
|
||||
expid_bg = _get_expid("BackgroundExperiment")
|
||||
expid = _get_expid("EmptyExperiment")
|
||||
@ -113,7 +118,6 @@ class SchedulerCase(unittest.TestCase):
|
||||
done.set()
|
||||
scheduler.notifier.publish = notify
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
scheduler.start()
|
||||
scheduler.submit("main", expid_bg, -99, None, False)
|
||||
loop.run_until_complete(background_running.wait())
|
||||
@ -122,6 +126,7 @@ class SchedulerCase(unittest.TestCase):
|
||||
loop.run_until_complete(scheduler.stop())
|
||||
|
||||
def test_flush(self):
|
||||
loop = self.loop
|
||||
scheduler = Scheduler(0, _handlers)
|
||||
expid = _get_expid("EmptyExperiment")
|
||||
|
||||
@ -147,10 +152,12 @@ class SchedulerCase(unittest.TestCase):
|
||||
done.set()
|
||||
scheduler.notifier.publish = notify
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
scheduler.start()
|
||||
scheduler.submit("main", expid, 0, None, False)
|
||||
loop.run_until_complete(first_preparing.wait())
|
||||
scheduler.submit("main", expid, 1, None, True)
|
||||
loop.run_until_complete(done.wait())
|
||||
loop.run_until_complete(scheduler.stop())
|
||||
|
||||
def tearDown(self):
|
||||
self.loop.close()
|
||||
|
@ -35,9 +35,12 @@ class SyncStructCase(unittest.TestCase):
|
||||
or "Finished" not in self.test_dict.keys():
|
||||
yield from asyncio.sleep(0.5)
|
||||
|
||||
def setUp(self):
|
||||
self.loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(self.loop)
|
||||
|
||||
def test_recv(self):
|
||||
self.loop = loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
loop = self.loop
|
||||
publisher = asyncio.Future()
|
||||
test_dict = asyncio.Future()
|
||||
asyncio.async(start_server(publisher, test_dict))
|
||||
@ -55,8 +58,8 @@ class SyncStructCase(unittest.TestCase):
|
||||
test_port))
|
||||
loop.run_until_complete(self.do_recv())
|
||||
self.assertEqual(self.test_dict, test_vector)
|
||||
|
||||
def tearDown(self):
|
||||
self.loop.run_until_complete(self.subscriber.close())
|
||||
self.loop.run_until_complete(self.publisher.stop())
|
||||
|
||||
def tearDown(self):
|
||||
self.loop.close()
|
||||
|
@ -40,6 +40,8 @@ def _call_worker(worker, expid):
|
||||
|
||||
|
||||
def _run_experiment(experiment):
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
expid = {
|
||||
"file": sys.modules[__name__].__file__,
|
||||
"experiment": experiment,
|
||||
@ -50,8 +52,8 @@ def _run_experiment(experiment):
|
||||
}
|
||||
|
||||
worker = Worker(handlers)
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(_call_worker(worker, expid))
|
||||
loop.close()
|
||||
|
||||
|
||||
class WatchdogCase(unittest.TestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user