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 *.code-workspace
*.dat
*.zip

View File

@ -159,23 +159,27 @@ function multi:newConnection(protect,func,kill)
local cn = multi:newConnection() local cn = multi:newConnection()
if not c1.__hasInstances then if not c1.__hasInstances then
cn.__hasInstances = 2 cn.__hasInstances = 2
cn.__count = 0 cn.__count = {0}
else else
cn.__hasInstances = c1.__hasInstances + 1 cn.__hasInstances = c1.__hasInstances + 1
cn.__count = c1.__count cn.__count = c1.__count
end end
c1(function(...) c1(function(...)
cn.__count = cn.__count + 1 cn.__count[1] = cn.__count[1] + 1
if cn.__count == cn.__hasInstances then print(cn.__count[1], cn.__hasInstances)
if cn.__count[1] == cn.__hasInstances then
cn:Fire(...) cn:Fire(...)
cn.__count = 0 cn.__count[1] = 0
end end
end) end)
c2(function(...) c2(function(...)
cn.__count = cn.__count + 1 cn.__count[1] = cn.__count[1] + 1
if cn.__count == cn.__hasInstances then print(cn.__count[1], cn.__hasInstances)
if cn.__count[1] == cn.__hasInstances then
cn:Fire(...) cn:Fire(...)
cn.__count = 0 cn.__count[1] = 0
end end
end) end)
return cn return cn
@ -250,6 +254,25 @@ function multi:newConnection(protect,func,kill)
end end
function self:Connect(func) function self:Connect(func)
table.insert(fast,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 end
return self return self
end end
@ -1085,42 +1108,18 @@ function thread.sleep(n)
return yield(CMD, t_sleep, n or 1) return yield(CMD, t_sleep, n or 1)
end end
function thread.hold(n,opt) local function conn_test(conn)
thread._Requests() local ready = false
local opt = opt or {} local args
if type(opt)=="table" then local func = function(...)
interval = opt.interval ready = true
if opt.cycles then args = {...}
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
end end
conn(func)
if type(n) == "number" then return function()
thread.getRunningThread().lastSleep = clock() if ready then
return yield(CMD, t_sleep, n or 0, nil, interval) return unpack(args) or multi.NIL
elseif type(n) == "table" and n.Type == "connector" then
local rdy = function()
return false
end 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
end end
@ -1142,20 +1141,7 @@ function thread.hold(n,opt)
thread.getRunningThread().lastSleep = clock() thread.getRunningThread().lastSleep = clock()
return yield(CMD, t_sleep, n or 0, nil, interval) return yield(CMD, t_sleep, n or 0, nil, interval)
elseif type(n) == "table" and n.Type == "connector" then elseif type(n) == "table" and n.Type == "connector" then
local rdy = function() return yield(CMD, t_hold, conn_test(n), nil, interval)
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)
elseif type(n) == "function" then elseif type(n) == "function" then
return yield(CMD, t_hold, n or dFunc, nil, interval) return yield(CMD, t_hold, n or dFunc, nil, interval)
else 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 package.path="multi/?.lua;multi/?/init.lua;multi/?.lua;multi/?/?/init.lua;"..package.path
require("lldebugger").start() require("lldebugger").start()
else else
package.path="./?.lua;../?/init.lua;../?.lua;../?/?/init.lua;"..package.path package.path = "../?/init.lua;../?.lua;"..package.path
end end
--[[ --[[
This file runs all tests. This file runs all tests.
@ -36,12 +36,12 @@ runTest = thread:newFunction(function()
end) end)
proc:newTStep(1,10,1,.1):OnStep(function(t) proc:newTStep(1,10,1,.1):OnStep(function(t)
tsteps = tsteps + 1 tsteps = tsteps + 1
end).OnEnd(function(step) end):OnEnd(function(step)
step:Destroy() step:Destroy()
end) end)
proc:newStep(1,10):OnStep(function(s) proc:newStep(1,10):OnStep(function(s)
steps = steps + 1 steps = steps + 1
end).OnEnd(function(step) end):OnEnd(function(step)
step:Destroy() step:Destroy()
end) end)
local loop = proc:newLoop(function(l) local loop = proc:newLoop(function(l)
@ -102,6 +102,7 @@ runTest = thread:newFunction(function()
ret3.OnStatus(function(part,whole) ret3.OnStatus(function(part,whole)
s3 = math.ceil((part/whole)*1000)/10 s3 = math.ceil((part/whole)*1000)/10
end) end)
ret.OnReturn(function() ret.OnReturn(function()
print("Done 1") print("Done 1")
end) end)
@ -111,7 +112,9 @@ runTest = thread:newFunction(function()
ret3.OnReturn(function() ret3.OnReturn(function()
print("Done 3") print("Done 3")
end) 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 if s1 == 100 and s2 == 100 and s3 == 100 then
print("Threads: Ok") print("Threads: Ok")
else else
@ -164,11 +167,11 @@ runTest = thread:newFunction(function()
os.exit() -- End of tests os.exit() -- End of tests
end) end)
runTest().OnError(function(...) print(runTest().OnError(function(...)
print("Error: Something went wrong with the test!") print("Error: Something went wrong with the test!")
print(...) print(...)
os.exit(1) os.exit(1)
end) end))
print("Pumping proc") print("Pumping proc")
while true do 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.path = "../?/init.lua;../?.lua;"..package.path
package.cpath = "lua5.4/lib/lua/5.4/?/core.dll;"--..package.cpath
multi, thread = require("multi"):init{print=true,findopt=true} multi, thread = require("multi"):init{print=true,findopt=true}
GLOBAL, THREAD = require("multi.integration.lanesManager"):init() GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
multi:getOptimizationConnection()(function(msg) 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")