Skip to content
Snippets Groups Projects
Unverified Commit eaeb865a authored by Sébastien Blin's avatar Sébastien Blin
Browse files

ut_syncHistory: fix testCreateConversationWithMessagesThenAddDevice

sendMessage is async, causing messages to be mixed before the assert

Change-Id: Ia08855a6a1516db2ee5acf01c166055831be80eb
parent d8545316
No related branches found
No related tags found
No related merge requests found
......@@ -208,11 +208,39 @@ void
SyncHistoryTest::testCreateConversationWithMessagesThenAddDevice()
{
auto aliceAccount = Manager::instance().getAccount<JamiAccount>(aliceId);
// Start conversation
auto convId = aliceAccount->startConversation();
std::mutex mtx;
std::unique_lock<std::mutex> lk {mtx};
std::condition_variable cv;
std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> confHandlers;
auto conversationReady = false;
auto messageReceived = false;
confHandlers.insert(DRing::exportable_callback<DRing::ConversationSignal::MessageReceived>(
[&](const std::string& accountId,
const std::string& /* conversationId */,
std::map<std::string, std::string> /*message*/) {
messageReceived = true;
cv.notify_one();
}));
confHandlers.insert(DRing::exportable_callback<DRing::ConversationSignal::ConversationReady>(
[&](const std::string& accountId, const std::string& conversationId) {
if (accountId == alice2Id && conversationId == convId) {
conversationReady = true;
cv.notify_one();
}
}));
DRing::registerSignalHandlers(confHandlers);
confHandlers.clear();
// Start conversation
messageReceived = false;
aliceAccount->sendMessage(convId, std::string("Message 1"));
CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(10), [&] { return messageReceived; }));
aliceAccount->sendMessage(convId, std::string("Message 2"));
CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(10), [&] { return messageReceived; }));
aliceAccount->sendMessage(convId, std::string("Message 3"));
CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(10), [&] { return messageReceived; }));
// Now create alice2
auto aliceArchive = std::filesystem::current_path().string() + "/alice.gz";
......@@ -228,21 +256,6 @@ SyncHistoryTest::testCreateConversationWithMessagesThenAddDevice()
details[ConfProperties::ARCHIVE_PATH] = aliceArchive;
alice2Id = Manager::instance().addAccount(details);
std::mutex mtx;
std::unique_lock<std::mutex> lk {mtx};
std::condition_variable cv;
std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> confHandlers;
auto conversationReady = false;
confHandlers.insert(DRing::exportable_callback<DRing::ConversationSignal::ConversationReady>(
[&](const std::string& accountId, const std::string& conversationId) {
if (accountId == alice2Id && conversationId == convId) {
conversationReady = true;
cv.notify_one();
}
}));
DRing::registerSignalHandlers(confHandlers);
confHandlers.clear();
// Check if conversation is ready
CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(60), [&]() { return conversationReady; }));
auto alice2Account = Manager::instance().getAccount<JamiAccount>(alice2Id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment