From 3f58a12da394244137ba85249dd13d09cb07e927 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 9 Jun 2020 19:00:34 +0200 Subject: quotest: make sure to send all events before leaving --- tests/quotest.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/quotest.cpp b/tests/quotest.cpp index ae5ece30..fefd0182 100644 --- a/tests/quotest.cpp +++ b/tests/quotest.cpp @@ -639,18 +639,24 @@ void TestManager::conclude() // .then([this] { finalize(); }); // STL-style auto* room = testSuite->room(); auto txnId = room->postHtmlText(plainReport, htmlReport); - connect(room, &Room::messageSent, this, - [this, room, txnId](const QString& serverTxnId) { - if (txnId != serverTxnId) - return; + // Now just wait until all the pending events reach the server + connectUntil(room, &Room::messageSent, this, [this, room] { + const auto& pendingEvents = room->pendingEvents(); + if (std::any_of(pendingEvents.begin(), pendingEvents.end(), + [](const PendingEventItem& pe) { + return pe.deliveryStatus() + < EventStatus::ReachedServer; + })) + return false; - clog << "Leaving the room" << endl; - auto* job = room->leaveRoom(); - connect(job, &BaseJob::finished, this, [this, job] { - Q_ASSERT(job->status().good()); - finalize(); - }); - }); + clog << "Leaving the room" << endl; + auto* job = room->leaveRoom(); + connect(job, &BaseJob::finished, this, [this, job] { + Q_ASSERT(job->status().good()); + finalize(); + }); + return true; + }); } void TestManager::finalize() -- cgit v1.2.3 From 08f4490d4d770878f805d26bfe1d0ef9cb3f7393 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 10 Jun 2020 08:31:03 +0200 Subject: TestSuite::sendRedaction: fix a stale TODO Add another TODO instead :-| --- tests/quotest.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/quotest.cpp b/tests/quotest.cpp index fefd0182..79720812 100644 --- a/tests/quotest.cpp +++ b/tests/quotest.cpp @@ -357,10 +357,7 @@ TEST_IMPL(sendReaction) FAIL_TEST(); } - // TODO: Check that it came back as a reaction event and that it attached to - // the right event - connectUntil( - targetRoom, &Room::updatedEvent, this, + connectUntil(targetRoom, &Room::updatedEvent, this, [this, thisTest, txnId, key, targetEvtId](const QString& actualTargetEvtId) { if (actualTargetEvtId != targetEvtId) return false; @@ -376,6 +373,7 @@ TEST_IMPL(sendReaction) FINISH_TEST(is(*evt) && !evt->id().isEmpty() && evt->relation().key == key && evt->transactionId() == txnId); + // TODO: Test removing the reaction }); return false; } -- cgit v1.2.3 From f3b8dbe01a43c5334a371edda833173468d99dc4 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 10 Jun 2020 08:31:43 +0200 Subject: Room: fix messageSent() being emitted too early Closes #406. --- lib/room.cpp | 15 +++++++-------- tests/quotest.cpp | 30 ++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/lib/room.cpp b/lib/room.cpp index 23e07cae..22ec1c82 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1565,18 +1565,17 @@ QString Room::Private::doSendEvent(const RoomEvent* pEvent) std::bind(&Room::Private::onEventSendingFailure, this, txnId, call)); Room::connect(call, &BaseJob::success, q, [this, call, txnId] { - emit q->messageSent(txnId, call->eventId()); auto it = q->findPendingEvent(txnId); - if (it == unsyncedEvents.end()) { + if (it != unsyncedEvents.end()) { + if (it->deliveryStatus() != EventStatus::ReachedServer) { + it->setReachedServer(call->eventId()); + emit q->pendingEventChanged(int(it - unsyncedEvents.begin())); + } + } else qCDebug(EVENTS) << "Pending event for transaction" << txnId << "already merged"; - return; - } - if (it->deliveryStatus() != EventStatus::ReachedServer) { - it->setReachedServer(call->eventId()); - emit q->pendingEventChanged(int(it - unsyncedEvents.begin())); - } + emit q->messageSent(txnId, call->eventId()); }); } else onEventSendingFailure(txnId); diff --git a/tests/quotest.cpp b/tests/quotest.cpp index 79720812..e47bf651 100644 --- a/tests/quotest.cpp +++ b/tests/quotest.cpp @@ -493,18 +493,28 @@ TEST_IMPL(sendAndRedact) if (txnId.isEmpty()) FAIL_TEST(); - connect(targetRoom, &Room::messageSent, this, + connectUntil(targetRoom, &Room::messageSent, this, [this, thisTest, txnId](const QString& tId, const QString& evtId) { if (tId != txnId) - return; + return false; + + // The event may end up having been merged, and that's ok; + // but if it's not, it has to be in the ReachedServer state. + if (auto it = room()->findPendingEvent(tId); + it != room()->pendingEvents().cend() + && it->deliveryStatus() != EventStatus::ReachedServer) { + clog << "Incorrect sent event status (" + << it->deliveryStatus() << ')' << endl; + FAIL_TEST(); + } clog << "Redacting the message" << endl; targetRoom->redactEvent(evtId, origin); - connectUntil(targetRoom, &Room::addedMessages, this, [this, thisTest, evtId] { return checkRedactionOutcome(thisTest, evtId); }); + return false; }); return false; } @@ -640,12 +650,16 @@ void TestManager::conclude() // Now just wait until all the pending events reach the server connectUntil(room, &Room::messageSent, this, [this, room] { const auto& pendingEvents = room->pendingEvents(); - if (std::any_of(pendingEvents.begin(), pendingEvents.end(), - [](const PendingEventItem& pe) { - return pe.deliveryStatus() - < EventStatus::ReachedServer; - })) + if (auto c = std::count_if(pendingEvents.begin(), pendingEvents.end(), + [](const PendingEventItem& pe) { + return pe.deliveryStatus() + < EventStatus::ReachedServer; + }); + c > 0) { + clog << "Events to reach the server: " << c << ", not leaving yet" + << endl; return false; + } clog << "Leaving the room" << endl; auto* job = room->leaveRoom(); -- cgit v1.2.3