[asterisk-commits] mjordan: testsuite/asterisk/trunk r4702 - /asterisk/trunk/tests/channels/pjsi...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Feb 14 06:51:24 CST 2014
Author: mjordan
Date: Fri Feb 14 06:48:11 2014
New Revision: 4702
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4702
Log:
pjsip/subscribe/missing_aor: Fix race condition in starting SIPp scenario
The pjsip/subscribe/missing_aor has been failing consistently on some build
agents. The reason why is due to how the test was written. Each step in the
test is triggered on the success of the previous step, where the previous
step was typically an AMI action execution. However, the AMI actions for
updating external MWI occur when the Stasis message for modifying the
mailbox state has been created and dispatched, not when the core has
actually bothered to update the MWI. Hence, the test was running through
its various AMI actions and then sending the SIP SUBSCRIBE request before
all of the mailbox state had been updated.
On the fast build agent, this typically failed. On the slow build agent,
it typically succeeded due to Asterisk actually running faster than the
test python script.
This patch refactors the test to use the AMI event MessageWaiting to
trigger the next stage. The AMI event is raised when the core itself has
actually updated the mailbox, so the test knows for sure that the
mailboxes are in the correct state before it subscribes.
Review: https://reviewboard.asterisk.org/r/3217/
Modified:
asterisk/trunk/tests/channels/pjsip/subscribe/missing_aor/run-test
Modified: asterisk/trunk/tests/channels/pjsip/subscribe/missing_aor/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/subscribe/missing_aor/run-test?view=diff&rev=4702&r1=4701&r2=4702
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/subscribe/missing_aor/run-test (original)
+++ asterisk/trunk/tests/channels/pjsip/subscribe/missing_aor/run-test Fri Feb 14 06:48:11 2014
@@ -8,12 +8,15 @@
'''
import sys
+import logging
sys.path.append("lib/python/asterisk")
from twisted.internet import reactor
from sipp import SIPpScenario
from test_case import TestCase
+
+LOGGER = logging.getLogger(__name__)
class MissingAor(TestCase):
"""Test case for subscribing to MWI without an aor/name in the sip uri"""
@@ -35,6 +38,7 @@
Once added subscribe to both mailboxes at once by issuing a subscribe
without an aor/name in the sip uri.
"""
+
def _mwi_update(num):
"""Create an external MWI update action."""
return {
@@ -43,7 +47,7 @@
'NewMessages': 1,
'OldMessages': 0}
- def _on_scenario(obj):
+ def _on_scenario_complete(obj):
"""Callback handler for when the sipp scenario runs successfully."""
# the scenario checks for the proper count
# so if we get here the test passed
@@ -51,21 +55,35 @@
self.stop_reactor()
return obj
- def _on_alice1(dummy):
- """Callback handler for when external MWI updated mailbox alice1."""
+ def _create_subscription():
+ """Create a subscription for the MWI"""
# the two separate mailboxes should now have
# messages waiting so subscribe to them
sipp = SIPpScenario(self.test_name,
{'scenario':'subscribe.xml', '-p':'5061'})
- sipp.run(self).addCallback(_on_scenario)
+ sipp.run(self).addCallback(_on_scenario_complete)
- def _on_alice0(dummy):
- """Callback handler for when external MWI updated mailbox alice0."""
+ def _send_second_update():
+ """Send the second MWI update"""
# add a message to alice1 via external mwi
- ami.sendDeferred(_mwi_update(1)).addCallback(_on_alice1)
+ ami.sendDeferred(_mwi_update(1))
+
+ def _handle_mwi(ami, event):
+ """Callback handler for the MessageWaiting event"""
+
+ LOGGER.info("Received MWI event for %s" % event.get('mailbox'))
+
+ if event.get('mailbox') == 'alice0':
+ _send_second_update()
+ elif event.get('mailbox') == 'alice1':
+ _create_subscription()
+ else:
+ LOGGER.error("Unknown mailbox %s!" % event.get('mailbox'))
+ self.set_passed(False)
# add a message to alice0 via external mwi
- ami.sendDeferred(_mwi_update(0)).addCallback(_on_alice0)
+ ami.registerEvent('MessageWaiting', _handle_mwi)
+ ami.sendDeferred(_mwi_update(0))
def main():
"""Main entry point for test."""
More information about the asterisk-commits
mailing list