From 58e13d2b47a3b62a30b3eda19b6ad6fbfbec0d48 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Mon, 16 Dec 2024 16:22:08 +0100 Subject: [PATCH] Quotest: fix sendReaction test The test was occasionally hitting the same target message as the redaction test, with the reaction test waiting forever to see the reaction on the message that just got redacted (with reactions being erased from it as a result). --- quotest/quotest.cpp | 69 ++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/quotest/quotest.cpp b/quotest/quotest.cpp index d1539296..df43638f 100644 --- a/quotest/quotest.cpp +++ b/quotest/quotest.cpp @@ -398,44 +398,43 @@ TEST_IMPL(sendMessage) TEST_IMPL(sendReaction) { - clog << "Reacting to the newest message in the room" << endl; - Q_ASSERT(targetRoom->timelineSize() > 0); - const auto targetEvtId = targetRoom->messageEvents().back()->id(); - - // TODO: a separate test unit for reactionevent.h - if (loadEvent(RoomEvent::basicJson( - ReactionEvent::TypeId, - { { RelatesToKey, toJson(EventRelation::replace(targetEvtId)) } }))) { - clog << "ReactionEvent can be created with an invalid relation type" - << endl; - FAIL_TEST(); - } - - const auto key = u"+1"_s; - const auto txnId = targetRoom->postReaction(targetEvtId, key); - if (!validatePendingEvent(txnId)) { - clog << "Invalid pending event right after submitting" << endl; - FAIL_TEST(); - } + return targetRoom->post(u"Reaction target"_s) + .whenMerged() + .then([this, thisTest](const RoomEvent& targetEvt) { + const auto targetEvtId = targetEvt.id(); + clog << "Reacting to the message just sent to the room: " << targetEvtId.toStdString() + << endl; - connectUntil(targetRoom, &Room::updatedEvent, this, - [this, thisTest, txnId, key, targetEvtId](const QString& actualTargetEvtId) { - if (actualTargetEvtId != targetEvtId) - return false; - const auto reactions = targetRoom->relatedEvents( - targetEvtId, EventRelation::AnnotationType); - // It's a test room, assuming no interference there should - // be exactly one reaction - if (reactions.size() != 1) + // TODO: a separate test unit for reactionevent.h + if (loadEvent(RoomEvent::basicJson( + ReactionEvent::TypeId, + { { RelatesToKey, toJson(EventRelation::replace(targetEvtId)) } }))) { + clog << "ReactionEvent can be created with an invalid relation type" << endl; FAIL_TEST(); + } - const auto* evt = - eventCast(reactions.back()); - FINISH_TEST(is(*evt) && !evt->id().isEmpty() - && evt->key() == key && evt->transactionId() == txnId); - // TODO: Test removing the reaction - }); - return false; + const auto key = u"+"_s; + const auto txnId = targetRoom->postReaction(targetEvtId, key); + FAIL_TEST_IF(!validatePendingEvent(txnId), + "Invalid pending event right after submitting"); + + connectUntil(targetRoom, &Room::updatedEvent, this, + [this, thisTest, txnId, key, targetEvtId](const QString& actualTargetEvtId) { + if (actualTargetEvtId != targetEvtId) + return false; + const auto reactions = + targetRoom->relatedEvents(targetEvtId, + EventRelation::AnnotationType); + FAIL_TEST_IF(reactions.size() != 1); + + const auto* evt = eventCast(reactions.back()); + FINISH_TEST(is(*evt) && !evt->id().isEmpty() + && evt->key() == key && evt->transactionId() == txnId); + // TODO: Test removing the reaction + }); + return false; + }) + .isRunning(); } TEST_IMPL(sendFile)