[asterisk-commits] tests/channels/pjsip/subscriptions/ast restart: Fix race con... (testsuite[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 15 16:11:46 CDT 2017


Anonymous Coward #1000019 has submitted this change and it was merged. ( https://gerrit.asterisk.org/5153 )

Change subject: tests/channels/pjsip/subscriptions/ast_restart: Fix race condition.
......................................................................


tests/channels/pjsip/subscriptions/ast_restart: Fix race condition.

The test is failing on fast machines because they restart and fully boot
before the testsuite reconnects the AMI connection.  As a result the
expected second SUBSCRIPTION_ESTABLISHED event is never seen.

* Instead of ping-ponging back and forth between Asterisk and the SIPp
scenario, change the test to be more SIPp scenario driven.

* Enable PJSIP message debugging in the config file to ensure that logging
messages are enabled early enough to see the subscription recreation
NOTIFY message on fast machines.

Change-Id: Ie79c5ca9954287c1dda42a24305ccc8bdd0a6e07
---
M tests/channels/pjsip/subscriptions/ast_restart/configs/ast1/pjsip.conf
M tests/channels/pjsip/subscriptions/ast_restart/sipp/subscribe.xml
M tests/channels/pjsip/subscriptions/ast_restart/test-config.yaml
3 files changed, 35 insertions(+), 95 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/tests/channels/pjsip/subscriptions/ast_restart/configs/ast1/pjsip.conf b/tests/channels/pjsip/subscriptions/ast_restart/configs/ast1/pjsip.conf
index 148bbf6..ead6d27 100644
--- a/tests/channels/pjsip/subscriptions/ast_restart/configs/ast1/pjsip.conf
+++ b/tests/channels/pjsip/subscriptions/ast_restart/configs/ast1/pjsip.conf
@@ -1,3 +1,11 @@
+[global]
+type=global
+
+; Enable debugging so we can see the SIP messages right after a restart.
+; The SIPp test case module will turn it on but it may be too late for
+; the subscription recreation to be seen after the restart.
+debug=yes
+
 [local]
 type=transport
 protocol=udp
diff --git a/tests/channels/pjsip/subscriptions/ast_restart/sipp/subscribe.xml b/tests/channels/pjsip/subscriptions/ast_restart/sipp/subscribe.xml
index e87351a..1ed154d 100644
--- a/tests/channels/pjsip/subscriptions/ast_restart/sipp/subscribe.xml
+++ b/tests/channels/pjsip/subscriptions/ast_restart/sipp/subscribe.xml
@@ -63,22 +63,8 @@
 		]]>
 	</send>
 
-	<!-- NOTIFY for AMI reconnecting and then changing the device state  -->
-	<recv request="NOTIFY" crlf="true">
-	</recv>
-
-	<send>
-		<![CDATA[
-			SIP/2.0 200 OK
-			[last_Via:]
-			[last_From:]
-			[last_To:]
-			[last_Call-ID:]
-			[last_CSeq:]
-			Contact: <sip:[local_ip]:[local_port];transport=[transport]>
-			Content-Length: 0
-		]]>
-	</send>
+	<!-- Wait for the testsuite to reconnect AMI to catch the subscription refresh -->
+	<pause milliseconds="5000" />
 
 	<!-- Refresh subscription  -->
 	<send retrans="500">
@@ -106,23 +92,6 @@
 		<action>
 			<ereg regexp="active;expires=[5,6][0,9][0,5-9]" check_it="true" search_in="hdr" header="Subscription-State" assign_to="resubstate" />
 		</action>
-	</recv>
-
-	<send>
-		<![CDATA[
-			SIP/2.0 200 OK
-			[last_Via:]
-			[last_From:]
-			[last_To:]
-			[last_Call-ID:]
-			[last_CSeq:]
-			Contact: <sip:[local_ip]:[local_port];transport=[transport]>
-			Content-Length: 0
-		]]>
-	</send>
-
-	<!-- NOTIFY for AMI changing the device state again  -->
-	<recv request="NOTIFY" crlf="true">
 	</recv>
 
 	<send>
@@ -179,6 +148,9 @@
 		]]>
 	</send>
 
+	<!-- Wait for the testsuite to process the Unsubscribe -->
+	<pause milliseconds="2000" />
+
 	<Reference variables="substate,resubstate,unsubstate" />
 
 </scenario>
diff --git a/tests/channels/pjsip/subscriptions/ast_restart/test-config.yaml b/tests/channels/pjsip/subscriptions/ast_restart/test-config.yaml
index 80470ed..63a2e3f 100644
--- a/tests/channels/pjsip/subscriptions/ast_restart/test-config.yaml
+++ b/tests/channels/pjsip/subscriptions/ast_restart/test-config.yaml
@@ -2,18 +2,14 @@
     summary: 'Test subscription persistence over Asterisk restarts'
     description: |
         Tests that subscriptions survive an Asterisk restart.
