Fix integration test cases failing in specific situations

This commit is contained in:
sangelovic
2020-05-17 15:06:29 +02:00
parent 6cbd49ddaa
commit fb35a9a196
2 changed files with 39 additions and 7 deletions

View File

@ -71,7 +71,8 @@ public:
s_connection->releaseName(INTERFACE_NAME); s_connection->releaseName(INTERFACE_NAME);
} }
static bool waitUntil(std::atomic<bool>& flag, std::chrono::milliseconds timeout = 5s) template <typename _Fnc>
static bool waitUntil(_Fnc&& fnc, std::chrono::milliseconds timeout = 5s)
{ {
std::chrono::milliseconds elapsed{}; std::chrono::milliseconds elapsed{};
std::chrono::milliseconds step{5ms}; std::chrono::milliseconds step{5ms};
@ -80,11 +81,16 @@ public:
elapsed += step; elapsed += step;
if (elapsed > timeout) if (elapsed > timeout)
return false; return false;
} while (!flag); } while (!fnc());
return true; return true;
} }
static bool waitUntil(std::atomic<bool>& flag, std::chrono::milliseconds timeout = 5s)
{
return waitUntil([&flag]() -> bool { return flag; }, timeout);
}
private: private:
void SetUp() override void SetUp() override
{ {
@ -110,6 +116,8 @@ std::unique_ptr<sdbus::IConnection> AdaptorAndProxyFixture::s_connection = sdbus
} }
using SdbusTestObject = AdaptorAndProxyFixture;
/*-------------------------------------*/ /*-------------------------------------*/
/* -- TEST CASES -- */ /* -- TEST CASES -- */
/*-------------------------------------*/ /*-------------------------------------*/
@ -127,8 +135,6 @@ TEST(AdaptorAndProxy, CanBeConstructedSuccesfully)
// Methods // Methods
using SdbusTestObject = AdaptorAndProxyFixture;
TEST_F(SdbusTestObject, CallsEmptyMethodSuccesfully) TEST_F(SdbusTestObject, CallsEmptyMethodSuccesfully)
{ {
ASSERT_NO_THROW(m_proxy->noArgNoReturn()); ASSERT_NO_THROW(m_proxy->noArgNoReturn());
@ -427,7 +433,7 @@ TEST_F(SdbusTestObject, AnswersThatAsyncCallIsNotPendingAfterItHasBeenCompleted)
auto call = m_proxy->doOperationClientSideAsync(0); auto call = m_proxy->doOperationClientSideAsync(0);
(void) future.get(); // Wait for the call to finish (void) future.get(); // Wait for the call to finish
ASSERT_FALSE(call.isPending()); ASSERT_TRUE(waitUntil([&call](){ return !call.isPending(); }));
} }
TEST_F(SdbusTestObject, InvokesErroneousMethodAsynchronouslyOnClientSide) TEST_F(SdbusTestObject, InvokesErroneousMethodAsynchronouslyOnClientSide)
@ -679,7 +685,20 @@ TEST_F(SdbusTestObject, EmitsInterfacesAddedSignalForSelectedObjectInterfaces)
EXPECT_THAT(objectPath, Eq(OBJECT_PATH)); EXPECT_THAT(objectPath, Eq(OBJECT_PATH));
EXPECT_THAT(interfacesAndProperties, SizeIs(1)); EXPECT_THAT(interfacesAndProperties, SizeIs(1));
EXPECT_THAT(interfacesAndProperties.count(INTERFACE_NAME), Eq(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_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; signalReceived = true;
}; };
@ -696,7 +715,20 @@ TEST_F(SdbusTestObject, EmitsInterfacesAddedSignalForAllObjectInterfaces)
{ {
EXPECT_THAT(objectPath, Eq(OBJECT_PATH)); EXPECT_THAT(objectPath, Eq(OBJECT_PATH));
EXPECT_THAT(interfacesAndProperties, SizeIs(5)); // INTERFACE_NAME + 4 standard interfaces 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; signalReceived = true;
}; };

View File

@ -111,7 +111,7 @@ protected:
// registration of signals is optional, it is useful because of introspection // registration of signals is optional, it is useful because of introspection
object_.registerSignal("simpleSignal").onInterface(INTERFACE_NAME).markAsDeprecated(); 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<std::map<int32_t, std::string>>(/*"aMap"*/); object_.registerSignal("signalWithMap").onInterface(INTERFACE_NAME).withParameters<std::map<int32_t, std::string>>(/*"aMap"*/);
object_.registerSignal("signalWithVariant").onInterface(INTERFACE_NAME).withParameters<sdbus::Variant>(/*"aVariant"*/); object_.registerSignal("signalWithVariant").onInterface(INTERFACE_NAME).withParameters<sdbus::Variant>(/*"aVariant"*/);