Created
June 13, 2012 16:51
-
-
Save eigenhombre/2925230 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Author
Python has weird scoping rules for variables within functions, so I didn't try it that way at the beginning -- trying it now, though
Author
You are right , that works -- even better, thanks! Code reviews FTW. I can't remember under what conditions I've been screwed by function-local variables before, but it's definitely quirky in python.
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
Why not turn
into