Skip to content

Instantly share code, notes, and snippets.

@eigenhombre
Created June 13, 2012 16:51
Show Gist options
  • Select an option

  • Save eigenhombre/2925230 to your computer and use it in GitHub Desktop.

Select an option

Save eigenhombre/2925230 to your computer and use it in GitHub Desktop.
class TestHardPDAQCrash(TestLiveControlWithPDAQ):
def test(self):
assert 'OK' == livecmd("config set -i default")
assert 'OK' == livecmd("altconfigs add -i alt1")
assert 'OK' == livecmd("start daq")
# Simulate hard crash of pDAQ:
self.toy.close()
# Lexical closure to collect complete set of log messages:
def message_updater():
msgs = []
def update_msgs():
msgs.extend(drain_queue(self.sink))
def messages_received_so_far():
update_msgs()
return msgs
return messages_received_so_far
allmsgs = message_updater()
def correct_recovery_failure_messages_generated():
all = allmsgs()
moni = [x["payload"] for x in all if x["cmd"] == "moni"]
logs = [x["value"] for x in moni if x["varname"] == "log"]
recovery_fail_msgs = filter(
lambda x: "failed and did not generate any events" in x,
logs)
failed_configs = [re.findall("config (\S+) failed", m)[0]
for m in recovery_fail_msgs]
return failed_configs == (["default" for _ in range(4)] +
["alt1" for _ in range(4)])
misc.wait_until(correct_recovery_failure_messages_generated)
@mrocklin
Copy link

I've done something like the following before

def allmsgs():
    allmsgs._msgs.extend(drain_queue(self.sink))
    return allmsgs._msgs
allmsgs._msgs = []

This is very clearly complecting functions and data. It works though and appears to be what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment