[asterisk-commits] single resource multiple changes: Refactor to remove custom... (testsuite[master])
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Aug 24 09:52:11 CDT 2017
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/6283 )
Change subject: single_resource_multiple_changes: Refactor to remove custom python
......................................................................
single_resource_multiple_changes: Refactor to remove custom python
This test (and many other rls tests) had a custom python thing
that proxied the sip stream between the test and asterisk and
resulted in 3 state machines running at the same time. All for
the sole purpose of testing that when rls notifies are batched,
the test only gets the last notify. It was unstable in high
stress environments.
Replaced with a few extra lines of xml in the scenario file and
4 new ami-event/ami-action pairs in yaml.
Change-Id: Ibfb23af16898cd0780f46deca03abb2815c71c96
---
D tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/driver.py
M tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/sipp/subscribe.xml
M tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/test-config.yaml
3 files changed, 91 insertions(+), 192 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Jenkins2: Approved for Submit
diff --git a/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/driver.py b/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/driver.py
deleted file mode 100755
index af021e7..0000000
--- a/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/driver.py
+++ /dev/null
@@ -1,159 +0,0 @@
-#!/usr/bin/env python
-
-import time
-import logging
-
-LOGGER = logging.getLogger(__name__)
-
-# These are the states that are moved through during the tests. They are listed
-# here in the order that they occur throughout the test.
-
-# Initial state before subscription establishment.
-UNESTABLISHED = 1
-
-# This state is entered after initial SUBSCRIBE-NOTIFY exchange has occurred.
-ESTABLISHED = 2
-
-# This state is entered after Alice's device state is changed to INUSE.
-ALICE_STATE_INUSE = 3
-
-# This state is entered after the NOTIFY changing Alice's device state to
-# NOT_INUSE is received.
-ALICE_STATE_NOT_INUSE = 4
-
-# This state is entered after the SUBSCRIBE-NOTIFY exchange for subscription
-# refresh has occurred.
-REFRESHED = 5
-
-# This state is entered after Bob's device state is changed to INUSE.
-BOB_STATE_INUSE = 6
-
-# This state is entered after the NOTIFY changing Bob's device state to
-# NOT_INUSE is received.
-BOB_STATE_NOT_INUSE = 7
-
-# This state is entered after SUBSCRIBE-NOTIFY exchange to terminate
-# subscription has occurred.
-TERMINATED = 8
-
-
-class TestDriver(object):
- def __init__(self, module_config, test_object):
- self.ami = None
- self.state = UNESTABLISHED
- self.test_object = test_object
- self.alice_time = 0.0
- self.bob_time = 0.0
- test_object.register_ami_observer(self.ami_connect)
-
- def fail_test(self):
- self.test_object.set_passed(False)
- self.test_object.stop_reactor()
-
- def ami_connect(self, ami):
- self.ami = ami
- self.ami.registerEvent('TestEvent', self.on_test_event)
- self.ami.registerEvent('DeviceStateChange', self.on_devstate_change)
-
- def on_devstate_change(self, ami, event):
- if self.state == ESTABLISHED:
- self.state = ALICE_STATE_INUSE
- LOGGER.debug("State change to {0}".format(ALICE_STATE_INUSE))
- message = {
- 'Action': 'SetVar',
- 'Variable': 'DEVICE_STATE(Custom:alice)',
- 'Value': 'NOT_INUSE'
- }
- self.ami.sendMessage(message)
- elif self.state == REFRESHED:
- self.state = BOB_STATE_INUSE
- LOGGER.debug("State change to {0}".format(BOB_STATE_INUSE))
- message = {
- 'Action': 'SetVar',
- 'Variable': 'DEVICE_STATE(Custom:bob)',
- 'Value': 'NOT_INUSE'
- }
- self.ami.sendMessage(message)
- elif (self.state == ALICE_STATE_INUSE or
- self.state == BOB_STATE_INUSE):
- return
- else:
- LOGGER.error("Unexpected state change ... it's complex")
- self.fail_test()
-
- def on_test_event(self, ami, event):
- state = event['state']
- if state == 'SUBSCRIPTION_ESTABLISHED':
- self.on_subscription_established()
- elif state == 'SUBSCRIPTION_REFRESHED':
- self.on_subscription_refreshed()
- elif state == 'SUBSCRIPTION_TERMINATED':
- self.on_subscription_terminated()
- elif state == 'SUBSCRIPTION_STATE_CHANGED':
- self.on_subscription_state_change()
-
- def on_subscription_established(self):
- if self.state != UNESTABLISHED:
- LOGGER.error("Unexpected state change from {0}. Expected state "
- "{1}".format(self.state, UNESTABLISHED))
- self.fail_test()
-
- LOGGER.debug("State change to {0}".format(ESTABLISHED))
- self.state = ESTABLISHED
- self.alice_time = time.time()
- message = {
- 'Action': 'SetVar',
- 'Variable': 'DEVICE_STATE(Custom:alice)',
- 'Value': 'InUse'
- }
- self.ami.sendMessage(message)
-
- def on_subscription_state_change(self):
- if self.state != ALICE_STATE_INUSE and self.state != BOB_STATE_INUSE:
- LOGGER.error("Unexpected state change from {0}. Expected state "
- "{1} or {2}".format(self.state, ESTABLISHED,
- REFRESHED))
- self.fail_test()
-
- if self.state == ALICE_STATE_INUSE:
- interval = time.time() - self.alice_time
- if interval < 5.0:
- LOGGER.error("Interval {0} too brief".format(interval))
- self.fail_test()
- LOGGER.debug("State change to {0}".format(ALICE_STATE_NOT_INUSE))
- self.state = ALICE_STATE_NOT_INUSE
- if self.state == BOB_STATE_INUSE:
- interval = time.time() - self.bob_time
- if time.time() - self.bob_time < 5.0:
- LOGGER.error("Interval {0} too brief".format(interval))
- self.fail_test()
- LOGGER.debug("State change to {0}".format(BOB_STATE_NOT_INUSE))
- self.state = BOB_STATE_NOT_INUSE
-
- def on_subscription_refreshed(self):
- if self.state != ALICE_STATE_NOT_INUSE:
- LOGGER.error("Unexpected state change from {0}. Expected state "
- "{1}".format(self.state, ALICE_STATE_NOT_INUSE))
- self.fail_test()
-
- LOGGER.debug("State change to {0}".format(REFRESHED))
- self.state = REFRESHED
- self.bob_time = time.time()
- message = {
- 'Action': 'SetVar',
- 'Variable': 'DEVICE_STATE(Custom:bob)',
- 'Value': 'InUse'
- }
- self.ami.sendMessage(message)
-
- def on_subscription_terminated(self):
- if self.state != BOB_STATE_NOT_INUSE:
- LOGGER.error("Unexpected state change from {0}. Expected state "
- "{1}".format(self.state, BOB_STATE_NOT_INUSE))
- self.fail_test()
-
- LOGGER.debug("State change to {0}".format(TERMINATED))
- self.state = TERMINATED
- # If we've made it here, then the test has passed!
- self.test_object.set_passed(True)
- self.test_object.stop_reactor()
diff --git a/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/sipp/subscribe.xml b/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/sipp/subscribe.xml
index 2eac2a0..e640ebd 100644
--- a/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/sipp/subscribe.xml
+++ b/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/sipp/subscribe.xml
@@ -35,10 +35,14 @@
</action>
</recv>
- <!-- Initial NOTIFY upon subscribing -->
+ <!-- Initial NOTIFY upon subscribing. Should have both alice and bob -->
<recv request="NOTIFY" crlf="true">
<action>
<ereg regexp="eventlist" search_in="hdr" header="Require:" check_it="true" assign_to="1" />
+
+ <ereg regexp="<name>pres_list</name>.+<resource uri=\"sip:alice at 127.0.0.1:5060\">.+<resource uri=\"sip:bob at 127.0.0.1:5060\">"
+ search_in="body" check_it="true" assign_to="1" />
+
</action>
</recv>
@@ -57,10 +61,14 @@
]]>
</send>
- <!-- NOTIFY upon changing Alice's state -->
+ <!-- NOTIFY upon changing Alice's state to inuse and back again.
+ With batching, should have only alice not inuse. -->
<recv request="NOTIFY" crlf="true">
<action>
<ereg regexp="eventlist" search_in="hdr" header="Require:" check_it="true" assign_to="1" />
+
+ <ereg regexp="<presence entity=\"sip:alice at 127.0.0.1:5060\"[^>]+>[^<]*<note>Ready</note>[^<]*<tuple id=\"alice\">[^<]*<status>[^<]*<basic>open</basic>[^<]*</status>"
+ search_in="body" check_it="true" assign_to="1" />
</action>
</recv>
@@ -134,10 +142,14 @@
]]>
</send>
- <!--- NOTIFY upon changing Bob's state -->
+ <!-- NOTIFY upon changing Bob's state to inuse and back again.
+ With batching, should have only bob not inuse. -->
<recv request="NOTIFY" crlf="true">
<action>
<ereg regexp="eventlist" search_in="hdr" header="Require:" check_it="true" assign_to="1" />
+
+ <ereg regexp="<presence entity=\"sip:bob at 127.0.0.1:5060\"[^>]+>[^<]*<note>Ready</note>[^<]*<tuple id=\"bob\">[^<]*<status>[^<]*<basic>open</basic>[^<]*</status>"
+ search_in="body" check_it="true" assign_to="1" />
</action>
</recv>
diff --git a/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/test-config.yaml b/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/test-config.yaml
index bd9bc51..a1b6573 100644
--- a/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/test-config.yaml
+++ b/tests/channels/pjsip/subscriptions/rls/lists/nominal/presence/batched/single_resource_multiple_changes/test-config.yaml
@@ -13,7 +13,6 @@
- buildoption: 'TEST_FRAMEWORK'
- python: 'twisted'
- python: 'starpy'
- - python: 'lxml'
- asterisk: 'res_pjsip'
- asterisk: 'res_pjsip_pubsub'
tags:
@@ -21,43 +20,90 @@
- pjsip
test-modules:
- add-test-to-search-path: 'True'
- add-to-search-path:
- -
- 'tests/channels/pjsip/subscriptions/rls'
test-object:
config-section: 'test-case-config'
typename: 'sipp.SIPpTestCase'
modules:
-
- config-section: 'test-config'
- typename: 'rls_test.RLSTest'
- -
- typename: 'driver.TestDriver'
+ config-section: 'ami-config'
+ typename: 'pluggable_modules.EventActionModule'
test-case-config:
- stop-after-scenarios: False
+ reactor-timeout: 15
+ stop-after-scenarios: True
test-iterations:
-
scenarios:
- - { 'target': '127.0.0.1:5061', 'key-args': {'scenario': 'subscribe.xml', '-i': '127.0.0.1', '-p': '5062', '-s': 'pres_list'} }
+ - { 'target': '127.0.0.1:5060', 'key-args': {'scenario': 'subscribe.xml', '-i': '127.0.0.1', '-p': '5062', '-s': 'pres_list'} }
-test-config:
- stop-test-after-notifys: False
- list-name: 'pres_list'
- packets:
- -
- full-state: True
- resources: { 'alice': {'type': 'PIDF', 'state': 'active'}, 'bob': {'type': 'PIDF', 'state': 'active'}}
- -
- full-state: False
- resources: { 'alice': {'type': 'PIDF', 'state': 'active' } }
- -
- full-state: True
- resources: { 'alice': {'type': 'PIDF', 'state': 'active'}, 'bob': {'type': 'PIDF', 'state': 'active'}}
- -
- full-state: False
- resources: { 'bob': {'type': 'PIDF', 'state': 'active' } }
- -
- full-state: True
- resources: { 'alice': {'type': 'PIDF', 'state': 'terminated'}, 'bob': {'type': 'PIDF', 'state': 'terminated'}}
+ami-config:
+ -
+ ami-events:
+ conditions:
+ match:
+ Event: 'TestEvent'
+ State: 'SUBSCRIPTION_ESTABLISHED'
+ Resource: 'pres_list'
+ count: '1'
+ ami-actions:
+ action:
+ Action: 'SetVar'
+ Variable: 'DEVICE_STATE(Custom:alice)'
+ Value: 'InUse'
+ -
+ ami-events:
+ conditions:
+ match:
+ Event: 'DeviceStateChange'
+ Device: 'Custom:alice'
+ State: 'INUSE'
+ count: '1'
+ ami-actions:
+ action:
+ Action: 'SetVar'
+ Variable: 'DEVICE_STATE(Custom:alice)'
+ Value: 'NOT_INUSE'
+ -
+ ami-events:
+ conditions:
+ match:
+ Event: 'DeviceStateChange'
+ Device: 'Custom:alice'
+ State: 'NOT_INUSE'
+ count: '1'
+ -
+ ami-events:
+ conditions:
+ match:
+ Event: 'TestEvent'
+ State: 'SUBSCRIPTION_REFRESHED'
+ requirements:
+ match:
+ Resource: 'pres_list'
+ count: '1'
+ ami-actions:
+ action:
+ Action: 'SetVar'
+ Variable: 'DEVICE_STATE(Custom:bob)'
+ Value: 'InUse'
+ -
+ ami-events:
+ conditions:
+ match:
+ Event: 'DeviceStateChange'
+ Device: 'Custom:bob'
+ State: 'INUSE'
+ count: '1'
+ ami-actions:
+ action:
+ Action: 'SetVar'
+ Variable: 'DEVICE_STATE(Custom:bob)'
+ Value: 'NOT_INUSE'
+ -
+ ami-events:
+ conditions:
+ match:
+ Event: 'DeviceStateChange'
+ Device: 'Custom:bob'
+ State: 'NOT_INUSE'
+ count: '1'
--
To view, visit https://gerrit.asterisk.org/6283
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibfb23af16898cd0780f46deca03abb2815c71c96
Gerrit-Change-Number: 6283
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-commits/attachments/20170824/95d3a692/attachment-0001.html>
More information about the asterisk-commits
mailing list