[asterisk-commits] wdoekes: testsuite/asterisk/trunk r3005 - in /asterisk/trunk: lib/python/aste...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jan 24 13:39:47 CST 2012
Author: wdoekes
Date: Tue Jan 24 13:39:41 2012
New Revision: 3005
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3005
Log:
Speed up CDR testcases by quitting as soon as all channels are hung up.
Review: https://reviewboard.asterisk.org/r/1671
Modified:
asterisk/trunk/lib/python/asterisk/CDRTestCase.py
asterisk/trunk/lib/python/asterisk/TestCase.py
asterisk/trunk/lib/python/asterisk/asterisk.py
asterisk/trunk/tests/cdr/console_dial_sip_answer/run-test
asterisk/trunk/tests/cdr/console_dial_sip_busy/run-test
Modified: asterisk/trunk/lib/python/asterisk/CDRTestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/CDRTestCase.py?view=diff&rev=3005&r1=3004&r2=3005
==============================================================================
--- asterisk/trunk/lib/python/asterisk/CDRTestCase.py (original)
+++ asterisk/trunk/lib/python/asterisk/CDRTestCase.py Tue Jan 24 13:39:41 2012
@@ -10,6 +10,7 @@
import sys
import logging
from twisted.internet import reactor
+from twisted.internet.error import ReactorNotRunning
sys.path.append("lib/python")
from asterisk import Asterisk
@@ -26,7 +27,7 @@
Example Usage:
class TestFoo(CDRTestCase):
def __init__(self):
- TestCase.__init__(self):
+ super(TestFoo, self).__init__()
self.add_expectation("Master", AsteriskCSVCDRLine(
accountcode='testsuite',
source='',
@@ -50,7 +51,7 @@
"""
Create a single Asterisk instance.
"""
- TestCase.__init__(self)
+ super(CDRTestCase, self).__init__()
self.CDRFileExpectations = defaultdict(list)
self.create_asterisk()
@@ -121,15 +122,26 @@
"""
An AMI callback event from create_ami_factory() function.
"""
- TestCase.ami_connect(self, ami)
+ super(CDRTestCase, self).ami_connect(self)
+ ami.registerEvent("Hangup", self.ami_test_done)
+
self.ami[0].originate(
channel = 'Local/1 at default',
application = 'Echo'
).addErrback(self.ami_logoff)
+ def ami_test_done(self, ami, event):
+ if event.get("event") == "Hangup":
+ if self.no_active_channels():
+ try:
+ self.stop_reactor()
+ except ReactorNotRunning:
+ # No problemo.
+ pass
+
def run(self):
"""
Create an AMI factory with a calback for the ami_connect() function.
"""
- TestCase.run(self)
+ super(CDRTestCase, self).run()
self.create_ami_factory()
Modified: asterisk/trunk/lib/python/asterisk/TestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/TestCase.py?view=diff&rev=3005&r1=3004&r2=3005
==============================================================================
--- asterisk/trunk/lib/python/asterisk/TestCase.py (original)
+++ asterisk/trunk/lib/python/asterisk/TestCase.py Tue Jan 24 13:39:41 2012
@@ -236,6 +236,18 @@
return res
+ def no_active_channels(self):
+ """
+ Return true if all our asterisk children have 0 active channels.
+ """
+ for asterisk in self.ast:
+ # 0 active channels
+ first_line = asterisk.cli_exec('core show channels count').split('\n', 1)[0]
+ # 0
+ first_number = first_line.split(' ', 1)[0]
+ if first_number != '0':
+ return False
+ return True
def stop_reactor(self):
"""
@@ -246,10 +258,10 @@
reactor.stop()
def __reactor_timeout(self):
- '''
+ """
A wrapper function for stop_reactor(), so we know when a reactor timeout
has occurred.
- '''
+ """
logger.warning("Reactor timeout: '%s' seconds" % self.reactor_timeout)
self.stop_reactor()
Modified: asterisk/trunk/lib/python/asterisk/asterisk.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/asterisk.py?view=diff&rev=3005&r1=3004&r2=3005
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (original)
+++ asterisk/trunk/lib/python/asterisk/asterisk.py Tue Jan 24 13:39:41 2012
@@ -139,13 +139,16 @@
start = time.time()
while True:
- if (self.cli_exec("core waitfullybooted") != ""):
- break
- else:
+ # This command should stall until completed, but if an
+ # exception occurs, it returns the empty string.
+ if not self.cli_exec("core waitfullybooted"):
if time.time() - start > 5:
+ logger.error("Unknown state of asterisk. Stopping waitfullybooted...")
break
logger.debug("Attempting waitfullybooted again...")
- continue
+ else:
+ # We're fully booted...
+ break
def stop(self):
"""Stop this instance of Asterisk.
Modified: asterisk/trunk/tests/cdr/console_dial_sip_answer/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/console_dial_sip_answer/run-test?view=diff&rev=3005&r1=3004&r2=3005
==============================================================================
--- asterisk/trunk/tests/cdr/console_dial_sip_answer/run-test (original)
+++ asterisk/trunk/tests/cdr/console_dial_sip_answer/run-test Tue Jan 24 13:39:41 2012
@@ -8,13 +8,8 @@
'''
import sys
-import os
-import logging
-import re
sys.path.append("lib/python")
-from asterisk.asterisk import Asterisk
-from asterisk.cdr import AsteriskCSVCDR, AsteriskCSVCDRLine
-from asterisk.TestCase import TestCase
+from asterisk.cdr import AsteriskCSVCDRLine
from asterisk.CDRTestCase import CDRTestCase
from twisted.internet import reactor
from asterisk.version import AsteriskVersion
Modified: asterisk/trunk/tests/cdr/console_dial_sip_busy/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/console_dial_sip_busy/run-test?view=diff&rev=3005&r1=3004&r2=3005
==============================================================================
--- asterisk/trunk/tests/cdr/console_dial_sip_busy/run-test (original)
+++ asterisk/trunk/tests/cdr/console_dial_sip_busy/run-test Tue Jan 24 13:39:41 2012
@@ -8,15 +8,10 @@
'''
import sys
-from time import sleep
-import os
sys.path.append("lib/python")
-from asterisk.asterisk import Asterisk
-from asterisk.cdr import AsteriskCSVCDR, AsteriskCSVCDRLine
-from asterisk.ami import AMI
+from asterisk.cdr import AsteriskCSVCDRLine
from asterisk.CDRTestCase import CDRTestCase
from twisted.internet import reactor
-import logging
class SIP_Dial_Busy_Test(CDRTestCase):
def __init__(self):
@@ -36,4 +31,6 @@
return test.results()
if __name__ == '__main__':
- sys.exit(main())
+ sys.exit(main())
+
+# vim:sw=4:ts=4:expandtab:textwidth=79
More information about the asterisk-commits
mailing list