[asterisk-commits] kmoore: testsuite/asterisk/trunk r3122 - /asterisk/trunk/lib/python/asterisk/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 21 16:55:27 CDT 2012


Author: kmoore
Date: Wed Mar 21 16:55:23 2012
New Revision: 3122

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3122
Log:
Avoid requesting channel status via AMI to improve execution speed

This allows SimpleTestCase to catch Newchannel events as they come in so the
channel can be stored instead of having to request the list of channels which
is slow and seemingly prone to failure.

Modified:
    asterisk/trunk/lib/python/asterisk/SimpleTestCase.py

Modified: asterisk/trunk/lib/python/asterisk/SimpleTestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/SimpleTestCase.py?view=diff&rev=3122&r1=3121&r2=3122
==============================================================================
--- asterisk/trunk/lib/python/asterisk/SimpleTestCase.py (original)
+++ asterisk/trunk/lib/python/asterisk/SimpleTestCase.py Wed Mar 21 16:55:23 2012
@@ -21,6 +21,7 @@
     event.'''
     event_count = 0
     expected_events = 1
+    hangup_chan = None
 
     def __init__(self):
         TestCase.__init__(self)
@@ -30,6 +31,7 @@
         LOGGER.info("Initiating call to local/100 at test on Echo() for simple test")
 
         ami.registerEvent('UserEvent', self.__event_cb)
+        ami.registerEvent('Newchannel', self.__channel_cb)
         df = ami.originate("local/100 at test", application="Echo")
 
         def handle_failure(reason):
@@ -40,34 +42,22 @@
 
         df.addErrback(handle_failure)
 
+    def __channel_cb(self, ami, event):
+        if not self.hangup_chan:
+            self.hangup_chan = event['channel']
+
     def __event_cb(self, ami, event):
         if self.verify_event(event):
             self.event_count += 1
             if self.event_count == self.expected_events:
-                # get list of channels so hangups can happen
-                df = self.ami[0].status().addCallbacks(self.status_callback,
-                    self.status_failed)
+                self.passed = True
+                LOGGER.info("Test ending, hanging up channel")
+                self.ami[0].hangup(self.hangup_chan).addCallbacks(
+                    self.hangup)
 
-    def status_callback(self, result):
-        '''Initiate hangup since no more testing will take place'''
-        for status_result in result:
-            if 'channel' in status_result:
-                self.ami[0].hangup(status_result['channel']).addCallbacks(
-                    self.hangup_success)
-            break
-        else:
-            # no channels to hang up? close it out
-            self.passed = True
-            self.stop_reactor()
-
-    def hangup_success(self, result):
+    def hangup(self, result):
         '''Now that the channels are hung up, the test can be ended'''
-        self.passed = True
-        self.stop_reactor()
-
-    def status_failed(self, reason):
-        '''If the channel listing failed, we still need to shut down'''
-        self.passed = True
+        LOGGER.info("Hangup complete, stopping reactor")
         self.stop_reactor()
 
     def verify_event(self, event):




More information about the asterisk-commits mailing list