forked from M-Labs/artiq
test_worker: fix asyncio event loop management
This commit is contained in:
parent
a96bbd8508
commit
c8ab6c1b2b
|
@ -62,44 +62,42 @@ async def _call_worker(worker, expid):
|
||||||
await worker.close()
|
await worker.close()
|
||||||
|
|
||||||
|
|
||||||
def _run_experiment(class_name):
|
class WorkerCase(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.loop = asyncio.new_event_loop()
|
||||||
|
asyncio.set_event_loop(self.loop)
|
||||||
|
|
||||||
|
def _run_experiment(self, class_name):
|
||||||
expid = {
|
expid = {
|
||||||
"log_level": logging.WARNING,
|
"log_level": logging.WARNING,
|
||||||
"file": sys.modules[__name__].__file__,
|
"file": sys.modules[__name__].__file__,
|
||||||
"class_name": class_name,
|
"class_name": class_name,
|
||||||
"arguments": dict()
|
"arguments": dict()
|
||||||
}
|
}
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
worker = Worker({})
|
worker = Worker({})
|
||||||
loop.run_until_complete(_call_worker(worker, expid))
|
self.loop.run_until_complete(_call_worker(worker, expid))
|
||||||
|
|
||||||
|
|
||||||
class WorkerCase(unittest.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.loop = asyncio.new_event_loop()
|
|
||||||
asyncio.set_event_loop(self.loop)
|
|
||||||
|
|
||||||
def test_simple_run(self):
|
def test_simple_run(self):
|
||||||
_run_experiment("SimpleExperiment")
|
self._run_experiment("SimpleExperiment")
|
||||||
|
|
||||||
def test_exception(self):
|
def test_exception(self):
|
||||||
with self.assertLogs() as logs:
|
with self.assertLogs() as logs:
|
||||||
with self.assertRaises(WorkerInternalException):
|
with self.assertRaises(WorkerInternalException):
|
||||||
_run_experiment("ExceptionTermination")
|
self._run_experiment("ExceptionTermination")
|
||||||
self.assertGreater(len(logs.records), 0)
|
self.assertGreater(len(logs.records), 0)
|
||||||
self.assertIn("Terminating with exception (TypeError)",
|
self.assertIn("Terminating with exception (TypeError)",
|
||||||
logs.output[-1])
|
logs.output[-1])
|
||||||
|
|
||||||
def test_watchdog_no_timeout(self):
|
def test_watchdog_no_timeout(self):
|
||||||
_run_experiment("WatchdogNoTimeout")
|
self._run_experiment("WatchdogNoTimeout")
|
||||||
|
|
||||||
def test_watchdog_timeout(self):
|
def test_watchdog_timeout(self):
|
||||||
with self.assertRaises(WorkerWatchdogTimeout):
|
with self.assertRaises(WorkerWatchdogTimeout):
|
||||||
_run_experiment("WatchdogTimeout")
|
self._run_experiment("WatchdogTimeout")
|
||||||
|
|
||||||
def test_watchdog_timeout_in_build(self):
|
def test_watchdog_timeout_in_build(self):
|
||||||
with self.assertRaises(WorkerWatchdogTimeout):
|
with self.assertRaises(WorkerWatchdogTimeout):
|
||||||
_run_experiment("WatchdogTimeoutInBuild")
|
self._run_experiment("WatchdogTimeoutInBuild")
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.loop.close()
|
self.loop.close()
|
||||||
|
|
Loading…
Reference in New Issue