[asterisk-commits] mmichelson: branch mmichelson/srv_sip_outbound r201 - in /asterisk/team/mmich...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 5 15:22:45 CDT 2010


Author: mmichelson
Date: Mon Apr  5 15:22:44 2010
New Revision: 201

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=201
Log:
Finalize func_srv test

Now it's on to the SIP outbound portion.


Modified:
    asterisk/team/mmichelson/srv_sip_outbound/tests/func_srv/configs/extensions.conf
    asterisk/team/mmichelson/srv_sip_outbound/tests/func_srv/test.lua

Modified: asterisk/team/mmichelson/srv_sip_outbound/tests/func_srv/configs/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/srv_sip_outbound/tests/func_srv/configs/extensions.conf?view=diff&rev=201&r1=200&r2=201
==============================================================================
--- asterisk/team/mmichelson/srv_sip_outbound/tests/func_srv/configs/extensions.conf (original)
+++ asterisk/team/mmichelson/srv_sip_outbound/tests/func_srv/configs/extensions.conf Mon Apr  5 15:22:44 2010
@@ -6,9 +6,6 @@
 exten => test,n,NoOp(Got ${SRVRESULT(${ID},getnum)} results)
 exten => test,n,Set(i=0)
 exten => test,n,While($[${i} < ${SRVRESULT(${ID},getnum)}])
-exten => test,n,NoOp(Host is ${SRVRESULT(${ID},${i},host)})
-exten => test,n,NoOp(Port is ${SRVRESULT(${ID},${i},port)})
-exten => test,n,NoOp(Priority is ${SRVRESULT(${ID},${i},priority)})
-exten => test,n,NoOp(Weight is ${SRVRESULT(${ID},${i},weight)})
+exten => test,n,UserEvent(SRV,RecordNum: ${i},Host: ${SRVRESULT(${ID},${i},host)},Port: ${SRVRESULT(${ID},${i},port)},Priority: ${SRVRESULT(${ID},${i},priority)},Weight: ${SRVRESULT(${ID},${i},weight)})
 exten => test,n,Set(i=$[${i} + 1])
-exten => test,1,
+exten => test,n,EndWhile

Modified: asterisk/team/mmichelson/srv_sip_outbound/tests/func_srv/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/srv_sip_outbound/tests/func_srv/test.lua?view=diff&rev=201&r1=200&r2=201
==============================================================================
--- asterisk/team/mmichelson/srv_sip_outbound/tests/func_srv/test.lua (original)
+++ asterisk/team/mmichelson/srv_sip_outbound/tests/func_srv/test.lua Mon Apr  5 15:22:44 2010
@@ -12,24 +12,82 @@
 end
 
 function srv_record.__eq(rec1, rec2)
+	-- Helpful for debugging
+	--print ("Going to compare the following:")
+	--print ("Host 1: " .. rec1.host .. " Host 2: " .. rec2.host)
+	--print ("Port 1: " .. rec1.port .. " Port 2: " .. rec2.port)
+	--print ("priority 1: " .. rec1.priority .. " priority 2: " .. rec2.priority)
+	--print ("weight 1: " .. rec1.weight .. " weight 2: " .. rec2.weight)
 	return rec1.host == rec2.host and rec1.port == rec2.port and rec1.priority == rec2.priority and rec1.weight == rec2.weight
 end
 
 srv_records = {
-	srv_record:new("udpserver1.asteriskphone.net",5060,0,3),
-	srv_record:new("udpserver2.asteriskphone.net",5061,1,0),
-	srv_record:new("udpserver3.asteriskphone.net",5060,1,0),
-	srv_record:new("udpserver4.asteriskphone.net",5060,65535,65535)
+	srv_record:new("udpserver1.asteriskphone.net","5060","0","3"),
+	srv_record:new("udpserver2.asteriskphone.net","5061","1","0"),
+	srv_record:new("udpserver3.asteriskphone.net","5060","1","0"),
+	srv_record:new("udpserver4.asteriskphone.net","5060","65535","65535")
 }
 
---instance = ast.new()
---ast:load_config("configs/extensions.conf")
---ast:generate_manager_conf()
---ast:spawn()
+function analyze_srv(event)
+	local record_num = event["RecordNum"] + 1
+	local record = srv_record:new(event["Host"], event["Port"], event["Priority"], event["Weight"])
+	--Helpful for debugging
+	--print ("User event callback")
+	--print ("Got record Host: " .. event["Host"] .. " Port: " .. event["Port"] .. " Priority: " .. event["Priority"] .. " Weight: " .. event["Weight"])
+	if record ~= srv_records[record_num] then
+		-- Since records 2 and 3 share the same priority, it is unpredictable
+		-- which order we'll see them arrive
+		if record_num == 2 then
+			record_num = 3
+		elseif record_num == 3 then
+			record_num = 2
+		else
+			fail("Records don't match!")
+		end
+		if record ~= srv_records[record_num] then
+			fail("Records don't match!")
+		end
+	end
+end
 
-for i,v in ipairs(srv_records) do
-	print ("Host: " .. v.host)
-	print ("Port: " .. v.port)
-	print ("Priority: " .. v.priority)
-	print ("Weight: " .. v.weight)
+function do_call(man)
+	local orig = ast.manager.action:new("Originate")
+	orig["Channel"] = "Local/test at test_context"
+	orig["Application"] = "Wait"
+	orig["Data"] = "3"
+	man:register_event("UserEvent", analyze_srv)
+	local res, err = man(orig)
+	if not res then
+		fail("Error originating call: " .. err)
+	end
+	if res["Response"] ~= "Success" then
+		fail("Response failure for Originate: " .. res["Message"])
+	end
+	posix.sleep(4)
+	res, err = man:pump_messages()
+	if not res then
+		fail("Error pumping messages: " .. err)
+	end
+	man:process_events()
+	man:unregister_event("UserEvent", analyze_srv)
 end
+
+instance = ast.new()
+instance:load_config("configs/extensions.conf")
+instance:generate_manager_conf()
+instance:spawn()
+
+man,err = instance:manager_connect()
+if not man then
+	fail("error connecting to asterisk: " .. err)
+end
+
+login = ast.manager.action.login()
+if not login then
+	fail("Couldn't create login?")
+end
+man(login)
+do_call(man)
+logoff = ast.manager.action.logoff()
+man(logoff)
+instance:term_or_kill()




More information about the asterisk-commits mailing list