[asterisk-commits] mjordan: testsuite/asterisk/trunk r2628 - in /asterisk/trunk: lib/python/aste...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Oct 17 15:10:53 CDT 2011
Author: mjordan
Date: Mon Oct 17 15:10:49 2011
New Revision: 2628
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=2628
Log:
Updated leave_voicemail_nominal to make it more resistant to failures due to
thread context switch timing issues
Modified:
asterisk/trunk/lib/python/asterisk/voicemail.py
asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/configs/ast2/extensions.conf
asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/run-test
Modified: asterisk/trunk/lib/python/asterisk/voicemail.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/voicemail.py?view=diff&rev=2628&r1=2627&r2=2628
==============================================================================
--- asterisk/trunk/lib/python/asterisk/voicemail.py (original)
+++ asterisk/trunk/lib/python/asterisk/voicemail.py Mon Oct 17 15:10:49 2011
@@ -102,7 +102,7 @@
def hangup(self):
if self.astSender == None:
logger.error("Attempting to send hangup to non-existant Asterisk instance")
- TestCase.testStateController.changeState(FailureTestState(self.controller))
+ self.testStateController.changeState(FailureTestState(self.controller))
return
df = self.amiSender.redirect(self.senderChannel, "voicemailCaller", "hangup", 1)
@@ -116,12 +116,12 @@
logger.info("Attempting to send DTMF " + dtmfToSend)
if self.amiSender == None:
logger.error("Attempting to send DTMF to non-connected caller AMI")
- TestCase.testStateController.changeState(FailureTestState(self.controller))
+ self.testStateController.changeState(FailureTestState(self.controller))
return
if self.astSender == None:
logger.error("Attempting to send DTMF to non-existant Asterisk instance")
- TestCase.testStateController.changeState(FailureTestState(self.controller))
+ self.testStateController.changeState(FailureTestState(self.controller))
return
if (self.__previous_dtmf != dtmfToSend):
@@ -142,12 +142,12 @@
def sendSoundFile(self, audioFile):
if self.amiSender == None:
logger.error("Attempting to send sound file to non-connected caller AMI")
- TestCase.testStateController.changeState(FailureTestState(self.controller))
+ self.testStateController.changeState(FailureTestState(self.controller))
return
if self.astSender == None:
logger.error("Attempting to send sound file to non-existant Asterisk instance")
- TestCase.testStateController.changeState(FailureTestState(self.controller))
+ self.testStateController.changeState(FailureTestState(self.controller))
return
if (self.__previous_audio != audioFile):
Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/configs/ast2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/configs/ast2/extensions.conf?view=diff&rev=2628&r1=2627&r2=2628
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/configs/ast2/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/configs/ast2/extensions.conf Mon Oct 17 15:10:49 2011
@@ -3,31 +3,24 @@
;
; You may need to alter the Wait(10) statement if the audio prompt
; played back by the receiver has a longer greeting then the default.
+[voicemailCaller]
-[sendvoicemail]
-exten => 1234,1,NoOp()
- same => n,Wait(10)
- same => n,Verbose(1, Playing back ${TALK_AUDIO})
- same => n,Playback(${TALK_AUDIO})
- same => n,Verbose(1, Sending # key)
- same => n,SendDTMF(#)
- same => n,Wait(1)
- same => n,Hangup()
+exten => sendDTMF,1,NoOp()
+ same => n,Verbose(1, Sending DTMF Signal ${DTMF_TO_SEND})
+ same => n,SendDTMF(${DTMF_TO_SEND})
+ same => n,Goto(voicemailCaller,wait,1)
-exten => 5678,1,NoOp()
- same => n,Wait(10)
- same => n,Verbose(1, Playing back ${TALK_AUDIO})
- same => n,Playback(${TALK_AUDIO})
- same => n,Verbose(1, Hanging up Abruptly)
- same => n,UserEvent(TestResult,result: pass, status: VoiceMail exited successfully)
- same => n,Wait(1)
- same => n,Hangup()
+exten => hangup,1,NoOp()
+ same => n,Verbose(1, Hanging up)
+ same => n,Hangup()
-exten => 9000,1,NoOp()
- same => n,Wait(10)
- same => n,Verbose(1, Playing back ${TALK_AUDIO})
- same => n,Playback(${TALK_AUDIO})
- same => n,Verbose(1, Sending # key)
- same => n,SendDTMF(#)
- same => n,Wait(1)
- same => n,Hangup()
+exten => wait,1,NoOp()
+ same => n,Wait(10000)
+
+exten => sendAudioWithDTMF,1,NoOp()
+ same => n,Verbose(1, Sending audio file ${TALK_AUDIO})
+ same => n,Playback(${TALK_AUDIO})
+ same => n,Verbose(1, Sending DTMF Signal ${DTMF_TO_SEND})
+ same => n,SendDTMF(${DTMF_TO_SEND})
+ same => n,Goto(voicemailCaller,wait,1)
+
Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/run-test?view=diff&rev=2628&r1=2627&r2=2628
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/run-test (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/run-test Mon Oct 17 15:10:49 2011
@@ -20,10 +20,79 @@
from asterisk.asterisk import Asterisk
from asterisk.TestCase import TestCase
from asterisk.voicemail import VoiceMailMailboxManagement
+from asterisk.voicemail import VoiceMailState
+from asterisk.voicemail import VoiceMailTest
logger = logging.getLogger(__name__)
-class LeaveVoicemailNominal(TestCase):
+"""
+TestState that is the entry point for the VoiceMail application
+"""
+class StartVoiceMailState(VoiceMailState):
+
+ def __init__(self, controller, voiceMailTest):
+ VoiceMailState.__init__(self, controller, voiceMailTest)
+
+ def handleStateChange(self, ami, event):
+ state = event['state']
+ if state == 'PLAYBACK':
+ message = event['message']
+
+ if message == 'vm-intro':
+ self.changeState(IntroVoiceMailState(self.controller, self.voiceMailTest))
+ else:
+ self.handleDefaultState(event)
+ else:
+ self.handleDefaultState(event)
+
+ def getStateName(self):
+ return "START"
+
+"""
+TestState that occurs when the Intro message is read, and will start the audio playback at the beep.
+After this the test states transition to a pending until switched back to Start by the reception
+of a UserEvent.
+"""
+class IntroVoiceMailState(VoiceMailState):
+
+ def __init__(self, controller, voiceMailTest):
+ VoiceMailState.__init__(self, controller, voiceMailTest)
+
+ def handleStateChange(self, ami, event):
+ state = event['state']
+ if state == 'PLAYBACK':
+ message = event['message']
+
+ if message == 'beep':
+ """ A beep indicates we need to stream some sound file over - use the same sound file for everything """
+ audioFile = os.path.join(os.getcwd(), "%s/sounds/talking" % (self.voiceMailTest.testParentDir))
+ self.voiceMailTest.sendSoundFileWithDTMF(audioFile, "#")
+ self.changeState(PendingVoiceMailState(self.controller, self.voiceMailTest))
+ else:
+ self.handleDefaultState(event)
+ else:
+ self.handleDefaultState(event)
+ def getStateName(self):
+ return "INTRO"
+
+"""
+TestState that occurs between leaving voicemails
+"""
+class PendingVoiceMailState(VoiceMailState):
+
+ def __init__(self, controller, voiceMailTest):
+ VoiceMailState.__init__(self, controller, voiceMailTest)
+ """ Reset the reactor timeout """
+ self.voiceMailTest.reset_timeout()
+
+ def handleStateChange(self, ami, event):
+ pass
+
+ def getStateName(self):
+ return "PENDING"
+
+
+class LeaveVoicemailNominal(VoiceMailTest):
"""The parent directory that this test resides in
"""
@@ -32,29 +101,41 @@
def __init__(self):
super(LeaveVoicemailNominal, self).__init__()
self.testResultsReceived = 0
- self.reactor_timeout = 120
+ self.reactor_timeout = 45
self.create_asterisk(2)
+ self.test_counter = 0
+ self.extensions = [1234,1234,5678,5678,9000]
def ami_connect(self, ami):
self.audioFile = os.path.join(os.getcwd(), "%s/sounds/talking" % (self.testParentDir))
ami.registerEvent('UserEvent', self.user_event)
+ """ Record which AMI instance we've received and attempt to set up the test controller """
+ if (ami.id == 0):
+ self.amiReceiver = ami
+ elif (ami.id == 1):
+ self.amiSender = ami
+ self.astSender = self.ast[self.amiSender.id]
+ self.createTestController()
+ if (self.testStateController != None):
+ startObject = StartVoiceMailState(self.testStateController, self)
+ self.testStateController.changeState(startObject)
+
if not (ami.id == 0):
- self.ast[ami.id].cli_exec("dialplan set global TALK_AUDIO " + self.audioFile)
-
- extensions = [1234,1234,5678,5678,9000]
- for extension in extensions:
- logger.info("Originating call to sip/ast1/" + str(extension))
- df = ami.originate("sip/ast1/" + str(extension), "sendvoicemail", str(extension), 1, None, "CallId-" + str(extension), None, None, None, {}, True )
- df.addErrback(self.handleOriginateFailure)
+ self.originate_call()
+
+ def originate_call(self):
+ extension = self.extensions[self.test_counter]
+ logger.info("Originating call to sip/ast1/" + str(extension))
+ df = self.amiSender.originate("sip/ast1/" + str(extension), "voicemailCaller", "wait", 1, None, "CallId-" + str(extension), None, None, None, {}, True )
+ df.addErrback(self.handleOriginateFailure)
def user_event(self, ami, event):
if event['userevent'] != 'TestResult':
return
self.testResultsReceived += 1
- super(LeaveVoicemailNominal, self).reset_timeout()
if event['result'] == "pass":
self.passed = True
logger.info("VoiceMail successfully exited")
@@ -66,6 +147,12 @@
if self.testResultsReceived == 5:
logger.info("All results received; stopping reactor")
self.stop_reactor()
+ else:
+ """ Originate the next call and reset the state machine """
+ self.test_counter += 1
+ self.senderChannel = "SIP/ast1-0000000" + str(self.test_counter)
+ self.testStateController.changeState(StartVoiceMailState(self.testStateController, self))
+ self.originate_call()
def run(self):
super(LeaveVoicemailNominal, self).run()
More information about the asterisk-commits
mailing list