From 37afd37f9e08398d98d994e8ed0d67321faca966 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Thu, 27 May 2021 16:47:45 -0400 Subject: [PATCH] Adding tests wip --- multi/init.lua | 4 +-- test.lua | 67 +++++++++++++++++++++++++------------------ tests/objectTests.lua | 3 ++ tests/runtests.lua | 6 +++- 4 files changed, 49 insertions(+), 31 deletions(-) create mode 100644 tests/objectTests.lua diff --git a/multi/init.lua b/multi/init.lua index 5420197..aac3c99 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -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}) diff --git a/test.lua b/test.lua index af7e39c..17d69cd 100644 --- a/test.lua +++ b/test.lua @@ -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() \ No newline at end of file diff --git a/tests/objectTests.lua b/tests/objectTests.lua new file mode 100644 index 0000000..9296a48 --- /dev/null +++ b/tests/objectTests.lua @@ -0,0 +1,3 @@ +return function objectTests(multi,thread) + print("Testing Alarms!") +end \ No newline at end of file diff --git a/tests/runtests.lua b/tests/runtests.lua index a4c3263..e0faa88 100644 --- a/tests/runtests.lua +++ b/tests/runtests.lua @@ -14,4 +14,8 @@ package.path="../?.lua;../?/init.lua;../?.lua;../?/?/init.lua;"..package.path Each test that is ran should have a 5 second pause after the test is complete 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. -]] \ No newline at end of file +]] +local multi, thread = require("multi"):init() +function runTest(path) + +end \ No newline at end of file