Skip to content

Commit

Permalink
Fix similar race condition on childpart
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Nov 14, 2016
1 parent e15580c commit fe6566e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
12 changes: 7 additions & 5 deletions malcolm/parts/builtin/childpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ def store_params(self, params):

@ManagerController.Reset
def reset(self, task):
# Wait until we have finished resetting
state = self.child.state
if state == sm.RESETTING:
task.when_matches(self.child["state"], sm.READY)
elif state != sm.READY:
try:
task.post(self.child["reset"])
except ValueError:
# We get a "ValueError: child is not writeable" if we can't run
# reset, probably because the child is already resetting,
# so just wait for it to be idle
task.when_matches(
self.child["state"], sm.READY, bad_values=[sm.FAULT])

@ManagerController.ReportOutports
def pre_layout(self, _):
Expand Down
18 changes: 10 additions & 8 deletions tests/test_parts/test_builtin/test_childpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

# module imports
from malcolm.core.part import Part
from malcolm.parts.builtin.childpart import ChildPart, OutportInfo
from malcolm.parts.builtin.runnablechildpart import RunnableChildPart
from malcolm.parts.builtin.childpart import ChildPart
from malcolm.core.syncfactory import SyncFactory
from malcolm.core import Process, Table, Task
from malcolm.controllers.runnablecontroller import RunnableController
Expand All @@ -23,6 +22,7 @@

sm = RunnableController.stateMachine


class PortsPart(Part):
in_port = ''
out_port = ''
Expand Down Expand Up @@ -71,8 +71,7 @@ def makeChildBlock(self, blockMri):
return part, controller

def setUp(self):
self.s = SyncFactory('threading')
self.p = Process('process1', self.s)
self.p = Process('process1', SyncFactory('threading'))

self.p1, self.c1 = self.makeChildBlock('child1')
self.p2, self.c2 = self.makeChildBlock('child2')
Expand All @@ -93,12 +92,15 @@ def setUp(self):
self.checkState(sm.DISABLED)
self.p.start()

retry = 0
while retry < 20 and self.c.state.value != sm.IDLE:
sleep(.5)
retry += 1
# wait until block is Ready
task = Task("block_ready_task", self.p)
task.when_matches(self.c.block["state"], sm.IDLE, timeout=1)

self.checkState(sm.IDLE)

def tearDown(self):
self.p.stop()

def test_init(self):
# check instantiation of object tree via logger names
self.assertEqual(self.c._logger.name,
Expand Down

0 comments on commit fe6566e

Please sign in to comment.