[asterisk-commits] tests/sorcery/memory cache populate: Add 'SorceryMemoryCache... (testsuite[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 18 05:45:06 CST 2015


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: tests/sorcery/memory_cache_populate: Add 'SorceryMemoryCachePopulate' AMI test.
......................................................................


tests/sorcery/memory_cache_populate: Add 'SorceryMemoryCachePopulate' AMI test.

This test verifies that the SorceryMemoryCachePopulate AMI action
performs as expected by retrieving a specific endpoint, deleting the
endpoint, populating the cache, and then retrieving the same endpoint.
Since the endpoint is deleted the second retrieval should fail.

ASTERISK-25625

Change-Id: I04b19fe6ccdd97c26fc1482ffe07162e575554e4
---
A tests/sorcery/memory_cache_populate/configs/ast1/extconfig.conf
A tests/sorcery/memory_cache_populate/configs/ast1/sorcery.conf
A tests/sorcery/memory_cache_populate/memory_cache_populate.py
A tests/sorcery/memory_cache_populate/test-config.yaml
M tests/sorcery/tests.yaml
5 files changed, 141 insertions(+), 0 deletions(-)

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



diff --git a/tests/sorcery/memory_cache_populate/configs/ast1/extconfig.conf b/tests/sorcery/memory_cache_populate/configs/ast1/extconfig.conf
new file mode 100644
index 0000000..adfe518
--- /dev/null
+++ b/tests/sorcery/memory_cache_populate/configs/ast1/extconfig.conf
@@ -0,0 +1,2 @@
+[settings]
+endpoints => curl,http://localhost:46821/endpoint
diff --git a/tests/sorcery/memory_cache_populate/configs/ast1/sorcery.conf b/tests/sorcery/memory_cache_populate/configs/ast1/sorcery.conf
new file mode 100644
index 0000000..d70f006
--- /dev/null
+++ b/tests/sorcery/memory_cache_populate/configs/ast1/sorcery.conf
@@ -0,0 +1,3 @@
+[res_pjsip]
+endpoint/cache=memory_cache,full_backend_cache=yes
+endpoint=realtime,endpoints
diff --git a/tests/sorcery/memory_cache_populate/memory_cache_populate.py b/tests/sorcery/memory_cache_populate/memory_cache_populate.py
new file mode 100644
index 0000000..065fc12
--- /dev/null
+++ b/tests/sorcery/memory_cache_populate/memory_cache_populate.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+
+'''
+Copyright (C) 2015, Digium, Inc.
+Joshua Colp <jcolp at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import logging
+
+LOGGER = logging.getLogger(__name__)
+ENDPOINT = 'test'
+CACHE = 'res_pjsip/endpoint'
+
+class MemoryCachePopulateTest(object):
+    def __init__(self, rt_data, test_object, ami):
+        self.rt_data = rt_data
+        self.test_object = test_object
+        self.ami = ami
+        self.endpoint_retrieved = 0
+
+    def fail_test(self):
+        self.test_object.set_passed(False)
+        self.test_object.stop_reactor()
+
+    def pass_test(self):
+        self.test_object.set_passed(True)
+        self.test_object.stop_reactor()
+
+    def retrieve_endpoint_and_fail(self):
+        def _expect_error(message):
+            if type(message) is not dict:
+                return 0
+
+            if message.get('response') != 'Error':
+                self.fail_test()
+                return 0
+
+            self.pass_test()
+
+            return 0
+
+        message = {
+            'Action': 'PJSIPShowEndpoint',
+            'Endpoint': ENDPOINT,
+        }
+        self.ami.sendMessage(message, responseCallback=_expect_error)
+
+    def retrieve_endpoint(self):
+        message = {
+            'Action': 'PJSIPShowEndpoint',
+            'Endpoint': ENDPOINT,
+        }
+        self.ami.sendMessage(message)
+
+    def populate_cache(self):
+        def _cache_populated(message):
+            self.retrieve_endpoint_and_fail()
+
+            return 0
+
+        message = {
+            'Action': 'SorceryMemoryCachePopulate',
+            'Cache': CACHE,
+        }
+        self.ami.sendMessage(message, responseCallback=_cache_populated)
+
+    def endpoint_detail_complete_callback(self, ami, event):
+        self.endpoint_retrieved += int(event.get('listitems'))
+
+        if self.endpoint_retrieved == 1:
+             self.rt_data.delete_rows('endpoint', { 'id': ENDPOINT })
+             self.retrieve_endpoint()
+        elif self.endpoint_retrieved == 2:
+             self.populate_cache()
+        elif self.endpoint_retrieved == 3:
+             self.fail_test()
+
+def check_it(rt_data, test_object, ami):
+    test = MemoryCachePopulateTest(rt_data, test_object, ami)
+
+    ami.registerEvent('EndpointDetailComplete', test.endpoint_detail_complete_callback)
+
+    test.retrieve_endpoint()
diff --git a/tests/sorcery/memory_cache_populate/test-config.yaml b/tests/sorcery/memory_cache_populate/test-config.yaml
new file mode 100644
index 0000000..6997a99
--- /dev/null
+++ b/tests/sorcery/memory_cache_populate/test-config.yaml
@@ -0,0 +1,49 @@
+testinfo:
+    summary:     'Sorcery Memory Cache AMI SorceryMemoryCachePopulate Test'
+    description: |
+        'This tests that the SorceryMemoryCachePopulate AMI action successfully clears
+         the sorcery memory cache and populates it with all objects in the backend.
+         It does this by doing the following:
+         1. PJSIP endpoints are configured with a memory cache and realtime.
+         2. A PJSIP endpoint is defined in realtime at the start of the test.
+         3. The PJSIPShowEndpoint AMI action is invoked which populates the memory cache.
+         4. The PJSIP endpoint is removed from realtime.
+         5. The SorceryMemoryCachePopulate AMI action is invoked on the memory cache.
+         6. The PJSIPShowEndpoint AMI action is invoked to confirm the endpoint
+            CAN NOT be retrieved as it should not exist in realtime or the cache.'
+
+
+properties:
+    minversion: '13.8.0'
+    dependencies:
+        - python: 'twisted'
+        - python: 'starpy'
+        - asterisk: 'res_pjsip'
+        - asterisk: 'res_config_curl'
+        - asterisk: 'func_curl'
+        - asterisk: 'res_sorcery_realtime'
+        - asterisk: 'res_sorcery_memory_cache'
+    tags:
+        - realtime
+        - pjsip
+
+test-modules:
+    add-test-to-search-path: 'True'
+    test-object:
+        config-section: test-case-config
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            config-section: 'realtime-config'
+            typename: 'realtime_test_module.RealtimeTestModule'
+
+test-case-config:
+    connect-ami: 'True'
+
+realtime-config:
+    entry_module: 'memory_cache_populate'
+    entry_method: 'check_it'
+    data:
+        endpoint:
+            -
+                id: 'test'
diff --git a/tests/sorcery/tests.yaml b/tests/sorcery/tests.yaml
index 6a44f51..0f9208e 100644
--- a/tests/sorcery/tests.yaml
+++ b/tests/sorcery/tests.yaml
@@ -3,3 +3,4 @@
     - test: 'memory_cache_expire_object'
     - test: 'memory_cache_stale'
     - test: 'memory_cache_stale_object'
+    - test: 'memory_cache_populate'

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I04b19fe6ccdd97c26fc1482ffe07162e575554e4
Gerrit-PatchSet: 2
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-commits mailing list