From cfef9d6ff310943c602d513b88d4568184284002 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Fri, 15 Jun 2018 18:28:36 +0200 Subject: Fix: infinite loop of event fired by test binding Restrict which api are monitored to avoid daemon log messages to be infinitely generated. Change-Id: Ie527267985ca8035c3f410be1d775f3214feac2c Signed-off-by: Romain Forlot --- conf.d/project/etc/test-config.json | 1 + conf.d/project/lua.d/aft.lua | 20 ++++++++++++++------ conf.d/project/lua.d/helloworld.lua | 6 ++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/conf.d/project/etc/test-config.json b/conf.d/project/etc/test-config.json index cf53b96..aee7857 100644 --- a/conf.d/project/etc/test-config.json +++ b/conf.d/project/etc/test-config.json @@ -15,6 +15,7 @@ "info": "Launch all the tests", "action": "lua://AFT#_launch_test", "args": { + "trace": "hello", "files": ["helloworld.lua"] } } diff --git a/conf.d/project/lua.d/aft.lua b/conf.d/project/lua.d/aft.lua index 5f548ce..aa8df56 100644 --- a/conf.d/project/lua.d/aft.lua +++ b/conf.d/project/lua.d/aft.lua @@ -80,13 +80,22 @@ function _AFT.registerData(dict, eventData) end end -function _AFT.daemonEventHandler(eventObj) +function _AFT.requestDaemonEventHandler(eventObj) local eventName = eventObj.data.message local log = _AFT.monitored_events[eventName] - if log and log.api == eventObj.daemon.api and log.type == eventObj.data.type then + local api = nil + print(log.api, api) + if eventObj.daemon then + api = eventObj.daemon.api + elseif eventObj.request then + api = eventObj.request.api + end + + if log and log.api == api and log.type == eventObj.data.type then _AFT.incrementCount(_AFT.monitored_events[eventName]) _AFT.registerData(_AFT.monitored_events[eventName], eventObj.data) end + end function _AFT.bindingEventHandler(eventObj) @@ -108,8 +117,8 @@ function _evt_catcher_ (source, action, eventObj) print(Dump_Table(eventObj)) if eventObj.type == "event" then _AFT.bindingEventHandler(eventObj) - elseif eventObj.type == "daemon" then - _AFT.daemonEventHandler(eventObj) + elseif eventObj.type == "daemon" or eventObj.type == "request" then + _AFT.requestDaemonEventHandler(eventObj) end end @@ -396,8 +405,7 @@ end function _launch_test(context, args) _AFT.context = context AFB:servsync(_AFT.context, "monitor", "set", { verbosity = "debug" }) - --AFB:servsync(_AFT.context, "monitor", "trace", { add = { event = "push_before", event = "push_after" }}) - AFB:servsync(_AFT.context, "monitor", "trace", { add = { daemon = "vverbose", event = "push_after" }}) + AFB:servsync(_AFT.context, "monitor", "trace", { add = { api = args.api, request = "vverbose", daemon = "vverbose", event = "push_after" }}) for _,f in pairs(args.files) do dofile('var/'..f) end diff --git a/conf.d/project/lua.d/helloworld.lua b/conf.d/project/lua.d/helloworld.lua index dc883f2..1b727df 100644 --- a/conf.d/project/lua.d/helloworld.lua +++ b/conf.d/project/lua.d/helloworld.lua @@ -32,7 +32,7 @@ end _AFT.addEventToMonitor("hello/anEvent") _AFT.addEventToMonitor("hello/anotherEvent", _callbackEvent) -_AFT.addLogToMonitor("test", "warning", "CtlDispatchEvent: fail to find uid=hello/anEvent in action event section") +_AFT.addLogToMonitor("hello", "warning", "verbose called for My Warning message!") _AFT.testVerbStatusSuccess('testPingSuccess','hello', 'ping', {}) _AFT.testVerbResponseEquals('testPingSuccess','hello', 'ping', {}, "Some String") @@ -51,10 +51,12 @@ _AFT.testVerbStatusSuccess('testEventAdd', 'hello', 'eventadd', {tag = 'evt', na _AFT.testVerbStatusSuccess('testEventSub', 'hello', 'eventsub', {tag = 'evt'}) _AFT.testVerbStatusSuccess('testEventPush', 'hello', 'eventpush', {tag = 'evt', data = { key = 'weird others data', another_key = 123.456}}) +_AFT.testVerbStatusSuccess('testGenerateWarning', 'hello', 'verbose', {level = 4, message = 'My Warning message!'}) + _AFT.testEvtReceived("testEvent", "hello/anEvent") _AFT.testEvtReceived("testEventCb", "hello/anotherEvent") -_AFT.testLogReceived("LogReceived", "CtlDispatchEvent: fail to find uid=hello/anEvent in action event section") +_AFT.testLogReceived("LogReceived", "verbose called for My Warning message!") _AFT.testCustom("mytest", function() _AFT.assertEquals(false, false) -- cgit 1.2.3-korg