[Asterisk-code-review] agi: add nominal agi test (testsuite[16])
Jenkins2
asteriskteam at digium.com
Mon Aug 20 09:03:43 CDT 2018
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/9967 )
Change subject: agi: add nominal agi test
......................................................................
agi: add nominal agi test
This test proves that multiple AGI scripts
run in parallel all execute to completion.
Change-Id: Icb02e66d91e12521638698b3f5e1fd101bae92d1
---
A tests/agi/nominal/configs/ast1/extensions.conf
A tests/agi/nominal/nominal.agi
A tests/agi/nominal/run-test
A tests/agi/nominal/test-config.yaml
M tests/agi/tests.yaml
5 files changed, 131 insertions(+), 0 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
diff --git a/tests/agi/nominal/configs/ast1/extensions.conf b/tests/agi/nominal/configs/ast1/extensions.conf
new file mode 100644
index 0000000..29bcdac
--- /dev/null
+++ b/tests/agi/nominal/configs/ast1/extensions.conf
@@ -0,0 +1,8 @@
+[default]
+; ----------------------------------------------------------------------
+; Nominal AGI call flow - answer and pass control to agi
+; ----------------------------------------------------------------------
+exten => nominal,1,NoOp()
+ same => n,Answer()
+ same => n,AGI(nominal.agi)
+ same => n,Hangup()
diff --git a/tests/agi/nominal/nominal.agi b/tests/agi/nominal/nominal.agi
new file mode 100755
index 0000000..97ff948
--- /dev/null
+++ b/tests/agi/nominal/nominal.agi
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+# TODO: fully implement AGI and check results of each command
+
+echo "EXEC PLAYBACK silence/3"
+echo "EXEC UserEvent AgiCompleted"
+
+exit 0
diff --git a/tests/agi/nominal/run-test b/tests/agi/nominal/run-test
new file mode 100755
index 0000000..a78fda4
--- /dev/null
+++ b/tests/agi/nominal/run-test
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+"""
+Copyright (C) 2018, Digium, Inc.
+Scott Griepentrog <scott at griepentrog.com>
+
+This progream is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+import os
+import sys
+import logging
+
+from twisted.internet import reactor
+from shutil import copy
+
+sys.path.append("lib/python")
+from asterisk.test_case import TestCase
+
+LOGGER = logging.getLogger(__name__)
+PATH = os.path.dirname(os.path.realpath(__file__))
+TEST_CALLS = 10
+
+
+class AGITest(TestCase):
+ """
+ This is the class that contains all the methods needed to run the test.
+ """
+ def __init__(self):
+ """
+ Initialization for class.
+ call_count keeps track of all successful tests.
+ """
+ TestCase.__init__(self)
+ self.call_count = 0
+ self.reactor_timeout = TEST_CALLS + 10
+ self.create_asterisk()
+
+ def run(self):
+ """
+ Creates the AMI connection with Asterisk.
+ """
+ TestCase.run(self)
+ self.copy_files()
+ self.create_ami_factory()
+
+ def copy_files(self):
+ """Copy agi script files to the path of the current test"""
+ for filename in os.listdir(PATH):
+ if filename[-4:] == '.agi':
+ copy("%s/%s" % (PATH, filename),
+ "%s/var/lib/asterisk/agi-bin/"
+ "%s" % (self.ast[0].base, filename))
+
+ def ami_connect(self, ami):
+ """
+ Sets up the AMI for Asterisk.
+ """
+ ami.registerEvent('UserEvent', self.user_event_handler)
+ LOGGER.info("---Starting AGI nominal test---")
+
+ def originate(call):
+ ami.originate(channel="Local/nominal at default",
+ application="Echo"
+ ).addErrback(self.handle_originate_failure)
+
+ for call in range(TEST_CALLS):
+ reactor.callLater(call, originate, call)
+
+ def user_event_handler(self, result, event):
+ """
+ Checks to see if the AGI script was completed as expected.
+ """
+ if event['userevent'] != 'AgiCompleted':
+ print event['userevent']
+ return
+
+ self.call_count += 1
+ LOGGER.info("Successful AGI: %d " % self.call_count)
+ if self.call_count == TEST_CALLS:
+ self.stop_reactor()
+
+
+def main():
+ """
+ Main method, run by default, determines if test passes or fails.
+ """
+ test = AGITest()
+ reactor.run()
+ if test.call_count != TEST_CALLS:
+ LOGGER.error("The expected amount of calls did not complete. "
+ "Expected successes: %d Actual: "
+ "%d" % (TEST_CALLS, test.call_count))
+ return 1
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main() or 0)
diff --git a/tests/agi/nominal/test-config.yaml b/tests/agi/nominal/test-config.yaml
new file mode 100644
index 0000000..c476227
--- /dev/null
+++ b/tests/agi/nominal/test-config.yaml
@@ -0,0 +1,16 @@
+testinfo:
+ summary: 'Test AGI with multiple calls in parallel'
+ description: |
+ 'This test checks to make certain that multiple overlapping AGIs are executed'
+
+properties:
+ dependencies:
+ - python : 'twisted'
+ - python : 'starpy'
+ - asterisk : 'app_userevent'
+ - asterisk : 'func_cdr'
+ - asterisk : 'func_logic'
+ - asterisk : 'pbx_config'
+ - asterisk : 'res_agi'
+ tags:
+ - AGI
diff --git a/tests/agi/tests.yaml b/tests/agi/tests.yaml
index 9dc2985..7f831ed 100644
--- a/tests/agi/tests.yaml
+++ b/tests/agi/tests.yaml
@@ -1,3 +1,4 @@
# Enter tests here in the order they should be considered for execution:
tests:
- test: 'exit_status'
+ - test: 'nominal'
--
To view, visit https://gerrit.asterisk.org/9967
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: 16
Gerrit-MessageType: merged
Gerrit-Change-Id: Icb02e66d91e12521638698b3f5e1fd101bae92d1
Gerrit-Change-Number: 9967
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Scott Griepentrog <scott at griepentrog.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180820/6f779e4f/attachment-0001.html>
More information about the asterisk-code-review
mailing list