From 63c953800330017ebb2afbabf41e5c4932c4d640 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sat, 22 Jan 2022 13:43:15 +0100 Subject: Quotest: fix changeName test This test was very unreliable because memberRenamed() signal was emitted upon lazy-loading of past member renames. The new code connects to aboutToAddNewMessages() instead, which should only contain the latest renaming event (past events are delivered in the 'state' object). --- quotest/quotest.cpp | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'quotest/quotest.cpp') diff --git a/quotest/quotest.cpp b/quotest/quotest.cpp index 40bc456b..792faabd 100644 --- a/quotest/quotest.cpp +++ b/quotest/quotest.cpp @@ -14,6 +14,7 @@ #include "events/reactionevent.h" #include "events/redactionevent.h" #include "events/simplestateevents.h" +#include "events/roommemberevent.h" #include #include @@ -592,25 +593,31 @@ TEST_IMPL(changeName) clog << "Renaming the user to " << newName.toStdString() << " in the target room" << endl; localUser->rename(newName, targetRoom); - connectUntil(targetRoom, &Room::memberRenamed, this, - [this, thisTest, localUser, newName](const User* u) { - if (localUser != u) - return false; - if (localUser->name(targetRoom) != newName) - FAIL_TEST(); - - clog - << "Member rename successful, renaming the account" + connectUntil( + targetRoom, &Room::aboutToAddNewMessages, this, + [this, thisTest, localUser, newName](const RoomEventsRange& evts) { + for (const auto& e : evts) { + if (const auto* rme = eventCast(e)) { + if (rme->stateKey() != localUser->id() + || !rme->isRename()) + continue; + if (!rme->newDisplayName() + || *rme->newDisplayName() != newName) + FAIL_TEST(); + clog << "Member rename successful, renaming the account" << endl; - const auto newN = newName.mid(0, 5); - localUser->rename(newN); - connectUntil(localUser, &User::defaultNameChanged, - this, [this, thisTest, localUser, newN] { - targetRoom->localUser()->rename({}); - FINISH_TEST(localUser->name() == newN); - }); - return true; - }); + const auto newN = newName.mid(0, 5); + localUser->rename(newN); + connectUntil(localUser, &User::defaultNameChanged, this, + [this, thisTest, localUser, newN] { + targetRoom->localUser()->rename({}); + FINISH_TEST(localUser->name() == newN); + }); + return true; + } + } + return false; + }); }); return false; } -- cgit v1.2.3