From fb35a9a196252ce6177f1c6013f7ac5f3c65ee5f Mon Sep 17 00:00:00 2001 From: sangelovic Date: Sun, 17 May 2020 15:06:29 +0200 Subject: [PATCH] Fix integration test cases failing in specific situations --- .../integrationtests/AdaptorAndProxy_test.cpp | 44 ++++++++++++++++--- tests/integrationtests/adaptor-glue.h | 2 +- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/tests/integrationtests/AdaptorAndProxy_test.cpp b/tests/integrationtests/AdaptorAndProxy_test.cpp index ddd814f..bdbd644 100644 --- a/tests/integrationtests/AdaptorAndProxy_test.cpp +++ b/tests/integrationtests/AdaptorAndProxy_test.cpp @@ -71,7 +71,8 @@ public: s_connection->releaseName(INTERFACE_NAME); } - static bool waitUntil(std::atomic& flag, std::chrono::milliseconds timeout = 5s) + template + static bool waitUntil(_Fnc&& fnc, std::chrono::milliseconds timeout = 5s) { std::chrono::milliseconds elapsed{}; std::chrono::milliseconds step{5ms}; @@ -80,11 +81,16 @@ public: elapsed += step; if (elapsed > timeout) return false; - } while (!flag); + } while (!fnc()); return true; } + static bool waitUntil(std::atomic& flag, std::chrono::milliseconds timeout = 5s) + { + return waitUntil([&flag]() -> bool { return flag; }, timeout); + } + private: void SetUp() override { @@ -110,6 +116,8 @@ std::unique_ptr AdaptorAndProxyFixture::s_connection = sdbus } +using SdbusTestObject = AdaptorAndProxyFixture; + /*-------------------------------------*/ /* -- TEST CASES -- */ /*-------------------------------------*/ @@ -127,8 +135,6 @@ TEST(AdaptorAndProxy, CanBeConstructedSuccesfully) // Methods -using SdbusTestObject = AdaptorAndProxyFixture; - TEST_F(SdbusTestObject, CallsEmptyMethodSuccesfully) { ASSERT_NO_THROW(m_proxy->noArgNoReturn()); @@ -427,7 +433,7 @@ TEST_F(SdbusTestObject, AnswersThatAsyncCallIsNotPendingAfterItHasBeenCompleted) auto call = m_proxy->doOperationClientSideAsync(0); (void) future.get(); // Wait for the call to finish - ASSERT_FALSE(call.isPending()); + ASSERT_TRUE(waitUntil([&call](){ return !call.isPending(); })); } TEST_F(SdbusTestObject, InvokesErroneousMethodAsynchronouslyOnClientSide) @@ -679,7 +685,20 @@ TEST_F(SdbusTestObject, EmitsInterfacesAddedSignalForSelectedObjectInterfaces) EXPECT_THAT(objectPath, Eq(OBJECT_PATH)); EXPECT_THAT(interfacesAndProperties, SizeIs(1)); EXPECT_THAT(interfacesAndProperties.count(INTERFACE_NAME), Eq(1)); +#if LIBSYSTEMD_VERSION<=244 + // Up to sd-bus v244, all properties are added to the list, i.e. `state', `action', and `blocking' in this case. EXPECT_THAT(interfacesAndProperties.at(INTERFACE_NAME), SizeIs(3)); + EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count("state")); + EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count("action")); + EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count("blocking")); +#else + // Since v245 sd-bus does not add to the InterfacesAdded signal message the values of properties marked only + // for invalidation on change, which makes the behavior consistent with the PropertiesChangedSignal. + // So in this specific instance, `action' property is no more added to the list. + EXPECT_THAT(interfacesAndProperties.at(INTERFACE_NAME), SizeIs(2)); + EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count("state")); + EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count("blocking")); +#endif signalReceived = true; }; @@ -696,7 +715,20 @@ TEST_F(SdbusTestObject, EmitsInterfacesAddedSignalForAllObjectInterfaces) { EXPECT_THAT(objectPath, Eq(OBJECT_PATH)); EXPECT_THAT(interfacesAndProperties, SizeIs(5)); // INTERFACE_NAME + 4 standard interfaces - EXPECT_THAT(interfacesAndProperties.at(INTERFACE_NAME), SizeIs(3)); // 3 properties under INTERFACE_NAME +#if LIBSYSTEMD_VERSION<=244 + // Up to sd-bus v244, all properties are added to the list, i.e. `state', `action', and `blocking' in this case. + EXPECT_THAT(interfacesAndProperties.at(INTERFACE_NAME), SizeIs(3)); + EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count("state")); + EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count("action")); + EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count("blocking")); +#else + // Since v245 sd-bus does not add to the InterfacesAdded signal message the values of properties marked only + // for invalidation on change, which makes the behavior consistent with the PropertiesChangedSignal. + // So in this specific instance, `action' property is no more added to the list. + EXPECT_THAT(interfacesAndProperties.at(INTERFACE_NAME), SizeIs(2)); + EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count("state")); + EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count("blocking")); +#endif signalReceived = true; }; diff --git a/tests/integrationtests/adaptor-glue.h b/tests/integrationtests/adaptor-glue.h index ba01cda..edfd6e6 100644 --- a/tests/integrationtests/adaptor-glue.h +++ b/tests/integrationtests/adaptor-glue.h @@ -111,7 +111,7 @@ protected: // registration of signals is optional, it is useful because of introspection object_.registerSignal("simpleSignal").onInterface(INTERFACE_NAME).markAsDeprecated(); - // Note: sd-bus of libsystemd up to v244 has a bug where it doesn't generate signal parameter names in introspection XML. Signal param names commented temporarily. + // Note: sd-bus of libsystemd up to (including) v244 has a bug where it doesn't generate signal parameter names in introspection XML. Signal param names commented temporarily. object_.registerSignal("signalWithMap").onInterface(INTERFACE_NAME).withParameters>(/*"aMap"*/); object_.registerSignal("signalWithVariant").onInterface(INTERFACE_NAME).withParameters(/*"aVariant"*/);