2015-03-12 01:26:04 +08:00
|
|
|
import unittest
|
|
|
|
import asyncio
|
|
|
|
import sys
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
from artiq import *
|
2015-03-12 02:07:04 +08:00
|
|
|
from artiq.master.worker import *
|
2015-03-12 01:26:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
class WatchdogNoTimeout(Experiment, AutoDB):
|
|
|
|
def run(self):
|
|
|
|
for i in range(10):
|
2015-04-28 23:23:59 +08:00
|
|
|
with watchdog(0.5*s):
|
2015-03-12 01:26:04 +08:00
|
|
|
sleep(0.1)
|
|
|
|
|
|
|
|
|
|
|
|
class WatchdogTimeout(Experiment, AutoDB):
|
|
|
|
def run(self):
|
2015-04-28 23:23:59 +08:00
|
|
|
with watchdog(0.1*s):
|
2015-03-12 01:26:04 +08:00
|
|
|
sleep(100.0)
|
|
|
|
|
|
|
|
|
2015-03-12 02:07:04 +08:00
|
|
|
class WatchdogTimeoutInBuild(Experiment, AutoDB):
|
|
|
|
def build(self):
|
2015-04-28 23:23:59 +08:00
|
|
|
with watchdog(0.1*s):
|
2015-03-12 02:07:04 +08:00
|
|
|
sleep(100.0)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2015-03-12 01:26:04 +08:00
|
|
|
@asyncio.coroutine
|
2015-05-21 16:41:45 +08:00
|
|
|
def _call_worker(worker, expid):
|
2015-03-12 01:26:04 +08:00
|
|
|
try:
|
2015-06-04 11:22:03 +08:00
|
|
|
yield from worker.prepare(0, "main", expid, 0)
|
2015-03-12 01:26:04 +08:00
|
|
|
yield from worker.run()
|
|
|
|
yield from worker.analyze()
|
|
|
|
finally:
|
|
|
|
yield from worker.close()
|
|
|
|
|
|
|
|
|
|
|
|
def _run_experiment(experiment):
|
2015-06-04 19:44:07 +08:00
|
|
|
expid = {
|
|
|
|
"file": sys.modules[__name__].__file__,
|
|
|
|
"experiment": experiment,
|
|
|
|
"arguments": dict()
|
|
|
|
}
|
|
|
|
handlers = {
|
|
|
|
"init_rt_results": lambda description: None
|
|
|
|
}
|
|
|
|
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
worker = Worker(handlers)
|
|
|
|
loop.run_until_complete(_call_worker(worker, expid))
|
2015-03-12 01:26:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
class WatchdogCase(unittest.TestCase):
|
2015-06-04 19:40:13 +08:00
|
|
|
def setUp(self):
|
|
|
|
self.loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(self.loop)
|
|
|
|
|
2015-03-12 01:26:04 +08:00
|
|
|
def test_watchdog_no_timeout(self):
|
2015-06-04 11:22:03 +08:00
|
|
|
_run_experiment("WatchdogNoTimeout")
|
2015-03-12 01:26:04 +08:00
|
|
|
|
|
|
|
def test_watchdog_timeout(self):
|
|
|
|
with self.assertRaises(WorkerWatchdogTimeout):
|
|
|
|
_run_experiment("WatchdogTimeout")
|
2015-03-12 02:07:04 +08:00
|
|
|
|
|
|
|
def test_watchdog_timeout_in_build(self):
|
|
|
|
with self.assertRaises(WorkerWatchdogTimeout):
|
|
|
|
_run_experiment("WatchdogTimeoutInBuild")
|
2015-06-04 19:40:13 +08:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.loop.close()
|