mirror of
https://github.com/rayaman/multi.git
synced 2026-09-04 23:17:35 -04:00
Fix some bugs, added connection/thread tests
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
function connectionThreadTests(multi,thread)
|
||||
print("Starting Connection and Thread tests!")
|
||||
func = thread:newFunction(function(count)
|
||||
local a = 0
|
||||
while true do
|
||||
a = a + 1
|
||||
thread.sleep(.1)
|
||||
thread.pushStatus(a,count)
|
||||
if a == count then break end
|
||||
end
|
||||
return "Done"
|
||||
end)
|
||||
local ret = func(10)
|
||||
local ret2 = func(15)
|
||||
local ret3 = func(20)
|
||||
local s1,s2,s3 = 0,0,0
|
||||
ret.OnStatus(function(part,whole)
|
||||
s1 = math.ceil((part/whole)*1000)/10
|
||||
end)
|
||||
ret2.OnStatus(function(part,whole)
|
||||
s2 = math.ceil((part/whole)*1000)/10
|
||||
end)
|
||||
ret3.OnStatus(function(part,whole)
|
||||
s3 = math.ceil((part/whole)*1000)/10
|
||||
end)
|
||||
local err, timeout = thread.hold(ret2.OnReturn + ret.OnReturn + ret3.OnReturn,{sleep=3})
|
||||
if s1 == 100 and s2 == 100 and s3 == 100 then
|
||||
print("Threads: Ok")
|
||||
else
|
||||
print("Threads on status error")
|
||||
end
|
||||
if timeout then
|
||||
print("Threads or Connection error!")
|
||||
else
|
||||
print("Connection Test 1: Ok")
|
||||
end
|
||||
conn1 = multi:newConnection()
|
||||
conn2 = multi:newConnection()
|
||||
conn3 = multi:newConnection()
|
||||
local c1,c2,c3,c4 = false,false,false,false
|
||||
local a = conn1(function()
|
||||
c1 = true
|
||||
end)
|
||||
local b = conn2(function()
|
||||
c2 = true
|
||||
end)
|
||||
local c = conn3(function()
|
||||
c3 = true
|
||||
end)
|
||||
local d = conn3(function()
|
||||
c4 = true
|
||||
end)
|
||||
conn1:Fire()
|
||||
conn2:Fire()
|
||||
conn3:Fire()
|
||||
if c1 and c2 and c3 and c4 then
|
||||
print("Connection Test 2: Ok")
|
||||
else
|
||||
print("Connection Test 2: Error")
|
||||
end
|
||||
c3 = false
|
||||
c4 = false
|
||||
d:Destroy()
|
||||
conn3:Fire()
|
||||
if c3 and not(c4) then
|
||||
print("Connection Test 3: Ok")
|
||||
else
|
||||
print("Connection Test 3: Error removing connection")
|
||||
end
|
||||
end
|
||||
return connectionThreadTests
|
||||
@@ -37,6 +37,6 @@ function objectTests(multi,thread)
|
||||
if tloops > 10 then print("TLoops: Ok") else print("TLoops: Bad!") end
|
||||
if updaters > 100 then print("Updaters: Ok") else print("Updaters: Bad!") end
|
||||
end)
|
||||
return event
|
||||
thread.hold(event.OnEvent)
|
||||
end
|
||||
return objectTests
|
||||
+9
-11
@@ -16,20 +16,18 @@ package.path="./?.lua;../?.lua;../?/init.lua;../?.lua;../?/?/init.lua;"..package
|
||||
This will be pushed directly to the master as tests start existing.
|
||||
]]
|
||||
local multi, thread = require("multi"):init()
|
||||
|
||||
local good = false
|
||||
runTest = thread:newFunction(function()
|
||||
local objects = multi:newProcessor("Basic Object Tests")
|
||||
objects.Start()
|
||||
otest = require("tests/objectTests")(objects,thread)
|
||||
thread.hold(otest.OnEvent)
|
||||
print("Timers: Ok")
|
||||
print("Connections: Ok")
|
||||
print("Threads: Ok")
|
||||
print(objects:getTasksDetails())
|
||||
good = true
|
||||
print("\nTests done")
|
||||
require("tests/objectTests")(objects,thread)
|
||||
objects.Stop()
|
||||
local conn_thread = multi:newProcessor("Connection/Thread Tests")
|
||||
conn_thread.Start()
|
||||
require("tests/connectionTest")(conn_thread,thread)
|
||||
conn_thread.Stop()
|
||||
print(multi:getTasksDetails())
|
||||
os.exit()
|
||||
end,true)
|
||||
print(runTest())
|
||||
end)
|
||||
runTest()
|
||||
multi:mainloop()
|
||||
Reference in New Issue
Block a user