[asterisk-dev] [Code Review] Testsuite test for hangup handlers.
Matt Jordan
reviewboard at asterisk.org
Wed Jul 25 13:57:38 CDT 2012
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/2062/#review6808
-----------------------------------------------------------
/asterisk/trunk/tests/hangup/handlers/run-test
<https://reviewboard.asterisk.org/r/2062/#comment13086>
You can define tests, their parameters, and their expected results as a list of dictionaries. Those dictionaries can contain anything you want. So this can be as complex or as simple as you need:
self._tests = []
self._tests.append(
{ 'expected_results' :
{ 'hangup_count': 2,
'hexten_count': 0,
'hhandler_in_count': 0,
...
},
'test_params' :
{ 'exten': 'foo'}
})
self._tests.append(
{ 'expected_results' :
{ 'something_else': 3
...
}
...
})
Then you can do something like:
self.execute(self._tests[self._current])
And you can check the results in the same fashion:
if (self._tests[self._current]['expected_results']['hangup_count'] != event['hangup_count']):
self.passed = False
I'm willing to bet that if you used some form of data structure, as opposed to a large number of member variables, you'd be able to find some other much more elegant way of expressing these tests.
This would also let you refactor large blocks of your code into small, common sub routines.
/asterisk/trunk/tests/hangup/handlers/run-test
<https://reviewboard.asterisk.org/r/2062/#comment13088>
If nothing else, each of these checks could be refactored into smaller subroutines that verify tests of each particular type.
/asterisk/trunk/tests/hangup/handlers/run-test
<https://reviewboard.asterisk.org/r/2062/#comment13089>
There's no reason not to have a single routine that resets your test state. The "cost" of setting variables to 0 when they may already be 0 is offset by the fact that you are, in fact, running in Python.
/asterisk/trunk/tests/hangup/handlers/run-test
<https://reviewboard.asterisk.org/r/2062/#comment13091>
Assuming you don't want to auto fail the test when a failing condition happens, but you also don't want the test to accidentally pass later on, you can now use self.passed() to set the pass/fail status of the test.
Setting self.passed(False) will set the test pass status to False, and will prevent a later self.passed(True) from overwriting the failed state.
- Matt
On July 25, 2012, 12:19 p.m., rmudgett wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/2062/
> -----------------------------------------------------------
>
> (Updated July 25, 2012, 12:19 p.m.)
>
>
> Review request for Asterisk Developers.
>
>
> Summary
> -------
>
> Tests to test hangup handlers:
> 1) Tests relative hangup handler location resolution.
> 2) Tests hangup_handler_pop and hangup_handler_wipe
> 3) Tests hangup handler stack execution order
> 4) Tests hangup handler execution on both sides of a single call with and without an h-exten.
> 5) Tests hangup handler execution on a forked call with and without an h-exten.
> 6) First half of CDR endbeforehexten test. Tests the default no setting.
>
>
> This addresses bug SWP-4207.
> https://issues.asterisk.org/jira/browse/SWP-4207
>
>
> Diffs
> -----
>
> /asterisk/trunk/tests/hangup/handlers/configs/ast1/cdr.conf PRE-CREATION
> /asterisk/trunk/tests/hangup/handlers/configs/ast1/extensions.conf PRE-CREATION
> /asterisk/trunk/tests/hangup/handlers/run-test PRE-CREATION
> /asterisk/trunk/tests/hangup/handlers/test-config.yaml PRE-CREATION
> /asterisk/trunk/tests/hangup/tests.yaml PRE-CREATION
> /asterisk/trunk/tests/tests.yaml 3361
>
> Diff: https://reviewboard.asterisk.org/r/2062/diff
>
>
> Testing
> -------
>
> All tests pass.
>
>
> Thanks,
>
> rmudgett
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20120725/99af5e13/attachment-0001.htm>
More information about the asterisk-dev
mailing list