From c46663aece5e001543b07d3ed901e64c38be4172 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 12 Dec 2018 13:20:46 +0900 Subject: qmc-example: Use lazy-loading; check full-loading upon setDisplayed --- examples/qmc-example.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'examples') diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp index 9c86d4a9..bdb9ef3f 100644 --- a/examples/qmc-example.cpp +++ b/examples/qmc-example.cpp @@ -26,6 +26,7 @@ class QMCTest : public QObject void setup(const QString& testRoomName); void onNewRoom(Room* r); void startTests(); + void loadMembers(); void sendMessage(); void addAndRemoveTag(); void sendAndRedact(); @@ -80,6 +81,7 @@ void QMCTest::setup(const QString& testRoomName) cout << "Access token: " << c->accessToken().toStdString() << endl; // Setting up sync loop + c->setLazyLoading(true); c->sync(); connect(c.data(), &Connection::syncDone, c.data(), [this,testRoomName] { cout << "Sync complete, " @@ -142,12 +144,41 @@ void QMCTest::onNewRoom(Room* r) void QMCTest::startTests() { cout << "Starting tests" << endl; + loadMembers(); sendMessage(); addAndRemoveTag(); sendAndRedact(); markDirectChat(); } +void QMCTest::loadMembers() +{ + running.push_back("Loading members"); + // The dedicated qmc-test room is too small to test + // lazy-loading-then-full-loading; use #test:matrix.org instead. + // TODO: #264 + auto* r = c->room(QStringLiteral("!vfFxDRtZSSdspfTSEr:matrix.org")); + if (!r) + { + cout << "#test:matrix.org is not found in the test user's rooms" << endl; + QMC_CHECK("Loading members", false); + return; + } + // It's not exactly correct because an arbitrary server might not support + // lazy loading; but in the absence of capabilities framework we assume + // it does. + if (r->memberNames().size() < r->joinedCount()) + { + cout << "Lazy loading doesn't seem to be enabled" << endl; + QMC_CHECK("Loading members", false); + return; + } + r->setDisplayed(); + connect(r, &Room::allMembersLoaded, [this] { + QMC_CHECK("Loading members", true); + }); +} + void QMCTest::sendMessage() { running.push_back("Message sending"); -- cgit v1.2.3 From cf4759edba82baf51dd40285d2e13b200ca7fd29 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 13 Dec 2018 15:54:02 +0900 Subject: qmc-example: Fix the lazy-loading test --- examples/qmc-example.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp index bdb9ef3f..e66687da 100644 --- a/examples/qmc-example.cpp +++ b/examples/qmc-example.cpp @@ -83,6 +83,8 @@ void QMCTest::setup(const QString& testRoomName) // Setting up sync loop c->setLazyLoading(true); c->sync(); + connectSingleShot(c.data(), &Connection::syncDone, + this, &QMCTest::startTests); connect(c.data(), &Connection::syncDone, c.data(), [this,testRoomName] { cout << "Sync complete, " << running.size() << " tests in the air" << endl; @@ -116,7 +118,6 @@ void QMCTest::setup(const QString& testRoomName) targetRoom = room; QMC_CHECK("Join room", true); - startTests(); }); } } @@ -167,15 +168,16 @@ void QMCTest::loadMembers() // It's not exactly correct because an arbitrary server might not support // lazy loading; but in the absence of capabilities framework we assume // it does. - if (r->memberNames().size() < r->joinedCount()) + if (r->memberNames().size() >= r->joinedCount()) { cout << "Lazy loading doesn't seem to be enabled" << endl; QMC_CHECK("Loading members", false); return; } r->setDisplayed(); - connect(r, &Room::allMembersLoaded, [this] { - QMC_CHECK("Loading members", true); + connect(r, &Room::allMembersLoaded, [this,r] { + QMC_CHECK("Loading members", + r->memberNames().size() + 1 >= r->joinedCount()); }); } -- cgit v1.2.3 From 12a0b95fdcfea15cd0ef313aec8868656629b986 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 14 Dec 2018 12:33:04 +0900 Subject: qmc-example: clearer QMC_CHECK; start tests only after the first sync is done Because lazy-loading test is executed on a room different from the test room. --- examples/qmc-example.cpp | 93 ++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 43 deletions(-) (limited to 'examples') diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp index e66687da..48787e44 100644 --- a/examples/qmc-example.cpp +++ b/examples/qmc-example.cpp @@ -20,10 +20,10 @@ using namespace std::placeholders; class QMCTest : public QObject { public: - QMCTest(Connection* conn, const QString& testRoomName, QString source); + QMCTest(Connection* conn, QString testRoomName, QString source); private slots: - void setup(const QString& testRoomName); + void setup(); void onNewRoom(Room* r); void startTests(); void loadMembers(); @@ -44,37 +44,45 @@ class QMCTest : public QObject QStringList succeeded; QStringList failed; QString origin; + QString testRoomName; Room* targetRoom = nullptr; }; #define QMC_CHECK(description, condition) \ { \ - const bool result = !!(condition); \ Q_ASSERT(running.removeOne(description)); \ - (result ? succeeded : failed).push_back(description); \ - cout << (description) << (result ? " successul" : " FAILED") << endl; \ - if (targetRoom) \ - targetRoom->postMessage(origin % ": " % QStringLiteral(description) % \ - (result ? QStringLiteral(" successful") : QStringLiteral(" FAILED")), \ - result ? MessageEventType::Notice : MessageEventType::Text); \ + if (!!(condition)) \ + { \ + succeeded.push_back(description); \ + cout << (description) << " successful" << endl; \ + if (targetRoom) \ + targetRoom->postMessage( \ + origin % ": " % (description) % " successful", \ + MessageEventType::Notice); \ + } else { \ + failed.push_back(description); \ + cout << (description) << " FAILED" << endl; \ + if (targetRoom) \ + targetRoom->postPlainText( \ + origin % ": " % (description) % " FAILED"); \ + } \ } -QMCTest::QMCTest(Connection* conn, const QString& testRoomName, QString source) - : c(conn), origin(std::move(source)) +QMCTest::QMCTest(Connection* conn, QString testRoomName, QString source) + : c(conn), origin(std::move(source)), testRoomName(std::move(testRoomName)) { if (!origin.isEmpty()) cout << "Origin for the test message: " << origin.toStdString() << endl; if (!testRoomName.isEmpty()) cout << "Test room name: " << testRoomName.toStdString() << endl; - connect(c.data(), &Connection::connected, - this, std::bind(&QMCTest::setup, this, testRoomName)); + connect(c.data(), &Connection::connected, this, &QMCTest::setup); connect(c.data(), &Connection::loadedRoomState, this, &QMCTest::onNewRoom); // Big countdown watchdog QTimer::singleShot(180000, this, &QMCTest::leave); } -void QMCTest::setup(const QString& testRoomName) +void QMCTest::setup() { cout << "Connected, server: " << c->homeserver().toDisplayString().toStdString() << endl; @@ -85,7 +93,7 @@ void QMCTest::setup(const QString& testRoomName) c->sync(); connectSingleShot(c.data(), &Connection::syncDone, this, &QMCTest::startTests); - connect(c.data(), &Connection::syncDone, c.data(), [this,testRoomName] { + connect(c.data(), &Connection::syncDone, c.data(), [this] { cout << "Sync complete, " << running.size() << " tests in the air" << endl; if (!running.isEmpty()) @@ -98,28 +106,6 @@ void QMCTest::setup(const QString& testRoomName) else finalize(); }); - - // Join a testroom, if provided - if (!targetRoom && !testRoomName.isEmpty()) - { - cout << "Joining " << testRoomName.toStdString() << endl; - running.push_back("Join room"); - auto joinJob = c->joinRoom(testRoomName); - connect(joinJob, &BaseJob::failure, this, - [this] { QMC_CHECK("Join room", false); finalize(); }); - // As of BaseJob::success, a Room object is not guaranteed to even - // exist; it's a mere confirmation that the server processed - // the request. - connect(c.data(), &Connection::loadedRoomState, this, - [this,testRoomName] (Room* room) { - Q_ASSERT(room); // It's a grave failure if room is nullptr here - if (room->canonicalAlias() != testRoomName) - return; // Not our room - - targetRoom = room; - QMC_CHECK("Join room", true); - }); - } } void QMCTest::onNewRoom(Room* r) @@ -144,12 +130,33 @@ void QMCTest::onNewRoom(Room* r) void QMCTest::startTests() { - cout << "Starting tests" << endl; - loadMembers(); - sendMessage(); - addAndRemoveTag(); - sendAndRedact(); - markDirectChat(); + if (testRoomName.isEmpty()) + return; + + cout << "Joining " << testRoomName.toStdString() << endl; + running.push_back("Join room"); + auto joinJob = c->joinRoom(testRoomName); + connect(joinJob, &BaseJob::failure, this, + [this] { QMC_CHECK("Join room", false); finalize(); }); + // As of BaseJob::success, a Room object is not guaranteed to even + // exist; it's a mere confirmation that the server processed + // the request. + connect(c.data(), &Connection::loadedRoomState, this, + [this] (Room* room) { + Q_ASSERT(room); // It's a grave failure if room is nullptr here + if (room->canonicalAlias() != testRoomName) + return; // Not our room + + targetRoom = room; + QMC_CHECK("Join room", true); + cout << "Starting tests" << endl; + + loadMembers(); + sendMessage(); + addAndRemoveTag(); + sendAndRedact(); + markDirectChat(); + }); } void QMCTest::loadMembers() -- cgit v1.2.3