-        The test ping-pongs between the SIPp scenario and Asterisk
-        by waiting for the other to signal completion of key events.
-        1) A SIPp scenario requests a subscription.
+        1) The SIPp scenario requests a subscription.
         2) Asterisk is restarted when the subscription gets established.
-        3) Asterisk changes the extension custom device state after the
-        restart recreates the subscription.
-        4) The SIPp scenario refreshes the subscription.
-        5) Asterisk changes the extension custom device state again after
-        the subscription is refreshed.
-        6) The SIPp scenario unsubscribes to complete the scenario.
-        7) The test completes successfully when Asterisk sees the
-        subscription get terminated.
+        3) The SIPp scenario sees the recreated subscription NOTIFY and
+        waits five seconds for the testsuite to reconnect the AMI connection.
+        4) The SIPp scenario then refreshes the subscription.
+        5) The SIPp scenario then unsubscribes and waits two seconds
+        for the testsuite to process the event before completing the
+        scenario.
 
 properties:
     minversion: [ '13.14.0', '14.3.0' ]
@@ -23,7 +19,6 @@
         - python : 'starpy'
         - sipp :
             version : 'v3.0'
-        - asterisk : 'func_devstate'
         - asterisk : 'res_pjsip'
         - asterisk : 'res_pjsip_pubsub'
     tags:
@@ -39,7 +34,7 @@
             typename: 'pluggable_modules.EventActionModule'
 
 sipp-config:
-    stop-after-scenarios: False
+    stop-after-scenarios: True
     fail-on-any: True
 
     # Indicate that the test is going to be restarting Asterisk so
@@ -57,8 +52,10 @@
 
 ami-config:
     -
-        # Event generated on initial subscription creation
-        # and on subscription recreation after a restart.
+        # Event generated on initial subscription creation.
+        # Event also generated on subscription recreation after
+        # a restart but we may not see it depending on timing
+        # or the speed of the machine.
         ami-events:
             conditions:
                 match:
@@ -77,31 +74,19 @@
                 Command: 'core restart gracefully'
     -
         # Wake up after Asterisk is fully booted again.
-        # This tends to be too early for the restart NOTIFY to have
-        # a chance to go out.  Recreating persistent subscriptions
-        # has to wait for Asterisk to be fully booted to ensure that
-        # all pjsip modules are loaded and ready.
+        #
+        # Depending upon timing or the speed of the machine
+        # this event is either too early or too late to get
+        # Asterisk and the SIPp scenario resynchronized after
+        # recreating the persistent subscriptions.  AMI either
+        # reconnects before Asterisk is fully booted and thus
+        # the persistent subscriptions haven't been recreated yet.
+        # Or AMI reconnects well after Asterisk has fully booted
+        # and the persistent subscriptions are already recreated.
+        #
         # We'll just require that we get restarted once.
         ami-restart:
             count: '1'
-    -
-        ami-events:
-            conditions:
-                match:
-                    Event: 'TestEvent'
-                    State: 'SUBSCRIPTION_ESTABLISHED'
-            requirements:
-                match:
-                    Resource: 'alice'
-            # Trigger on the second event
-            count: '2'
-            trigger-on-count: True
-        ami-actions:
-            action:
-                Action: 'SetVar'
-                ActionID: '23456'
-                Variable: 'DEVICE_STATE(Custom:hitchcock)'
-                Value: 'BUSY'
     -
         ami-events:
             conditions:
@@ -112,30 +97,6 @@
                 match:
                     Resource: 'alice'
             count: '1'
-            trigger-on-count: True
-        ami-actions:
-            # Changing the custom device state again so we can re-run
-            # the test without a previous run possibly interfering.
-            # This is basically paranoia because I think the AstDB is
-            # deleted between tests.  However, refreshing the subscription
-            # further tests that the subscription dialog is fully
-            # recreated after the restart.
-            action:
-                Action: 'SetVar'
-                ActionID: '34567'
-                Variable: 'DEVICE_STATE(Custom:hitchcock)'
-                Value: 'NOT_INUSE'
-    -
-        ami-events:
-            conditions:
-                match:
-                    Event: 'TestEvent'
-                    State: 'SUBSCRIPTION_STATE_CHANGED'
-            requirements:
-                match:
-                    Resource: 'alice'
-            # Changed the custom device state twice.
-            count: '2'
     -
         ami-events:
             conditions:
@@ -146,4 +107,3 @@
                 match:
                     Resource: 'alice'
             count: '1'
-        stop_test:

-- 
To view, visit https://gerrit.asterisk.org/5153
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie79c5ca9954287c1dda42a24305ccc8bdd0a6e07
Gerrit-PatchSet: 2
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-commits mailing list