[asterisk-commits] jrose: testsuite/asterisk/trunk r4551 - in /asterisk/trunk/tests/channels/pjs...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 10 16:16:59 CST 2014


Author: jrose
Date: Fri Jan 10 16:16:55 2014
New Revision: 4551

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4551
Log:
testsuite: PJSIP hold test improvements and corrections

SIPP scenarios ported from the chan_sip hold tests were attempting to
start the calls in sendonly mode instead of in sendrecv. This seemed
incorrect and was causing (very) spurious test failures, so I changed
it.

Review: https://reviewboard.asterisk.org/r/3105/

Modified:
    asterisk/trunk/tests/channels/pjsip/hold/run-test
    asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_IP_media_restrict.xml
    asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_IP_restrict.xml
    asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_media_restrict.xml

Modified: asterisk/trunk/tests/channels/pjsip/hold/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/hold/run-test?view=diff&rev=4551&r1=4550&r2=4551
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/hold/run-test (original)
+++ asterisk/trunk/tests/channels/pjsip/hold/run-test Fri Jan 10 16:16:55 2014
@@ -1,11 +1,11 @@
 #!/usr/bin/env python
-'''
+"""
 Copyright (C) 2014, Digium, Inc.
 Jonathan Rose <jrose at digium.com>
 
 This program is free software, distributed under the terms of
 the GNU General Public License Version 2.
-'''
+"""
 
 import sys
 import logging
@@ -16,13 +16,16 @@
 from asterisk.sipp import SIPpScenario
 from twisted.internet import reactor
 
-logger = logging.getLogger(__name__)
+LOGGER = logging.getLogger(__name__)
 INJECT_FILE = "inject.csv"
 
 
 class SIPHold(TestCase):
+    '''TestCase to execute and evaluate PJSIP hold/unhold scenarios '''
+
     def __init__(self):
-        TestCase.__init__(self)
+        ''' Constructor '''
+        super(SIPHold, self).__init__()
         self.create_asterisk()
 
         self.sipp_scn_phone_a = [{'scenario': 'phone_A.xml',
@@ -56,10 +59,16 @@
         self.hold_events = 0
         self.unhold_events = 0
         self.user_events = 0
-        self.__test_counter = 0
+        self._test_counter = 0
+        self._a_finished = False
+        self._b_finished = False
 
     def ami_connect(self, ami):
-        TestCase.ami_connect(self, ami)
+        ''' Reaction to new AMI connection
+
+        :param ami: AMI connection that was established
+        '''
+        super(SIPHold, self).ami_connect(ami)
         ami.registerEvent('UserEvent', self.user_event_handler)
 
         ami.registerEvent('MusicOnHoldStart', self.moh_start_event_handler)
@@ -68,37 +77,55 @@
         ami.registerEvent('Hold', self.hold_event_handler)
         ami.registerEvent('Unhold', self.unhold_event_handler)
 
-        logger.info("Starting SIP scenario")
+        LOGGER.info("Starting SIP scenario")
         self.execute_scenarios()
 
     def execute_scenarios(self):
+        '''Execute sipp scenarios and check results for a single test phase
+        '''
         def __check_scenario_a(result):
-            self.__a_finished = True
+            ''' Callback from successful sipp scenario - raises flag
+            indicating that side A completed execution
+
+            :param result: value returned by sipp indicating completion status
+            '''
+            self._a_finished = True
             return result
 
         def __check_scenario_b(result):
-            self.__b_finished = True
+            ''' Callback from successful sipp scenario - raises flag
+            indicating that side B completed execution
+
+            :param result: value returned by sipp indicating completion status
+            '''
+            self._b_finished = True
             return result
 
         def __execute_next_scenario(result):
-            if self.__a_finished and self.__b_finished:
-                self.__test_counter += 1
+            ''' Callback from successful sipp scenario - if both sipp
+            scenarios are finished then this function will start executing
+            the next scenario.
+
+            :param result: value returned by sipp indicating completion status
+            '''
+            if self._a_finished and self._b_finished:
+                self._test_counter += 1
                 self.reset_timeout()
                 self.execute_scenarios()
             return result
 
-        if self.__test_counter == len(self.sipp_scn_phone_a):
-            logger.info("All scenarios executed")
+        if self._test_counter == len(self.sipp_scn_phone_a):
+            LOGGER.info("All scenarios executed")
             return
 
         sipp_a = SIPpScenario(self.test_name,
-                              self.sipp_scn_phone_a[self.__test_counter])
+                              self.sipp_scn_phone_a[self._test_counter])
         sipp_b = SIPpScenario(self.test_name,
-                              self.sipp_scn_phone_b[self.__test_counter])
+                              self.sipp_scn_phone_b[self._test_counter])
 
         # Start up the listener first - Phone A calls Phone B
-        self.__a_finished = False
-        self.__b_finished = False
+        self._a_finished = False
+        self._b_finished = False
         db = sipp_b.run(self)
         da = sipp_a.run(self)
 
@@ -108,56 +135,85 @@
         db.addCallback(__execute_next_scenario)
 
     def user_event_handler(self, ami, event):
+        ''' Reacts to UserEvents issued to indicate the end of a call.
+        stops the testsuite once all calls have reached that point.
+
+        :param ami: AMI connection that the event was received from
+        :param event: Event that was received
+        '''
         self.user_events += 1
         if (self.user_events == len(self.sipp_scn_phone_a)):
-            logger.info("All user events received; stopping reactor")
+            LOGGER.info("All user events received; stopping reactor")
             self.stop_reactor()
 
     def moh_start_event_handler(self, ami, event):
-        logger.debug("Received MOH start event")
+        ''' Reacts to music on hold start events and tallies them.
+
+        :param ami: AMI connection the event was received from
+        :param event: Event that was received
+        '''
+        LOGGER.debug("Received MOH start event")
         self.moh_start_events += 1
 
     def moh_stop_event_handler(self, ami, event):
-        logger.debug("Received MOH stop event")
+        ''' Reacts to music on hold stop events and tallies them.
+
+        :param ami: AMI connection the event was received from
+        :param event: Event that was received
+        '''
+
+        LOGGER.debug("Received MOH stop event")
         self.moh_stop_events += 1
 
     def hold_event_handler(self, ami, event):
-        logger.debug("Recieved Hold event")
+        ''' Reacts to hold events and tallies them.
+
+        :param ami: AMI connection the event was received from
+        :param event: Event that was received
+        '''
+
+        LOGGER.debug("Recieved Hold event")
         self.hold_events += 1
 
     def unhold_event_handler(self, ami, event):
-        logger.debug("Received Unhold event")
+        ''' Reacts to unhold events and tallies them.
+
+        :param ami: AMI connection the event was received from
+        :param event: Event that was received
+        '''
+
+        LOGGER.debug("Received Unhold event")
         self.unhold_events += 1
 
     def run(self):
-        TestCase.run(self)
+        ''' Run the test and create an AMI connection '''
+
+        super(SIPHold, self).run()
         self.create_ami_factory()
 
 
 def main():
     test = SIPHold()
-    test.start_asterisk()
     reactor.run()
-    test.stop_asterisk()
 
     if (test.moh_start_events != len(test.sipp_scn_phone_a)):
-        logger.error("Failed to receive %d MOH start events (received %d)" %
+        LOGGER.error("Failed to receive %d MOH start events (received %d)" %
                      (len(test.sipp_scn_phone_a), test.moh_start_events))
         test.passed = False
     if (test.moh_stop_events != len(test.sipp_scn_phone_a)):
-        logger.error("Failed to receive %d MOH stop events (received %d)" %
+        LOGGER.error("Failed to receive %d MOH stop events (received %d)" %
                      (len(test.sipp_scn_phone_a), test.moh_stop_events))
         test.passed = False
     if (test.hold_events != len(test.sipp_scn_phone_a)):
-        logger.error("Failed to receive %d Hold events (received %d)" %
+        LOGGER.error("Failed to receive %d Hold events (received %d)" %
                      (len(test.sipp_scn_phone_a), test.hold_events))
         test.passed = False
     if (test.unhold_events != len(test.sipp_scn_phone_a)):
-        logger.error("Failed to receive %d Unhold events (received %d)" %
+        LOGGER.error("Failed to receive %d Unhold events (received %d)" %
                      (len(test.sipp_scn_phone_a), test.unhold_events))
         test.passed = False
     if (test.user_events != len(test.sipp_scn_phone_a)):
-        logger.error("Failed to receive %d user test events (received %d)" %
+        LOGGER.error("Failed to receive %d user test events (received %d)" %
                      (len(test.sipp_scn_phone_a), test.user_events))
         test.passed = False
 

Modified: asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_IP_media_restrict.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_IP_media_restrict.xml?view=diff&rev=4551&r1=4550&r2=4551
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_IP_media_restrict.xml (original)
+++ asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_IP_media_restrict.xml Fri Jan 10 16:16:55 2014
@@ -74,9 +74,9 @@
 			s=Polycom IP Phone
 			c=IN IP4 [local_ip]
 			t=0 0
-			a=sendonly
+			a=sendrecv
 			m=audio 2226 RTP/AVP 0 101
-			a=sendonly
+			a=sendrecv
 			a=rtpmap:0 PCMU/8000
 			a=rtpmap:101 telephone-event/8000
 		]]>

Modified: asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_IP_restrict.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_IP_restrict.xml?view=diff&rev=4551&r1=4550&r2=4551
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_IP_restrict.xml (original)
+++ asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_IP_restrict.xml Fri Jan 10 16:16:55 2014
@@ -74,9 +74,9 @@
 			s=Polycom IP Phone
 			c=IN IP4 [local_ip]
 			t=0 0
-			a=sendonly
+			a=sendrecv
 			m=audio 2226 RTP/AVP 0 101
-			a=sendonly
+			a=sendrecv
 			a=rtpmap:0 PCMU/8000
 			a=rtpmap:101 telephone-event/8000
 		]]>

Modified: asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_media_restrict.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_media_restrict.xml?view=diff&rev=4551&r1=4550&r2=4551
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_media_restrict.xml (original)
+++ asterisk/trunk/tests/channels/pjsip/hold/sipp/phone_B_media_restrict.xml Fri Jan 10 16:16:55 2014
@@ -74,9 +74,9 @@
 			s=Polycom IP Phone
 			c=IN IP4 [local_ip]
 			t=0 0
-			a=sendonly
+			a=sendrecv
 			m=audio 2226 RTP/AVP 0 101
-			a=sendonly
+			a=sendrecv
 			a=rtpmap:0 PCMU/8000
 			a=rtpmap:101 telephone-event/8000
 		]]>




More information about the asterisk-commits mailing list