[asterisk-commits] mmichelson: testsuite/asterisk/trunk r368 - /asterisk/trunk/tests/queues/wrap...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jun 8 14:44:02 CDT 2010


Author: mmichelson
Date: Tue Jun  8 14:43:59 2010
New Revision: 368

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=368
Log:
Make wrapup_time test a bit more reliable.

Bamboo was reporting test failures. The biggest reason for
this was that we were only waiting for a call to be answered before
moving on to the next one. What we needed to be doing was to wait
for the previous call to complete before moving to the next one. After
making these changes, I find that the Bamboo agent is passing the
test every time now.

One more errant test to go...


Modified:
    asterisk/trunk/tests/queues/wrapup_time/test.lua

Modified: asterisk/trunk/tests/queues/wrapup_time/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/queues/wrapup_time/test.lua?view=diff&rev=368&r1=367&r2=368
==============================================================================
--- asterisk/trunk/tests/queues/wrapup_time/test.lua (original)
+++ asterisk/trunk/tests/queues/wrapup_time/test.lua Tue Jun  8 14:43:59 2010
@@ -32,7 +32,7 @@
 	--print("BridgedChannel: " .. tostring(event["BridgedChannel"]))
 	--print("Ringtime: " .. tostring(event["Ringtime"]))
 	if event["MemberName"] == "member1" then
-		pass = true
+		connectpass = true
 	else
 		print(event["Membername"])
 	end
@@ -49,7 +49,9 @@
 	--print("BridgedChannel: " .. tostring(event["BridgedChannel"]))
 	--print("Ringtime: " .. tostring(event["Ringtime"]))
 	if event["MemberName"] == "member2" then
-		pass = true
+		connectpass = true
+	else
+		print(event["Membername"])
 	end
 end
 
@@ -62,10 +64,16 @@
 	return instance
 end
 
+function complete_handler(event)
+	completepass = true
+end
+
 function test_call(ast_instance, man, handler, exten)
 	if handler then
 		man:register_event("AgentConnect", handler)
-		pass = false
+		man:register_event("AgentComplete", complete_handler)
+		connectpass = false
+		completepass = false
 	end
 	local orig = ast.manager.action:new("Originate")
 	orig["Channel"] = "Local/" .. exten .. "@test_context/n"
@@ -90,39 +98,49 @@
 		fail("Originate successful when there should have been no available queue members")
 	end
 
-	posix.sleep(1)
-
-	res, err = man:pump_messages()
-	if not res then
-		fail("Error pumping messages: " .. err)
+	--This loop is constructed so that we will wait for the call to
+	--finish before moving on. We'll only wait a maximum of 30 iterations
+	--though. And since there is a 1 second sleep on each iteration, that
+	--comes out to about 30 seconds.
+	i = 0
+	while not completepass or not connectpass and i < 30 do
+		res, err = man:pump_messages()
+		if not res then
+			fail("Failure while waiting for event" .. err)
+		end
+		man:process_events()
+		i = i + 1;
+		posix.sleep(1)
 	end
 
-	man:process_events()
-	if not pass then
-		if handler == member1 then
-			fail("Did not get AgentConnect for member1 as expected")
-		elseif handler == member2 then
-			fail("Did not get AgentConnect for member2 as expected")
-		else
-			fail("Got AgentConnect when we should not have gotten one")
-		end
+	if not connectpass then
+		fail("Failed to receive an AgentConnect event within 30 seconds")
 	end
+
+	if not completepass then
+		fail("Failed to receive an AgentComplete event within 30 seconds")
+	end
+
 	man:unregister_event("AgentConnect", handler)
+	man:unregister_event("AgentComplete", complete_handler)
 end
 
 instance1 = setup_ast_instance("ast1")
 instance2 = setup_ast_instance("ast2")
 
-posix.sleep(1)
-
 man1 = manager_setup(instance1)
 man2 = manager_setup(instance2)
 
 test_call(instance1, man1, member1, "test1")
+posix.sleep(1)
 test_call(instance1, man1, member1, "test2")
+posix.sleep(1)
 test_call(instance1, man1, member2, "test1")
+posix.sleep(1)
 test_call(instance2, man2, member1, "test1")
+posix.sleep(1)
 test_call(instance2, man2, member2, "test2")
+posix.sleep(1)
 --On this call, since both members are unavailable,
 --originating a call to the queue will fail since
 --no one will answer




More information about the asterisk-commits mailing list