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] --Constructors [CORE]
local _tid = 0 local _tid = 0
function multi:newBase(ins) 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 = {} 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}) setmetatable(c, {__index = multi})
else else
setmetatable(c, {__index = multi}) setmetatable(c, {__index = multi})

View File

@ -1,40 +1,51 @@
package.path = "./?/init.lua;"..package.path
multi,thread = require("multi"):init() 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 local sandcount = 0
func = jq:newFunction("test",function(a,b) function multi:newProcessor(name)
THREAD.sleep(2) local c = {}
return a+b setmetatable(c,{__index = self})
end) local multi,thread = require("multi"):init() -- We need to capture the t in thread
local name = name or "Processor_"..sandcount
for i = 1,10 do sandcount = sandcount + 1
func(i,i*3).connect(function(data) c.Mainloop = {}
print(data) c.Type = "process"
end) 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 end
local a = true sandbox = multi:newProcessor()
b = false 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 while true do
thread.sleep(1) thread.sleep(1)
print("Testing 1 ...",a,b,test) print("Thread Test...")
end end
end).OnError(function(self,msg)
print(msg)
end) end)
-- All upvalues are stripped! no access to the global, multi and thread are exposed however sandbox.Start()
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)
multi:mainloop() 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) 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. This will be pushed directly to the master as tests start existing.
]] ]]
local multi, thread = require("multi"):init()
function runTest(path)
end