[asterisk-commits] mnicholson: testsuite/asterisk/trunk r454 - in /asterisk/trunk/tests: ./ mana...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jul 1 10:54:47 CDT 2010
Author: mnicholson
Date: Thu Jul 1 10:54:43 2010
New Revision: 454
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=454
Log:
Added manager/response-time test
Added:
asterisk/trunk/tests/manager/
asterisk/trunk/tests/manager/response-time/
asterisk/trunk/tests/manager/response-time/run-test (with props)
asterisk/trunk/tests/manager/response-time/test-config.yaml (with props)
asterisk/trunk/tests/manager/response-time/test.lua (with props)
Modified:
asterisk/trunk/tests/tests.yaml
Added: asterisk/trunk/tests/manager/response-time/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/response-time/run-test?view=auto&rev=454
==============================================================================
--- asterisk/trunk/tests/manager/response-time/run-test (added)
+++ asterisk/trunk/tests/manager/response-time/run-test Thu Jul 1 10:54:43 2010
@@ -1,0 +1,3 @@
+#!/bin/bash -e
+. lib/sh/lua.sh
+asttest -a / -s `dirname $0` $@
Propchange: asterisk/trunk/tests/manager/response-time/run-test
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/manager/response-time/run-test
------------------------------------------------------------------------------
svn:executable = *
Propchange: asterisk/trunk/tests/manager/response-time/run-test
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/manager/response-time/run-test
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/manager/response-time/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/response-time/test-config.yaml?view=auto&rev=454
==============================================================================
--- asterisk/trunk/tests/manager/response-time/test-config.yaml (added)
+++ asterisk/trunk/tests/manager/response-time/test-config.yaml Thu Jul 1 10:54:43 2010
@@ -1,0 +1,14 @@
+testinfo:
+ summary: 'Test the expected response time for manager actions.'
+ description: |
+ "This test ensures that the manager responds within a reasonable
+ ammount of time for actions."
+ issues:
+ -jira: AST-359
+
+properties:
+ minversion: '1.4'
+ dependencies:
+ - app : 'bash'
+ - app : 'asttest'
+
Propchange: asterisk/trunk/tests/manager/response-time/test-config.yaml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/manager/response-time/test-config.yaml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/manager/response-time/test-config.yaml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/manager/response-time/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/response-time/test.lua?view=auto&rev=454
==============================================================================
--- asterisk/trunk/tests/manager/response-time/test.lua (added)
+++ asterisk/trunk/tests/manager/response-time/test.lua Thu Jul 1 10:54:43 2010
@@ -1,0 +1,102 @@
+function check(msg, r, err)
+ if not r then
+ error(msg .. ": " .. tostring(err))
+ end
+ return r
+end
+
+function timed_action(m, a, r)
+ local start = posix.gettimeofday()
+ local res, err = m(a)
+ local stop = posix.gettimeofday()
+
+ if a["Action"] ~= "Logoff" and not res then
+ error(string.format("Error sending action '%s': %s", a["Action"], tostring(err)))
+ end
+
+ if r then
+ r(res, err)
+ end
+
+ -- return the total number of usecs
+ return (stop.tv_sec - start.tv_sec) * 1000000 + (stop.tv_usec - start.tv_usec)
+end
+
+function test_action(results, m, a, r)
+ for i=1,10 do
+ table.insert(results, {timed_action(m, a, r), a["Action"]})
+ end
+end
+
+function mean(results)
+ if #results == 0 then
+ return 0
+ end
+
+ local total = 0
+ for _, val in ipairs(results) do
+ total = total + val[1]
+ end
+ return total / #results
+end
+
+function print_results(results)
+ for _, val in ipairs(times) do
+ print(val[2] .. ": " .. val[1])
+ end
+end
+
+action = ast.manager.action
+
+print("starting asterisk")
+asterisk = ast.new()
+asterisk:generate_manager_conf()
+asterisk:spawn()
+
+m = check("error connecting to asterisk", asterisk:manager_connect())
+
+print("testing login")
+times = {}
+table.insert(times, {timed_action(m, action.login(), function(res, err)
+ if res["Response"] ~= "Success" then
+ error("error authenticating: " .. res["Message"])
+ end
+end), "Login"})
+
+print("testing ping")
+test_action(times, m, action.ping())
+
+print("testing logoff")
+table.insert(times, {timed_action(m, action.logoff()), "Logoff"})
+
+avg = mean(times)
+print("average time per response was " .. avg .. " usecs")
+
+-- there is a problem if the average time is greater than 5000 usecs 5000 was
+-- chosen after running this test multiple times on my system while compiling
+-- asterisk with make -j4. During this an previous runs the average time never
+-- went over 3000. During failed runs, the average time is around 35000; so
+-- 5000 should prevent any false positives while still detecting failures.
+-- Really average times should be less than 500, but system load cause them to
+-- spike.
+expected_avg = 5000
+if avg > expected_avg then
+ print("average time greater than " .. expected_avg .. " usec")
+ print("recorded time per action:")
+ print_results(times)
+ fail("manager took too long to respond; average time was " .. avg .. " usecs")
+end
+
+-- there is also a problem if any of the individual times were over 5000
+-- once again, individual times should really be less than 250 usec, but system
+-- load can cause this to spike.
+individual_time = 5000
+for _, val in ipairs(times) do
+ if val[1] > individual_time then
+ print(string.format("time for action '%s' was greater than %s usecs", val[2], individual_time))
+ print("all times:")
+ print_results(times)
+ fail(string.format("action '%s' took longer than %s usecs", val[2], individual_time))
+ end
+end
+
Propchange: asterisk/trunk/tests/manager/response-time/test.lua
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/manager/response-time/test.lua
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/manager/response-time/test.lua
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: asterisk/trunk/tests/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/tests.yaml?view=diff&rev=454&r1=453&r2=454
==============================================================================
--- asterisk/trunk/tests/tests.yaml (original)
+++ asterisk/trunk/tests/tests.yaml Thu Jul 1 10:54:43 2010
@@ -30,3 +30,4 @@
- test: 'queues/macro_gosub_test'
- test: 'queues/ringinuse_and_pause'
- test: 'queues/wrapup_time'
+ - test: 'manager/response-time'
More information about the asterisk-commits
mailing list