Tests failing with connections * connections, not counting triggers properly

This commit is contained in:
Ryan Ward 2022-11-06 01:00:04 -04:00
parent 6369450d2f
commit d6d4934a7e
5 changed files with 51 additions and 103 deletions

7
.gitignore vendored
View File

@ -1,8 +1 @@
*lua5.1
*lua5.2
*lua5.3
*lua5.4
*luajit
*.code-workspace
*.dat
*.zip

View File

@ -159,23 +159,27 @@ function multi:newConnection(protect,func,kill)
local cn = multi:newConnection()
if not c1.__hasInstances then
cn.__hasInstances = 2
cn.__count = 0
cn.__count = {0}
else
cn.__hasInstances = c1.__hasInstances + 1
cn.__count = c1.__count
end
c1(function(...)
cn.__count = cn.__count + 1
if cn.__count == cn.__hasInstances then
cn.__count[1] = cn.__count[1] + 1
print(cn.__count[1], cn.__hasInstances)
if cn.__count[1] == cn.__hasInstances then
cn:Fire(...)
cn.__count = 0
cn.__count[1] = 0
end
end)
c2(function(...)
cn.__count = cn.__count + 1
if cn.__count == cn.__hasInstances then
cn.__count[1] = cn.__count[1] + 1
print(cn.__count[1], cn.__hasInstances)
if cn.__count[1] == cn.__hasInstances then
cn:Fire(...)
cn.__count = 0
cn.__count[1] = 0
end
end)
return cn
@ -250,6 +254,25 @@ function multi:newConnection(protect,func,kill)
end
function self:Connect(func)
table.insert(fast,func)
local temp = {}
setmetatable(temp,{
__call=function(s,...)
return self:Connect(...)
end,
__index = function(t,k)
if rawget(t,"root_link") then
return t["root_link"][k]
end
return nil
end,
__newindex = function(t,k,v)
if rawget(t,"root_link") then
t["root_link"][k] = v
end
rawset(t,k,v)
end,
})
return temp
end
return self
end
@ -1085,42 +1108,18 @@ function thread.sleep(n)
return yield(CMD, t_sleep, n or 1)
end
function thread.hold(n,opt)
thread._Requests()
local opt = opt or {}
if type(opt)=="table" then
interval = opt.interval
if opt.cycles then
return yield(CMD, t_holdW, opt.cycles or 1, n or dFunc, interval)
elseif opt.sleep then
return yield(CMD, t_holdF, opt.sleep, n or dFunc, interval)
elseif opt.skip then
return yield(CMD, t_skip, opt.skip or 1, nil, interval)
end
local function conn_test(conn)
local ready = false
local args
local func = function(...)
ready = true
args = {...}
end
if type(n) == "number" then
thread.getRunningThread().lastSleep = clock()
return yield(CMD, t_sleep, n or 0, nil, interval)
elseif type(n) == "table" and n.Type == "connector" then
local rdy = function()
return false
conn(func)
return function()
if ready then
return unpack(args) or multi.NIL
end
n(function(a1,a2,a3,a4,a5,a6)
rdy = function()
if a1==nil then
return NIL,a2,a3,a4,a5,a6
end
return a1,a2,a3,a4,a5,a6
end
end)
return yield(CMD, t_hold, function()
return rdy()
end, nil, interval)
elseif type(n) == "function" then
return yield(CMD, t_hold, n or dFunc, nil, interval)
else
error("Invalid argument passed to thread.hold(...)!")
end
end
@ -1142,20 +1141,7 @@ function thread.hold(n,opt)
thread.getRunningThread().lastSleep = clock()
return yield(CMD, t_sleep, n or 0, nil, interval)
elseif type(n) == "table" and n.Type == "connector" then
local rdy = function()
return false
end
n(function(a1,a2,a3,a4,a5,a6)
rdy = function()
if a1==nil then
return NIL,a2,a3,a4,a5,a6
end
return a1,a2,a3,a4,a5,a6
end
end)
return yield(CMD, t_hold, function()
return rdy()
end, nil, interval)
return yield(CMD, t_hold, conn_test(n), nil, interval)
elseif type(n) == "function" then
return yield(CMD, t_hold, n or dFunc, nil, interval)
else

View File

@ -2,7 +2,7 @@ if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
package.path="multi/?.lua;multi/?/init.lua;multi/?.lua;multi/?/?/init.lua;"..package.path
require("lldebugger").start()
else
package.path="./?.lua;../?/init.lua;../?.lua;../?/?/init.lua;"..package.path
package.path = "../?/init.lua;../?.lua;"..package.path
end
--[[
This file runs all tests.
@ -36,12 +36,12 @@ runTest = thread:newFunction(function()
end)
proc:newTStep(1,10,1,.1):OnStep(function(t)
tsteps = tsteps + 1
end).OnEnd(function(step)
end):OnEnd(function(step)
step:Destroy()
end)
proc:newStep(1,10):OnStep(function(s)
steps = steps + 1
end).OnEnd(function(step)
end):OnEnd(function(step)
step:Destroy()
end)
local loop = proc:newLoop(function(l)
@ -102,6 +102,7 @@ runTest = thread:newFunction(function()
ret3.OnStatus(function(part,whole)
s3 = math.ceil((part/whole)*1000)/10
end)
ret.OnReturn(function()
print("Done 1")
end)
@ -111,7 +112,9 @@ runTest = thread:newFunction(function()
ret3.OnReturn(function()
print("Done 3")
end)
local err, timeout = thread.hold(ret.OnReturn + ret2.OnReturn + ret3.OnReturn)
local err, timeout = thread.hold(ret.OnReturn * ret2.OnReturn * ret3.OnReturn)
print("Working!",s1,s2,s3)
if s1 == 100 and s2 == 100 and s3 == 100 then
print("Threads: Ok")
else
@ -164,11 +167,11 @@ runTest = thread:newFunction(function()
os.exit() -- End of tests
end)
runTest().OnError(function(...)
print(runTest().OnError(function(...)
print("Error: Something went wrong with the test!")
print(...)
os.exit(1)
end)
end))
print("Pumping proc")
while true do

View File

@ -1,5 +1,4 @@
package.path = "./?/init.lua;?.lua;lua5.4/share/lua/5.4/?/init.lua;lua5.4/share/lua/5.4/?.lua;"--..package.path
package.cpath = "lua5.4/lib/lua/5.4/?/core.dll;"--..package.cpath
package.path = "../?/init.lua;../?.lua;"..package.path
multi, thread = require("multi"):init{print=true,findopt=true}
GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
multi:getOptimizationConnection()(function(msg)

View File

@ -1,33 +0,0 @@
function difference(a, b)
local ai = {}
local r = {}
local rr = {}
for k,v in pairs(a) do r[k] = v; ai[v]=true end
for k,v in pairs(b) do
if ai[v]==nil then table.insert(rr,r[k]) end
end
return rr
end
function remove(a, b)
local ai = {}
local r = {}
for k,v in pairs(a) do ai[v]=true end
for k,v in pairs(b) do
if ai[v]==nil then table.insert(r,a[k]) end
end
return r
end
function printtab(tab,msg)
print(msg or "TABLE")
for i,v in pairs(tab) do
print(i, v)
end
print("")
end
local tab1 = {1,2,3,4,5}
local tab2 = {3,4,5,6,7}
tab1 = remove(tab1,tab2)
printtab(tab1, "Table 1")
printtab(tab2, "Table 2")