[Asterisk-code-review] tests/sorcery/memory cache populate: Add 'SorceryMemoryCache... (testsuite[master])
Joshua Colp
asteriskteam at digium.com
Sun Dec 13 07:16:33 CST 2015
Joshua Colp has uploaded a new change for review.
https://gerrit.asterisk.org/1809
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, 139 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/09/1809/1
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..a80757c
--- /dev/null
+++ b/tests/sorcery/memory_cache_populate/memory_cache_populate.py
@@ -0,0 +1,84 @@
+#!/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.populate_cache()
+ elif self.endpoint_retrieved == 2:
+ 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: newchange
Gerrit-Change-Id: I04b19fe6ccdd97c26fc1482ffe07162e575554e4
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
More information about the asterisk-code-review
mailing list