summaryrefslogtreecommitdiffstats
path: root/conf.d/controller/lua.d/aft.lua
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-07-09 18:55:49 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-10 17:16:33 +0200
commitef0ae0c644b37b2bcc130b7435941c77fe2bb437 (patch)
treeda3d96e2e29d67959fadf05be7692979a60bb8ec /conf.d/controller/lua.d/aft.lua
parent599a2c79b654d9ce047ec5377c3f0cf50eaa94dc (diff)
lockwait: add lua lockwait function
this function handles to wait for one specific afb event Change-Id: Ief730b6b5f2109379ca0191d98b013d1c9e4225e Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'conf.d/controller/lua.d/aft.lua')
-rw-r--r--conf.d/controller/lua.d/aft.lua33
1 files changed, 21 insertions, 12 deletions
diff --git a/conf.d/controller/lua.d/aft.lua b/conf.d/controller/lua.d/aft.lua
index 329cefd..6fd1882 100644
--- a/conf.d/controller/lua.d/aft.lua
+++ b/conf.d/controller/lua.d/aft.lua
@@ -141,12 +141,26 @@ end
Assert and test functions about the event part.
]]
-function _AFT.assertEvtNotReceived(eventName)
- local count = 0
+function _AFT.lockwait(eventName, timeout)
+ local count = 0
if _AFT.monitored_events[eventName].receivedCount then
- count = _AFT.monitored_events[eventName].receivedCount
+ if timeout then
+ count = _AFT.monitored_events[eventName].receivedCount
+ end
end
+ while timeout > 0 do
+ timeout = AFB:lockwait(_AFT.context, timeout)
+ if _AFT.monitored_events[eventName].receivedCount == count + 1 then
+ return 1
+ end
+ end
+ return 0
+end
+
+function _AFT.assertEvtNotReceived(eventName, timeout)
+ local count = _AFT.lockwait(eventName, timeout)
+
_AFT.assertIsTrue(count == 0, "Event '".. eventName .."' received but it shouldn't")
if _AFT.monitored_events[eventName].cb then
@@ -155,11 +169,8 @@ function _AFT.assertEvtNotReceived(eventName)
end
end
-function _AFT.assertEvtReceived(eventName)
- local count = 0
- if _AFT.monitored_events[eventName].receivedCount then
- count = _AFT.monitored_events[eventName].receivedCount
- end
+function _AFT.assertEvtReceived(eventName, timeout)
+ local count = _AFT.lockwait(eventName, timeout)
_AFT.assertIsTrue(count > 0, "No event '".. eventName .."' received")
@@ -172,8 +183,7 @@ end
function _AFT.testEvtNotReceived(testName, eventName, timeout, setUp, tearDown)
table.insert(_AFT.tests_list, {testName, function()
if _AFT.beforeEach then _AFT.beforeEach() end
- if timeout then sleep(timeout) end
- _AFT.assertEvtNotReceived(eventName)
+ _AFT.assertEvtNotReceived(eventName, timeout)
if _AFT.afterEach then _AFT.afterEach() end
end})
end
@@ -181,8 +191,7 @@ end
function _AFT.testEvtReceived(testName, eventName, timeout, setUp, tearDown)
table.insert(_AFT.tests_list, {testName, function()
if _AFT.beforeEach then _AFT.beforeEach() end
- if timeout then sleep(timeout) end
- _AFT.assertEvtReceived(eventName)
+ _AFT.assertEvtReceived(eventName, timeout)
if _AFT.afterEach then _AFT.afterEach() end
end})
end