aboutsummaryrefslogtreecommitdiff
path: root/tests/quotest.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-06-10 08:31:43 +0200
committerKitsune Ral <Kitsune-Ral@users.sf.net>2020-06-10 15:06:47 +0200
commitf3b8dbe01a43c5334a371edda833173468d99dc4 (patch)
tree8121a01d4a1df5b84377cb5a33f213af861ab753 /tests/quotest.cpp
parent08f4490d4d770878f805d26bfe1d0ef9cb3f7393 (diff)
downloadlibquotient-f3b8dbe01a43c5334a371edda833173468d99dc4.tar.gz
libquotient-f3b8dbe01a43c5334a371edda833173468d99dc4.zip
Room: fix messageSent() being emitted too early
Closes #406.
Diffstat (limited to 'tests/quotest.cpp')
-rw-r--r--tests/quotest.cpp30
1 files changed, 22 insertions, 8 deletions
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();