[Asterisk-code-review] Fix bouncing sip bye also test. (testsuite[master])

Anonymous Coward asteriskteam at digium.com
Thu Feb 18 12:05:24 CST 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: Fix bouncing sip_bye_also test.
......................................................................


Fix bouncing sip_bye_also test.

The test was failing for a few reasons

* The SIPp scenarios had no delay between sending an ACK and sending a
  BYE with Also. This meant that sometimes the BYE would be received
  before the SIP channel was bridged, resulting in a failed transfer.
  This was not actually detected by the test as a failure, but I noticed
  it when diagnosing the test.

* The AMI hangup action would sometimes run before all of the calls had
  stabilized. This resulted in Asterisk sending a 503 response to
  incoming INVITEs from SIPp.

Unfortunately, simply increasing the delay before running the AMI action
did not work as expected. The SIPpTestCase would end the test once all
SIPp scenarios had finished. This resulted in a failing test because the
AMI action did not run before the test completed.

This commit introduces two changes to get the test passing.

First, the SIPp scenario that is run now has a two-second delay between
sending the ACK and sending the BYE. This allows time for calls to be
bridged before attempting the transfer.

Second, the SIPpTestCase has been altered to have an option,
"stop-after-scenarios". When set to "False", the test will not stop
after the SIPp scenarios have completed. Stopping the test is left to
another party. To complement this, the SIPpAMIActionTestCase has a new
option, "run-after-scenarios". This makes it so the AMI action is not
attempted until after the SIPp scenarios have all completed.

By using these new options, we can be sure not to run the AMI action to
early, and we can be sure the test won't stop before the AMI action has
a chance to run. The test has been altered to use the HangupMonitor in
order to stop the test.

Change-Id: Iaaa791f24fe52515c42e4c529bb8f0fd6494ea7a
---
M lib/python/asterisk/sipp.py
M tests/channels/SIP/sip_bye_also/test-config.yaml
2 files changed, 39 insertions(+), 9 deletions(-)

Approvals:
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved
  George Joseph: Looks good to me, but someone else must approve



diff --git a/lib/python/asterisk/sipp.py b/lib/python/asterisk/sipp.py
index 83f5e82..59aa54b 100644
--- a/lib/python/asterisk/sipp.py
+++ b/lib/python/asterisk/sipp.py
@@ -97,6 +97,11 @@
         else:
             self._fail_on_any = True
 
+        if 'stop-after-scenarios' in self._test_config:
+            self._stop_after_scenarios = self._test_config['stop-after-scenarios']
+        else:
+            self._stop_after_scenarios = True
+
         self.register_intermediate_obverver(self._handle_scenario_finished)
         self.create_asterisk()
 
@@ -231,12 +236,14 @@
 
         final_deferred = defer.Deferred()
         final_deferred.addCallback(_final_deferred_callback)
-        final_deferred.addCallback(_finish_test)
+        if self._stop_after_scenarios:
+            final_deferred.addCallback(_finish_test)
         sipp_sequence = SIPpScenarioSequence(self,
                                              self.scenarios,
                                              self._fail_on_any,
                                              self._intermediate_callback_fn,
-                                             final_deferred)
+                                             final_deferred,
+                                             self._stop_after_scenarios)
         sipp_sequence.register_scenario_start_callback(self._scenario_start_callback_fn)
         sipp_sequence.register_scenario_stop_callback(self._scenario_stop_callback_fn)
         sipp_sequence.execute()
@@ -284,6 +291,11 @@
 
         self.ami_args = test_config['ami-action']['args']
         self.ami_delay = test_config['ami-action'].get('delay', 0)
+        self.run_after_scenarios = test_config['ami-action'].get(
+            'run-after-scenarios', False
+        )
+        if self.run_after_scenarios:
+            self.register_final_observer(self.scenarios_complete)
 
     def on_reactor_timeout(self):
         """Create a failure token when the test times out"""
@@ -295,19 +307,28 @@
             return
         self.remove_fail_token(self.ami_token)
 
-    def ami_connect(self, ami):
-        """Handle the AMI connect event"""
-        super(SIPpAMIActionTestCase, self).ami_connect(ami)
-
+    def run_ami_action(self):
         def _ami_action():
             """Send the AMI action"""
             LOGGER.info("Sending Action: %s" % self.ami_args)
-            ami_out = ami.sendDeferred(self.ami_args)
-            ami_out.addCallback(ami.errorUnlessResponse)
+            ami_out = self.ami.sendDeferred(self.ami_args)
+            ami_out.addCallback(self.ami.errorUnlessResponse)
             ami_out.addCallback(self.remove_token_on_success)
 
         reactor.callLater(self.ami_delay, _ami_action)
 
+    def ami_connect(self, ami):
+        """Handle the AMI connect event"""
+        super(SIPpAMIActionTestCase, self).ami_connect(ami)
+        self.ami = ami
+
+        if not self.run_after_scenarios:
+            self.run_ami_action()
+
+    def scenarios_complete(self, test, test_object):
+        LOGGER.info("Scenarios complete, running AMI action")
+        self.run_ami_action()
+
 
 class SIPpScenarioSequence(object):
     """Execute a sequence of SIPp Scenarios in sequence.
diff --git a/tests/channels/SIP/sip_bye_also/test-config.yaml b/tests/channels/SIP/sip_bye_also/test-config.yaml
index a51f27d..1774f2e 100644
--- a/tests/channels/SIP/sip_bye_also/test-config.yaml
+++ b/tests/channels/SIP/sip_bye_also/test-config.yaml
@@ -16,14 +16,23 @@
     test-object:
         config-section: sipp-config
         typename: 'sipp.SIPpAMIActionTestCase'
+    modules:
+        -
+            config-section: hangup-config
+            typename: 'pluggable_modules.HangupMonitor'
+
+hangup-config:
+    ids: '0'
 
 sipp-config:
     fail-on-any: True
+    stop-after-scenarios: False
     test-iterations:
         -
             scenarios:
-                - { 'key-args': {'scenario': 'uac-bye-also.xml', '-p': '5061', '-m': '10', '-s': '200'} }
+                - { 'key-args': {'scenario': 'uac-bye-also.xml', '-p': '5061', '-m': '10', '-s': '200', '-d': '2000'} }
     ami-action:
+        run-after-scenarios: True
         delay: 1
         args:
             Action: 'Hangup'

-- 
To view, visit https://gerrit.asterisk.org/2262
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iaaa791f24fe52515c42e4c529bb8f0fd6494ea7a
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <george.joseph at fairview5.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list