diff --git a/bitelab/__init__.py b/bitelab/__init__.py index f96fa83..f1369dd 100644 --- a/bitelab/__init__.py +++ b/bitelab/__init__.py @@ -103,6 +103,9 @@ async def log_event(tag, board=None, user=None, extra={}): logging.info(json.dumps(info)) +class TimeOut(DefROAttribute): + defattername = 'timeout' + class EtherIface(DefROAttribute): defattrname = 'eiface' @@ -172,10 +175,14 @@ class BoardImpl: self.attrcache[i] = await self.attrmap[i].getvalue() async def activate(self): + assert self.lock.locked() and self.reserved + for i in self.options: await i.activate(self) async def deactivate(self): + assert self.lock.locked() and self.reserved + for i in self.options: await i.deactivate(self) @@ -1228,7 +1235,9 @@ class TestBoardImpl(unittest.IsolatedAsyncioTestCase): opt = create_autospec(Attribute) brd = BoardImpl('foo', 'bar', [ opt ]) - await brd.activate() + async with brd.lock: + await brd.reserve() + await brd.activate() opt.activate.assert_called_with(brd) @@ -1237,7 +1246,9 @@ class TestBoardImpl(unittest.IsolatedAsyncioTestCase): opt = create_autospec(Attribute) brd = BoardImpl('foo', 'bar', [ opt ]) - await brd.deactivate() + async with brd.lock: + await brd.reserve() + await brd.deactivate() opt.deactivate.assert_called_with(brd) @@ -1348,3 +1359,10 @@ class TestAttrs(unittest.IsolatedAsyncioTestCase): wrap_subprocess_exec(cse, retcode=1) with self.assertRaises(RuntimeError): await ei.activate(brd) + + async def test_timeout(self): + # that a TimeOut can be created + to = TimeOut(.1) + + # that a board w/ the to + brd = BoardImpl('foo', 'bar', [ to ])