Fixed issues with missing code

This commit is contained in:
2023-05-05 16:33:31 -04:00
parent 189552ac65
commit 33202260e3
6 changed files with 166 additions and 75 deletions
+30 -30
View File
@@ -20,7 +20,7 @@ end
The expected and actual should "match" (Might be impossible when playing with threads)
This will be pushed directly to the master as tests start existing.
]]
local multi, thread = require("multi"):init{print=true}--{priority=true}
local multi, thread = require("multi"):init{print=true,warn=true,error=false}--{priority=true}
local good = false
local proc = multi:newProcessor("Test")
@@ -32,7 +32,7 @@ end)
runTest = thread:newFunction(function()
local alarms,tsteps,steps,loops,tloops,updaters,events=false,0,0,0,0,0,false
print("Testing Basic Features. If this fails most other features will probably not work!")
multi.print("Testing Basic Features. If this fails most other features will probably not work!")
proc:newAlarm(2):OnRing(function(a)
alarms = true
a:Destroy()
@@ -62,18 +62,18 @@ runTest = thread:newFunction(function()
event.OnEvent(function(evnt)
evnt:Destroy()
events = true
print("Alarms: Ok")
print("Events: Ok")
if tsteps == 10 then print("TSteps: Ok") else print("TSteps: Bad!") end
if steps == 10 then print("Steps: Ok") else print("Steps: Bad!") end
if loops > 100 then print("Loops: Ok") else print("Loops: Bad!") end
if tloops > 10 then print("TLoops: Ok") else print("TLoops: Bad!") end
if updaters > 100 then print("Updaters: Ok") else print("Updaters: Bad!") end
multi.success("Alarms: Ok")
multi.success("Events: Ok")
if tsteps == 10 then multi.success("TSteps: Ok") else multi.error("TSteps: Bad!") end
if steps == 10 then multi.success("Steps: Ok") else multi.error("Steps: Bad!") end
if loops > 100 then multi.success("Loops: Ok") else multi.error("Loops: Bad!") end
if tloops > 10 then multi.success("TLoops: Ok") else multi.error("TLoops: Bad!") end
if updaters > 100 then multi.success("Updaters: Ok") else multi.error("Updaters: Bad!") end
end)
thread.hold(event.OnEvent)
print("Starting Connection and Thread tests!")
multi.print("Starting Connection and Thread tests!")
func = thread:newFunction(function(count)
print("Starting Status test: ",count)
multi.print("Starting Status test: ",count)
local a = 0
while true do
a = a + 1
@@ -88,13 +88,13 @@ runTest = thread:newFunction(function()
local ret3 = func(20)
local s1,s2,s3 = 0,0,0
ret.OnError(function(...)
print("Func 1:",...)
multi.error("Func 1:",...)
end)
ret2.OnError(function(...)
print("Func 2:",...)
multi.error("Func 2:",...)
end)
ret3.OnError(function(...)
print("Func 3:",...)
multi.error("Func 3:",...)
end)
ret.OnStatus(function(part,whole)
s1 = math.ceil((part/whole)*1000)/10
@@ -107,31 +107,31 @@ runTest = thread:newFunction(function()
end)
ret.OnReturn(function(...)
print("Done 1",...)
multi.success("Done 1",...)
end)
ret2.OnReturn(function(...)
print("Done 2",...)
multi.success("Done 2",...)
end)
ret3.OnReturn(function(...)
print("Done 3",...)
multi.success("Done 3",...)
end)
local err, timeout = thread.hold(ret.OnReturn * ret2.OnReturn * ret3.OnReturn)
if s1 == 100 and s2 == 100 and s3 == 100 then
print("Threads: All tests Ok")
multi.success("Threads: All tests Ok")
else
if s1>0 and s2>0 and s3 > 0 then
print("Thread OnStatus: Ok")
multi.success("Thread OnStatus: Ok")
else
print("Threads OnStatus or thread.hold(conn) Error!")
multi.error("Threads OnStatus or thread.hold(conn) Error!")
end
if timeout then
print("Connection Error!")
multi.error("Connection Error!")
else
print("Connection Test 1: Ok")
multi.success("Connection Test 1: Ok")
end
print("Connection holding Error!")
multi.error("Connection holding Error!")
end
conn1 = proc:newConnection()
@@ -160,30 +160,30 @@ runTest = thread:newFunction(function()
conn3:Fire()
if c1 and c2 and c3 and c4 then
print("Connection Test 2: Ok")
multi.success("Connection Test 2: Ok")
else
print("Connection Test 2: Error")
multi.error("Connection Test 2: Error")
end
c3 = false
c4 = false
conn3:Unconnect(d)
conn3:Fire()
if c3 and not(c4) then
print("Connection Test 3: Ok")
multi.success("Connection Test 3: Ok")
else
print("Connection Test 3: Error removing connection")
multi.error("Connection Test 3: Error removing connection")
end
if not love then
print("Testing pseudo threading")
multi.print("Testing pseudo threading")
os.execute("lua tests/threadtests.lua p")
print("Testing lanes threading")
multi.print("Testing lanes threading")
os.execute("lua tests/threadtests.lua l")
os.exit()
end
end)
runTest().OnError(function(...)
print("Error: Something went wrong with the test!")
multi.error("Something went wrong with the test!")
print(...)
end)
+26 -21
View File
@@ -1,8 +1,8 @@
package.path = "../?/init.lua;../?.lua;"..package.path
multi, thread = require("multi"):init{}--{priority=true}
multi, thread = require("multi"):init{print=true,warn=true,error=false}--{priority=true}
proc = multi:newProcessor("Thread Test",true)
local LANES, LOVE, PSEUDO = 1, 2, 3
local env
local env, we_good
if love then
GLOBAL, THREAD = require("multi.integration.loveManager"):init()
@@ -27,11 +27,11 @@ else
end
end
print("Testing THREAD.setENV() if the multi_assert is not found then there is a problem")
multi.print("Testing THREAD.setENV() if the multi_assert is not found then there is a problem")
THREAD.setENV({
multi_assert = function(expected, actual, s)
if expected ~= actual then
error(s .. " Expected: '".. expected .."' Actual: '".. actual .."'")
multi.error(s .. " Expected: '".. expected .."' Actual: '".. actual .."'")
end
end
})
@@ -47,7 +47,7 @@ multi:newThread("Scheduler Thread",function()
multi_assert("table", type(f), "Argument f is not a table!")
queue:push("done")
end,"Passing some args", 1, 2, 3, true, {"Table"}).OnError(function(self,err)
print("Error:", err)
multi.error(err)
os.exit()
end)
@@ -57,7 +57,7 @@ multi:newThread("Scheduler Thread",function()
thread.kill()
end
print("Thread Spawning, THREAD namaspace in threads, global's working, and queues for passing data: Ok")
multi.success("Thread Spawning, THREAD namaspace in threads, global's working, and queues for passing data: Ok")
func = THREAD:newFunction(function(a,b,c)
assert(a == 3, "First argument expected '3' got '".. a .."'!")
@@ -73,7 +73,7 @@ multi:newThread("Scheduler Thread",function()
assert(c == 3, "Third return was not '3'!")
assert(d[1] == "a table", "Fourth return is not table, or doesn't contain 'a table'!")
print("Threaded Functions, arg passing, return passing, holding: Ok")
multi.success("Threaded Functions, arg passing, return passing, holding: Ok")
test=multi:newSystemThreadedTable("YO"):init()
test["test1"]="tabletest"
@@ -84,7 +84,7 @@ multi:newThread("Scheduler Thread",function()
THREAD.hold(function() return tab["test1"] end)
THREAD.sleep(.1)
tab["test2"] = "Whats so funny?"
end).OnError(print)
end).OnError(multi.error)
multi:newThread("test2",function()
thread.hold(function() return test["test2"] end)
@@ -96,11 +96,11 @@ multi:newThread("Scheduler Thread",function()
end,{sleep=1})
if val == multi.TIMEOUT then
print("SystemThreadedTables: Failed")
multi.error("SystemThreadedTables: Failed")
os.exit()
end
print("SystemThreadedTables: Ok")
multi.success("SystemThreadedTables: Ok")
local ready = false
@@ -123,11 +123,11 @@ multi:newThread("Scheduler Thread",function()
end,{sleep=2})
if val == multi.TIMEOUT then
print("SystemThreadedJobQueues: Failed")
multi.error("SystemThreadedJobQueues: Failed")
os.exit()
end
print("SystemThreadedJobQueues: Ok")
multi.success("SystemThreadedJobQueues: Ok")
queue2 = multi:newSystemThreadedQueue("Test_Queue2"):init()
multi:newSystemThread("Test_Thread_2",function()
@@ -137,7 +137,7 @@ multi:newThread("Scheduler Thread",function()
queue2:push("Test_Thread_2")
end)
multi:mainloop()
end).OnError(print)
end).OnError(multi.error)
multi:newSystemThread("Test_Thread_3",function()
queue2 = THREAD.waitFor("Test_Queue2"):init()
@@ -146,7 +146,7 @@ multi:newThread("Scheduler Thread",function()
queue2:push("Test_Thread_3")
end)
multi:mainloop()
end).OnError(print)
end).OnError(multi.error)
connOut = multi:newSystemThreadedConnection("ConnectionNAMEHERE"):init()
a=0
connOut(function(arg)
@@ -164,21 +164,26 @@ multi:newThread("Scheduler Thread",function()
count = count + 1
end
end
end).OnError(print)
end).OnError(multi.error)
_, err = thread.hold(function() return count == 9 end,{sleep=.3})
if err == multi.TIMEOUT then
print("SystemThreadedConnections: Failed")
os.exit()
multi.error("SystemThreadedConnections: Failed")
end
print("SystemThreadedConnections: Ok")
multi.success("SystemThreadedConnections: Ok")
print("Tests complete!")
we_good = true
os.exit()
end).OnError(print)
end).OnError(multi.error)
multi.OnExit(function(err)
if not we_good then
multi.error("There was an error running some tests!")
else
multi.success("Tests complete!")
end
end)
multi:mainloop()