Browse Source

start work on timeout, make sure board is locked/reserved during activate/deactivate

main
John-Mark Gurney 4 years ago
parent
commit
b68a5daa51
1 changed files with 20 additions and 2 deletions
  1. +20
    -2
      bitelab/__init__.py

+ 20
- 2
bitelab/__init__.py View File

@@ -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 ])

Loading…
Cancel
Save