Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the redaction test in Quotest #841

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions quotest/quotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,18 @@ TEST_IMPL(setTopic)
return false;
}

// TODO: maybe move it to Room?..
QFuture<void> ensureEvent(Room* room, const QString& evtId, QPromise<void>&& p = QPromise<void>{})
{
auto future = p.future();
if (room->findInTimeline(evtId) == room->historyEdge()) {
clog << "Loading a page of history, " << room->timelineSize() << " events so far\n";
room->getPreviousContent().then(std::bind_front(ensureEvent, room, evtId, std::move(p)));
} else
p.finish();
return future;
}

TEST_IMPL(redactEvent)
{
using TargetEventType = RoomMemberEvent;
Expand All @@ -587,20 +599,25 @@ TEST_IMPL(redactEvent)
Q_ASSERT(memberEventToRedact); // ...or the room state is totally screwed
const auto& evtId = memberEventToRedact->id();

clog << "Redacting the latest member event" << endl;
targetRoom->redactEvent(evtId, origin);
connectUntil(targetRoom, &Room::addedMessages, this, [this, thisTest, evtId] {
auto it = targetRoom->findInTimeline(evtId);
if (it == targetRoom->historyEdge())
return false; // Waiting for the next sync

FINISH_TEST((*it)->switchOnType([this](const TargetEventType& e) {
return e.redactionReason() == origin
&& e.membership() == Membership::Join;
// The second condition above tests MSC2176 - if it's violated (pre
// 0.8 beta), membership() ends up being Membership::Undefined
}));
// Make sure the event is loaded in the timeline before proceeding with the test, to make sure
// the replacement tracked below actually occurs
ensureEvent(targetRoom, evtId).then([this, thisTest, evtId] {
clog << "Redacting the latest member event" << endl;
targetRoom->redactEvent(evtId, origin);
connectUntil(targetRoom, &Room::replacedEvent, this,
[this, thisTest, evtId](const RoomEvent* evt) {
// Concurrent replacement/redaction shouldn't happen as of now; but if/when
// event editing is added to the test suite, this may become a thing
if (evt->id() != evtId)
return false;
FINISH_TEST(evt->switchOnType([this](const TargetEventType& e) {
return e.redactionReason() == origin && e.membership() == Membership::Join;
// The second condition above tests MSC2176 - if it's violated (pre 0.8
// beta), membership() ends up being Membership::Undefined
}));
});
});

return false;
}

Expand Down