Adding tests wip

This commit is contained in:
Ryan Ward 2021-05-27 16:47:45 -04:00
parent 4399fb6424
commit 37afd37f9e
4 changed files with 49 additions and 31 deletions

View File

@ -323,9 +323,9 @@ end
--Constructors [CORE]
local _tid = 0
function multi:newBase(ins)
if not(self.Type=='mainprocess' or self.Type=='process' or self.Type=='queue') then error('Can only create an object on multi or an interface obj') return false end
if not(self.Type=='mainprocess' or self.Type=='process' or self.Type=='queue' or self.Type == 'sandbox') then error('Can only create an object on multi or an interface obj') return false end
local c = {}
if self.Type=='process' or self.Type=='queue' then
if self.Type=='process' or self.Type=='queue' or self.Type=='sandbox' then
setmetatable(c, {__index = multi})
else
setmetatable(c, {__index = multi})

View File

@ -1,40 +1,51 @@
package.path = "./?/init.lua;"..package.path
multi,thread = require("multi"):init()
GLOBAL,THREAD = require("multi.integration.threading"):init() -- Auto detects your enviroment and uses what's available
--GLOBAL,THREAD = require("multi.integration.threading"):init() -- Auto detects your enviroment and uses what's available
jq = multi:newSystemThreadedJobQueue(5) -- Job queue with 4 worker threads
func = jq:newFunction("test",function(a,b)
THREAD.sleep(2)
return a+b
end)
for i = 1,10 do
func(i,i*3).connect(function(data)
print(data)
end)
local sandcount = 0
function multi:newProcessor(name)
local c = {}
setmetatable(c,{__index = self})
local multi,thread = require("multi"):init() -- We need to capture the t in thread
local name = name or "Processor_"..sandcount
sandcount = sandcount + 1
c.Mainloop = {}
c.Type = "process"
c.Active = false
c.OnError = multi:newConnection()
c.process = self:newThread(name,function()
while true do
thread.hold(function()
return sandbox.Active
end)
c:uManager()
end
end).OnError(c.OnError)
function c.Start()
c.Active = true
end
function c.Stop()
c.Active = false
end
return c
end
local a = true
b = false
sandbox = multi:newProcessor()
sandbox:newTLoop(function()
print("testing...")
end,1)
multi:newThread("Standard Thread 1",function()
test2 = multi:newTLoop(function()
print("testing2...")
end,1)
sandbox:newThread("Test Thread",function()
while true do
thread.sleep(1)
print("Testing 1 ...",a,b,test)
print("Thread Test...")
end
end).OnError(function(self,msg)
print(msg)
end)
-- All upvalues are stripped! no access to the global, multi and thread are exposed however
multi:newISOThread("ISO Thread 2",function()
while true do
thread.sleep(1)
print("Testing 2 ...",a,b,test) -- a and b are nil, but test is true
end
end,{test=true,print=print})
.OnError(function(self,msg)
print(msg)
end)
sandbox.Start()
multi:mainloop()

3
tests/objectTests.lua Normal file
View File

@ -0,0 +1,3 @@
return function objectTests(multi,thread)
print("Testing Alarms!")
end

View File

@ -15,3 +15,7 @@ package.path="../?.lua;../?/init.lua;../?.lua;../?/?/init.lua;"..package.path
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()
function runTest(path)
end