[Asterisk-code-review] pjsip: Add test for evsub leaks (testsuite[18])

Michael Bradeen asteriskteam at digium.com
Thu Apr 13 13:08:25 CDT 2023


Michael Bradeen has uploaded this change for review. ( https://gerrit.asterisk.org/c/testsuite/+/20083 )


Change subject: pjsip: Add test for evsub leaks
......................................................................

pjsip: Add test for evsub leaks

Add a test that creates and terminates an evsub in the
three possible ways:

- unsubscribe with expires = 0
- allow subscription to timeout on the server side
- send a 5xx response to the initial notify

After each termination, call PJSIPShowSubscriptionsInbound
and if any InboundSubscriptionDetail events are generated,
the test fails.

ASTERISK-30469

Change-Id: Ia4b7ed52649fa102be0af7145036abfea5dd3c4b
---
A tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/configs/ast1/pjsip.conf
A tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_server_timeout.xml
A tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_sub_unsub.xml
A tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_term.xml
A tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/test-config.yaml
M tests/channels/pjsip/subscriptions/mwi/tests.yaml
6 files changed, 324 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/83/20083/1

diff --git a/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/configs/ast1/pjsip.conf b/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/configs/ast1/pjsip.conf
new file mode 100644
index 0000000..ca0dbb7
--- /dev/null
+++ b/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/configs/ast1/pjsip.conf
@@ -0,0 +1,21 @@
+[global]
+type=global
+debug=yes
+
+[local-transport]
+type=transport
+bind=127.0.0.1
+protocol=udp
+
+[alice]
+type=endpoint
+transport=local-transport
+allow=g722,ulaw,alaw
+context=default
+aors=alice
+
+[alice]
+type=aor
+contact=sip:alice at 127.0.0.1:5061
+max_contacts=1
+mailboxes=alice
diff --git a/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_server_timeout.xml b/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_server_timeout.xml
new file mode 100644
index 0000000..c177dad
--- /dev/null
+++ b/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_server_timeout.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="Subscribe">
+  <!-- Subscribe -->
+  <send retrans="500">
+    <![CDATA[
+      SUBSCRIBE sip:alice@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: "alice" <sip:alice@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
+      To: "alice" <sip:alice@[remote_ip]:[remote_port]>
+      Call-ID: [call_id]
+      CSeq: 1 SUBSCRIBE
+      Contact: "alice" <sip:alice@[local_ip]:[local_port]>
+      Max-Forwards: 70
+      Event: message-summary
+      Expires: 10
+      Accept: application/simple-message-summary
+      Allow-Events: message-summary
+      User-Agent: SIPp
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <recv response="200" rtd="true">
+  </recv>
+
+  <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>
+
+  <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>
+
+</scenario>
diff --git a/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_sub_unsub.xml b/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_sub_unsub.xml
new file mode 100644
index 0000000..ca2f533
--- /dev/null
+++ b/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_sub_unsub.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="Subscribe">
+  <!-- Subscribe -->
+  <send retrans="500">
+    <![CDATA[
+      SUBSCRIBE sip:alice@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: "alice" <sip:alice@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
+      To: "alice" <sip:alice@[remote_ip]:[remote_port]>
+      Call-ID: [call_id]
+      CSeq: 1 SUBSCRIBE
+      Contact: "alice" <sip:alice@[local_ip]:[local_port]>
+      Max-Forwards: 70
+      Event: message-summary
+      Expires: 300
+      Accept: application/simple-message-summary
+      Allow-Events: message-summary
+      User-Agent: SIPp
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <recv response="200" rtd="true">
+    <action>
+          <ereg regexp="(;tag=.*)" header="To:" search_in="hdr" check_it="true" assign_to="to_tag"/>
+    </action>
+  </recv>
+
+  <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>
+
+  <pause milliseconds="1000"/>
+
+  <!-- Unsubscribe -->
+  <send retrans="500">
+    <![CDATA[
+      SUBSCRIBE sip:alice@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: "alice" <sip:alice@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
+      To: "alice" <sip:alice@[remote_ip]:[remote_port]>[$to_tag]
+      Call-ID: [call_id]
+      CSeq: 3 SUBSCRIBE
+      Contact: "alice" <sip:alice@[local_ip]:[local_port]>
+      Max-Forwards: 70
+      Event: message-summary
+      Expires: 0
+      Accept: application/simple-message-summary
+      Allow-Events: message-summary
+      User-Agent: SIPp
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <recv response="200" rtd="true" />
+
+  <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>
+
+</scenario>
diff --git a/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_term.xml b/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_term.xml
new file mode 100644
index 0000000..4e2982a
--- /dev/null
+++ b/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/sipp/mwi_subscription_term.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="Subscribe">
+  <!-- Subscribe -->
+  <send retrans="500">
+    <![CDATA[
+      SUBSCRIBE sip:alice@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: "alice" <sip:alice@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
+      To: "alice" <sip:alice@[remote_ip]:[remote_port]>
+      Call-ID: [call_id]
+      CSeq: 1 SUBSCRIBE
+      Contact: "alice" <sip:alice@[local_ip]:[local_port]>
+      Max-Forwards: 70
+      Event: message-summary
+      Expires: 10
+      Accept: application/simple-message-summary
+      Allow-Events: message-summary
+      User-Agent: SIPp
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <recv response="200" rtd="true">
+  </recv>
+
+  <recv request="NOTIFY" crlf="true">
+  </recv>
+
+  <send>
+    <![CDATA[
+
+      SIP/2.0 500 Server Error
+      [last_Via:]
+      [last_From:]
+      [last_To:]
+      [last_Call-ID:]
+      [last_CSeq:]
+      Contact: <sip:[local_ip]:[local_port];transport=[transport]>
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+</scenario>
diff --git a/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/test-config.yaml b/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/test-config.yaml
new file mode 100644
index 0000000..0ac2655
--- /dev/null
+++ b/tests/channels/pjsip/subscriptions/mwi/sub_term_leakcheck/test-config.yaml
@@ -0,0 +1,75 @@
+testinfo:
+    summary:     'Test MWI that subscriptions are cleaned upon termination.'
+    description: |
+        'This creates an MWI subscribtion, then lets the subscription terminate in the following 3 ways:
+         1 - unsubscribe with expires = 0
+         2 - allow subscription to timeout on the server side
+         3 - send a 5xx response to the initial notify
+
+         In all three cases we test to make sure that there are no active subscriptions
+         at the end.  If we receive any InboundSubscriptionDetail events, the test fails.'
+
+properties:
+    dependencies:
+        - python: 'twisted'
+        - python: 'starpy'
+        - asterisk: 'res_pjsip'
+        - sipp:
+            version: 'v3.0'
+    tags:
+        - pjsip
+
+test-modules:
+    add-test-to-search-path: 'True'
+    test-object:
+        config-section: sipp-config
+        typename: 'sipp_iterator.SIPpIteratorTestCase'
+    modules:
+        -
+            config-section: 'ami-config'
+            typename: 'pluggable_modules.EventActionModule'
+
+sipp-config:
+    connect-ami: 'True'
+    reactor-timeout: 30
+    type: 'single'
+    scenarios:
+        # Alice subscribes and unsubscribes
+        - { 'scenario': {'Name': 'mwi_subscription_sub_unsub.xml', 'port': '5061', 'target': '127.0.0.1'},
+            'action': {'Action': 'none'}}
+        # Make sure the susbscription is cleaned
+        - { 'scenario': {'Name': 'none'},
+            'action': {'Action': 'PJSIPShowSubscriptionsInbound'}}
+        # Alice subscribes then waits for the server to timeout the subscription
+        - { 'scenario': {'Name': 'mwi_subscription_server_timeout.xml', 'port': '5061', 'target': '127.0.0.1'},
+            'action': {'Action': 'none'}}
+        # Make sure the susbscription is cleaned
+        - { 'scenario': {'Name': 'none'},
+            'action': {'Action': 'PJSIPShowSubscriptionsInbound'}}
+        # Alice subscribes and then sends a 5xx in response to the NOTIFY
+        - { 'scenario': {'Name': 'mwi_subscription_term.xml', 'port': '5061', 'target': '127.0.0.1'},
+            'action': {'Action': 'none'}}
+        # Make sure the susbscription is cleaned
+        - { 'scenario': {'Name': 'none'},
+            'action': {'Action': 'PJSIPShowSubscriptionsInbound'}}
+        # indicate no more scenarios to run, send testComplete Event
+        - { 'scenario': {'Name': 'done'},
+            'action': {'Action': 'UserEvent', 'UserEvent': 'testComplete'}}
+
+ami-config:
+    -
+        ami-events:
+            conditions:
+                match:
+                    Event: 'InboundSubscriptionDetail'
+            count: 0
+        stop_test:
+    -
+        ami-events:
+            conditions:
+                match:
+                    Event: 'UserEvent'
+                    UserEvent: 'testComplete'
+            count: 1
+        stop_test:
+
diff --git a/tests/channels/pjsip/subscriptions/mwi/tests.yaml b/tests/channels/pjsip/subscriptions/mwi/tests.yaml
index 3636508..753aab9 100644
--- a/tests/channels/pjsip/subscriptions/mwi/tests.yaml
+++ b/tests/channels/pjsip/subscriptions/mwi/tests.yaml
@@ -9,3 +9,4 @@
     - test: 'no_accept_header'
     - test: 'sub_setup_teardown'
     - test: 'sub_setup_teardown_drop_options'
+    - test: 'sub_term_leakcheck'

-- 
To view, visit https://gerrit.asterisk.org/c/testsuite/+/20083
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: 18
Gerrit-Change-Id: Ia4b7ed52649fa102be0af7145036abfea5dd3c4b
Gerrit-Change-Number: 20083
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230413/a099ebe6/attachment-0001.html>


More information about the asterisk-code-review mailing list