From 5c3503e35c1b883e97ed6874f7683d0a7b5938b7 Mon Sep 17 00:00:00 2001 From: Frederic Marec Date: Tue, 9 Apr 2019 17:52:22 +0200 Subject: Fix event management in test framework Fix event receive Fix event not receive Fix lockwait event Remove trailing indentation Bug-AGL: SPEC-2374 Change-Id: Ie64b23c242bc13dcf7af96ff3ed2316bf6cad5f7 Signed-off-by: Frederic Marec --- test/CMakeLists.txt | 6 +++--- test/afb-test/fixtures/mapi_low-can.lua | 34 +++++++++++++++++++++++++-------- test/afb-test/tests/mapi_tests.lua | 6 +++--- 3 files changed, 32 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d75b1c9..1dbb54d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ ########################################################################### -# Copyright 2015 - 2018 IoT.bzh +# Copyright 2015 - 2019 IoT.bzh # -# author: Romain Forlot +# author: Forlot Romain # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ # ----------------------------------------------------- PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN}) -ADD_TEST(NAME AFB-TEST_TESTS +ADD_TEST(NAME afTest_tests WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND afm-test "${CMAKE_BINARY_DIR}/package" "${CMAKE_BINARY_DIR}/package-test" SERVICE ) diff --git a/test/afb-test/fixtures/mapi_low-can.lua b/test/afb-test/fixtures/mapi_low-can.lua index 9909492..b88fc2f 100644 --- a/test/afb-test/fixtures/mapi_low-can.lua +++ b/test/afb-test/fixtures/mapi_low-can.lua @@ -26,16 +26,34 @@ function _unsubscribe(source, args) AFB:success(source) end +function _evtpush(source, context, val) + local event = val[0] + return AFB:evtpush(source, _evtHandles[event], val[1]) +end + function _get(source, args) - local evtHandle1 = AFB:evtmake(source, 'messages_engine_speed') - local evtHandle2 = AFB:evtmake(source, 'messages_vehicle_speed') - if type(evtHandle1) == "userdata" and type(evtHandle2) == "userdata" then - AFB:subscribe(source, evtHandle1) - AFB:evtpush(source,evtHandle1,{value = 1234}) - AFB:subscribe(source, evtHandle2) - AFB:evtpush(source,evtHandle2,{value = 5678}) - end + _evtHandles = {} + _messageHandles = {} + + _evtHandles['messages_engine_speed'] = nil + _evtHandles['messages_vehicle_speed'] = nil + + _messageHandles['messages_engine_speed'] = 1234 + _messageHandles['messages_vehicle_speed'] = 5678 + + for k,v in pairs(_messageHandles) do + if type(_evtHandles[k]) ~= "userdata" then + _evt = AFB:evtmake(source, k) + _evtHandles[k] = _evt + end + if type(_evtHandles[k]) == "userdata" then + AFB:subscribe(source, _evtHandles[k]) + AFB:timerset(source, {uid="evtpush_"..k, delay=1, count=1}, "_evtpush", {k, v}) + end + end + AFB:success(source) + end function _list(source, args) diff --git a/test/afb-test/tests/mapi_tests.lua b/test/afb-test/tests/mapi_tests.lua index e8cf142..2007c85 100644 --- a/test/afb-test/tests/mapi_tests.lua +++ b/test/afb-test/tests/mapi_tests.lua @@ -34,12 +34,12 @@ end) _AFT.describe("testLockWait",function() - local evt1 = "low-can/messages_engine_speed" + local evt1 = "low-can/messages_engine" + local evt2 = "low-can/messages_engine_not_receive" local timeout = 2000000 _AFT.addEventToMonitor(evt1) local start = os.time() * 1000000 - _AFT.assertEvtNotReceived(evt1, timeout) + _AFT.assertEvtNotReceived(evt2, timeout) local stop = os.time() * 1000000 - _AFT.assertIsTrue( (stop - start) >= timeout, "Timeout not reached, LockWait feature is not working." ) end, nil, nil) -- cgit 1.2.3-korg