From b28d4cf578f4ceabb0d40f65e55ac533027e8733 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 27 Apr 2017 15:52:56 +0200 Subject: We get an offline status notification initially --- tests/notificationtest.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/notificationtest.cpp b/tests/notificationtest.cpp index a34d325..e268a17 100644 --- a/tests/notificationtest.cpp +++ b/tests/notificationtest.cpp @@ -67,12 +67,22 @@ private slots: VERIFYEXEC(Sink::Store::synchronize(query)); VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); - QVERIFY(statusNotifications.size() <= 3); - QTRY_COMPARE(statusNotifications.size(), 3); - //Sync - QCOMPARE(statusNotifications.at(0).code, static_cast(ApplicationDomain::Status::ConnectedStatus)); - QCOMPARE(statusNotifications.at(1).code, static_cast(ApplicationDomain::Status::BusyStatus)); - QCOMPARE(statusNotifications.at(2).code, static_cast(ApplicationDomain::Status::ConnectedStatus)); + using namespace Sink::ApplicationDomain; + { + QList expected = { + Status::OfflineStatus, + Status::ConnectedStatus, + Status::BusyStatus, + Status::ConnectedStatus + }; + qInfo() << "Received notifications " << statusNotifications; + QVERIFY2(statusNotifications.size() <= expected.size(), "More notifications than expected."); + QTRY_COMPARE(statusNotifications.size(), expected.size()); + qInfo() << "All received notifications " << statusNotifications; + for (auto i = 0; i < statusNotifications.size(); i++) { + QCOMPARE(statusNotifications.at(i).code, static_cast(expected.at(i))); + } + } //Changereplay // It can happen that we get a changereplay notification pair first and then a second one at the end, // we therefore currently filter all changereplay notifications (see above). -- cgit v1.2.3 From a4ce2b2eda8a2fea4263017e6868c327f22f5e47 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 28 Apr 2017 12:19:52 +0200 Subject: Removed the template argument from the write property mapper --- tests/domainadaptortest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index a17152e..c5f6e3b 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp @@ -19,7 +19,7 @@ class TestFactory : public DomainTypeAdaptorFactory>::create(); + mResourceWriteMapper = QSharedPointer::create(); Sink::ApplicationDomain::TypeImplementation::configure(*mResourceWriteMapper); } }; @@ -29,7 +29,7 @@ class TestMailFactory : public DomainTypeAdaptorFactory>::create(); + mResourceWriteMapper = QSharedPointer::create(); Sink::ApplicationDomain::TypeImplementation::configure(*mResourceWriteMapper); } }; @@ -51,7 +51,7 @@ private slots: void testCreateBufferPart() { - auto writeMapper = QSharedPointer>::create(); + auto writeMapper = QSharedPointer::create(); Sink::ApplicationDomain::TypeImplementation::configure(*writeMapper); Sink::ApplicationDomain::Event event; @@ -104,7 +104,7 @@ private slots: void testMail() { - auto writeMapper = QSharedPointer>::create(); + auto writeMapper = QSharedPointer::create(); Sink::ApplicationDomain::TypeImplementation::configure(*writeMapper); Sink::ApplicationDomain::Mail mail; -- cgit v1.2.3 From a08984c450b1cd2584272b0d57a2f95ae3d074c3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 28 Apr 2017 15:25:47 +0200 Subject: Removed the resource mapper --- tests/domainadaptortest.cpp | 8 ++------ tests/testimplementations.h | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index c5f6e3b..2b7455a 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp @@ -14,23 +14,19 @@ #include "metadata_generated.h" #include "entity_generated.h" -class TestFactory : public DomainTypeAdaptorFactory +class TestFactory : public DomainTypeAdaptorFactory { public: TestFactory() { - mResourceWriteMapper = QSharedPointer::create(); - Sink::ApplicationDomain::TypeImplementation::configure(*mResourceWriteMapper); } }; -class TestMailFactory : public DomainTypeAdaptorFactory +class TestMailFactory : public DomainTypeAdaptorFactory { public: TestMailFactory() { - mResourceWriteMapper = QSharedPointer::create(); - Sink::ApplicationDomain::TypeImplementation::configure(*mResourceWriteMapper); } }; diff --git a/tests/testimplementations.h b/tests/testimplementations.h index a145265..ff9d9b8 100644 --- a/tests/testimplementations.h +++ b/tests/testimplementations.h @@ -33,7 +33,7 @@ #include "mail_generated.h" #include "createentity_generated.h" -class TestEventAdaptorFactory : public DomainTypeAdaptorFactory +class TestEventAdaptorFactory : public DomainTypeAdaptorFactory { public: TestEventAdaptorFactory() : DomainTypeAdaptorFactory() @@ -43,7 +43,7 @@ public: virtual ~TestEventAdaptorFactory(){}; }; -class TestMailAdaptorFactory : public DomainTypeAdaptorFactory +class TestMailAdaptorFactory : public DomainTypeAdaptorFactory { public: TestMailAdaptorFactory() : DomainTypeAdaptorFactory() -- cgit v1.2.3 From ca5020095abfb76e63bd801e9722c07193eb05f5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 28 Apr 2017 15:29:18 +0200 Subject: A single propertymapper for both directions --- tests/domainadaptortest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index 2b7455a..df44819 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp @@ -47,7 +47,7 @@ private slots: void testCreateBufferPart() { - auto writeMapper = QSharedPointer::create(); + auto writeMapper = QSharedPointer::create(); Sink::ApplicationDomain::TypeImplementation::configure(*writeMapper); Sink::ApplicationDomain::Event event; @@ -100,7 +100,7 @@ private slots: void testMail() { - auto writeMapper = QSharedPointer::create(); + auto writeMapper = QSharedPointer::create(); Sink::ApplicationDomain::TypeImplementation::configure(*writeMapper); Sink::ApplicationDomain::Mail mail; -- cgit v1.2.3 From 8eab2b67fdf83c657f996debfc238703a78b337b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 5 May 2017 10:42:28 +0200 Subject: Don't leak transactions when copying them. Previsouly we would hit the maxreaders limit --- tests/storagetest.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 7202628..dfb91ec 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -487,6 +487,24 @@ private slots: } } + void testCopyTransaction() + { + Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite); + { + auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite); + transaction.openDatabase("a", nullptr, false); + transaction.openDatabase("b", nullptr, false); + transaction.openDatabase("c", nullptr, false); + transaction.commit(); + } + auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); + for (int i = 0; i < 1000; i++) { + transaction.openDatabase("a", nullptr, false); + transaction.openDatabase("b", nullptr, false); + transaction.openDatabase("c", nullptr, false); + transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); + } + } }; QTEST_MAIN(StorageTest) -- cgit v1.2.3 From 3657dcd309f30b704801dcaf3e43b71ef703c0de Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 7 May 2017 11:27:40 +0200 Subject: Somewhat useless stress test... --- tests/CMakeLists.txt | 3 +++ tests/dbwriter.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ tests/storagetest.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tests/dbwriter.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c77a736..2b3e7b1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,6 +16,9 @@ add_library(sink_test SHARED testimplementations.cpp getrssusage.cpp mailtest.cp qt5_use_modules(sink_test Core Test Concurrent) target_link_libraries(sink_test sink libhawd KF5::Mime) +add_executable(dbwriter dbwriter.cpp) +target_link_libraries(dbwriter sink) + include(SinkTest) manual_tests ( diff --git a/tests/dbwriter.cpp b/tests/dbwriter.cpp new file mode 100644 index 0000000..902a607 --- /dev/null +++ b/tests/dbwriter.cpp @@ -0,0 +1,45 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + + QByteArrayList arguments; + for (int i = 0; i < argc; i++) { + arguments << argv[i]; + } + auto testDataPath = arguments.value(1); + auto dbName = arguments.value(2); + auto count = arguments.value(3).toInt(); + + if (Sink::Storage::DataStore(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly).exists()) { + Sink::Storage::DataStore(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite).removeFromDisk(); + } + + qWarning() << "Creating db: " << testDataPath << dbName << count; + Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite); + for (int i = 0; i < count; i++) { + if (!transaction) { + qWarning() << "No valid transaction"; + return -1; + } + transaction.openDatabase("a", nullptr, false).write(QByteArray::number(i), "a"); + transaction.openDatabase("b", nullptr, false).write(QByteArray::number(i), "b"); + transaction.openDatabase("c", nullptr, false).write(QByteArray::number(i), "c"); + transaction.openDatabase("p", nullptr, false).write(QByteArray::number(i), "c"); + transaction.openDatabase("q", nullptr, false).write(QByteArray::number(i), "c"); + if (i > (count/2)) { + for (int d = 0; d < 40; d++) { + transaction.openDatabase("db" + QByteArray::number(d), nullptr, false).write(QByteArray::number(i), "a"); + } + } + if ((i % 1000) == 0) { + transaction.commit(); + transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite); + } + } + qWarning() << "Creating db done."; + return 0; +} diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index dfb91ec..9e9bad9 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -505,6 +505,43 @@ private slots: transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); } } + + /* + * This test is meant to find problems with the multi-process architecture and initial database creation. + * If we create named databases dynamically (not all up front), it is possilbe that we violate the rule + * that mdb_open_dbi may only be used by a single thread at a time. + * This test is meant to stress that condition. + * + * However, it yields absolutely nothing. + */ + void testReadDuringExternalProcessWrite() + { + QSKIP("Not running multiprocess test"); + + QList> futures; + for (int i = 0; i < 5; i++) { + futures << QtConcurrent::run([&]() { + QTRY_VERIFY(Sink::Storage::DataStore(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly).exists()); + Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly); + auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); + for (int i = 0; i < 100000; i++) { + transaction.openDatabase("a", nullptr, false); + transaction.openDatabase("b", nullptr, false); + transaction.openDatabase("c", nullptr, false); + transaction.openDatabase("p", nullptr, false); + transaction.openDatabase("q", nullptr, false); + } + }); + } + + //Start writing to the db from a separate process + QVERIFY(QProcess::startDetached(QCoreApplication::applicationDirPath() + "/dbwriter", QStringList() << testDataPath << dbName << QString::number(100000))); + + for (auto future : futures) { + future.waitForFinished(); + } + + } }; QTEST_MAIN(StorageTest) -- cgit v1.2.3 From 32a2d9b61193db0a3f7ab6f45113c7d3d1ce6a92 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 8 May 2017 23:38:36 +0200 Subject: Fixed warnings --- tests/hawd/state.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/hawd/state.cpp b/tests/hawd/state.cpp index dfeef41..46b5f28 100644 --- a/tests/hawd/state.cpp +++ b/tests/hawd/state.cpp @@ -117,7 +117,7 @@ void State::findGitHash() { #ifdef HAVE_LIBGIT2 git_libgit2_init(); - git_buf root = {0}; + git_buf root; int error = git_repository_discover(&root, projectPath().toStdString().data(), 0, NULL); if (!error) { git_repository *repo = NULL; -- cgit v1.2.3 From bebbc07a1c517fd9020a83a5de3efcca5b0dccca Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 11 May 2017 11:58:15 +0200 Subject: Fixed benchmark --- tests/hawd/state.cpp | 2 +- tests/mailquerybenchmark.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/hawd/state.cpp b/tests/hawd/state.cpp index 46b5f28..dfeef41 100644 --- a/tests/hawd/state.cpp +++ b/tests/hawd/state.cpp @@ -117,7 +117,7 @@ void State::findGitHash() { #ifdef HAVE_LIBGIT2 git_libgit2_init(); - git_buf root; + git_buf root = {0}; int error = git_repository_discover(&root, projectPath().toStdString().data(), 0, NULL); if (!error) { git_repository *repo = NULL; diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp index b15c8d6..00c156d 100644 --- a/tests/mailquerybenchmark.cpp +++ b/tests/mailquerybenchmark.cpp @@ -78,7 +78,7 @@ class MailQueryBenchmark : public QObject entityStore.commitTransaction(); } - void testLoad(const Sink::Query &query, int count, int expectedSize) + void testLoad(const QByteArray &name, const Sink::Query &query, int count, int expectedSize) { const auto startingRss = getCurrentRSS(); @@ -124,7 +124,7 @@ class MailQueryBenchmark : public QObject std::cout << "Rss without db [kb]: " << rssWithoutDb / 1024 << std::endl; std::cout << "Percentage error: " << percentageRssError << std::endl; - HAWD::Dataset dataset("mail_query", mHawdState); + HAWD::Dataset dataset(QString{"mail_query"} + name, mHawdState); HAWD::Dataset::Row row = dataset.row(); row.setValue("rows", list.size()); row.setValue("queryResultPerMs", (qreal)list.size() / elapsed); @@ -159,7 +159,7 @@ private slots: query.limit(1000); populateDatabase(50000); - testLoad(query, 50000, query.limit()); + testLoad({}, query, 50000, query.limit()); } void test50kThreadleader() @@ -176,7 +176,7 @@ private slots: int count = 50000; populateDatabase(count, mailsPerFolder); - testLoad(query, count, query.limit()); + testLoad("_threadleader", query, count, query.limit()); } }; -- cgit v1.2.3 From 003adce13169c6874a4399a3345c215a0a758f9b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 11 May 2017 15:03:01 +0200 Subject: Fixed querytest --- tests/querytest.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index f639d94..65004b6 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -503,12 +503,13 @@ private slots: Folder folder2(resource2.identifier()); VERIFYEXEC(Sink::Store::create(folder2)); } + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << resource1.identifier())); + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << resource2.identifier())); // Test Sink::Query query; query.resourceFilter(account1); - // We fetch before the data is available and rely on the live query mechanism to deliver the actual data auto folders = Sink::Store::read(query); QCOMPARE(folders.size(), 1); } @@ -626,6 +627,9 @@ private slots: Folder folder2(resource2.identifier()); VERIFYEXEC(Sink::Store::create(folder2)); + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << resource1.identifier())); + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << resource2.identifier())); + // Test Sink::Query query; query.resourceContainsFilter("cap1"); -- cgit v1.2.3 From cf28dd267cf8e385539dc84938e4cae61b13fdb0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 11 May 2017 15:09:37 +0200 Subject: Fixed notification test --- tests/notificationtest.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/notificationtest.cpp b/tests/notificationtest.cpp index e268a17..f0d957e 100644 --- a/tests/notificationtest.cpp +++ b/tests/notificationtest.cpp @@ -70,10 +70,9 @@ private slots: using namespace Sink::ApplicationDomain; { QList expected = { - Status::OfflineStatus, Status::ConnectedStatus, Status::BusyStatus, - Status::ConnectedStatus + Status::ConnectedStatus, }; qInfo() << "Received notifications " << statusNotifications; QVERIFY2(statusNotifications.size() <= expected.size(), "More notifications than expected."); -- cgit v1.2.3 From 41f8f9bc05c059cafa780ac8aec27a56cba2c278 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 12 May 2017 08:20:43 +0200 Subject: No more SINK_DEBUG_AREA --- tests/mailsynctest.cpp | 2 -- tests/mailtest.cpp | 2 -- tests/messagequeuetest.cpp | 2 -- 3 files changed, 6 deletions(-) (limited to 'tests') diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp index c8ba9f1..5d51fbc 100644 --- a/tests/mailsynctest.cpp +++ b/tests/mailsynctest.cpp @@ -33,8 +33,6 @@ using namespace Sink; using namespace Sink::ApplicationDomain; -SINK_DEBUG_AREA("mailsynctest") - void MailSyncTest::initTestCase() { Test::initTest(); diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp index c51fc56..e1361e4 100644 --- a/tests/mailtest.cpp +++ b/tests/mailtest.cpp @@ -31,8 +31,6 @@ using namespace Sink; using namespace Sink::ApplicationDomain; -SINK_DEBUG_AREA("mailtest") - void MailTest::initTestCase() { Test::initTest(); diff --git a/tests/messagequeuetest.cpp b/tests/messagequeuetest.cpp index 83fa23f..2e3bd75 100644 --- a/tests/messagequeuetest.cpp +++ b/tests/messagequeuetest.cpp @@ -9,8 +9,6 @@ #include "log.h" #include "test.h" -SINK_DEBUG_AREA("messagequeuetest") - /** * Test of the messagequeue implementation. */ -- cgit v1.2.3 From 4fd06c19bf8ca057f4a60f762568158fb0caa8ec Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 12 May 2017 08:32:59 +0200 Subject: Try once more to initialize git_buf portably... --- tests/hawd/state.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/hawd/state.cpp b/tests/hawd/state.cpp index dfeef41..a994718 100644 --- a/tests/hawd/state.cpp +++ b/tests/hawd/state.cpp @@ -117,7 +117,7 @@ void State::findGitHash() { #ifdef HAVE_LIBGIT2 git_libgit2_init(); - git_buf root = {0}; + git_buf root = GIT_BUF_INIT_CONST(0, 0); int error = git_repository_discover(&root, projectPath().toStdString().data(), 0, NULL); if (!error) { git_repository *repo = NULL; -- cgit v1.2.3 From 8730949269771ad4d6bba9ba2414d272f9a0a799 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 12 May 2017 11:31:17 +0200 Subject: Made the test a bit conciser --- tests/querytest.cpp | 76 ++++++++++++++++++----------------------------------- 1 file changed, 26 insertions(+), 50 deletions(-) (limited to 'tests') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 65004b6..72eca86 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -98,10 +98,7 @@ private slots: void testSingle() { // Setup - { - Mail mail("sink.dummy.instance1"); - VERIFYEXEC(Sink::Store::create(mail)); - } + VERIFYEXEC(Sink::Store::create(Mail("sink.dummy.instance1"))); // Test Sink::Query query; @@ -116,10 +113,7 @@ private slots: void testSingleWithDelay() { // Setup - { - Mail mail("sink.dummy.instance1"); - Sink::Store::create(mail).exec().waitForFinished(); - } + VERIFYEXEC(Sink::Store::create(Mail("sink.dummy.instance1"))); // Test Sink::Query query; @@ -142,13 +136,13 @@ private slots: Mail mail("sink.dummy.instance1"); mail.setExtractedMessageId("test1"); mail.setFolder("folder1"); - Sink::Store::create(mail).exec().waitForFinished(); + VERIFYEXEC(Sink::Store::create(mail)); } { Mail mail("sink.dummy.instance1"); mail.setExtractedMessageId("test2"); mail.setFolder("folder2"); - Sink::Store::create(mail).exec().waitForFinished(); + VERIFYEXEC(Sink::Store::create(mail)); } // Test @@ -164,13 +158,13 @@ private slots: auto mail = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); { mail->setFolder("folder2"); - Sink::Store::modify(*mail).exec().waitForFinished(); + VERIFYEXEC(Sink::Store::modify(*mail)); } QTRY_COMPARE(model->rowCount(), 0); { mail->setFolder("folder1"); - Sink::Store::modify(*mail).exec().waitForFinished(); + VERIFYEXEC(Sink::Store::modify(*mail)); } QTRY_COMPARE(model->rowCount(), 1); } @@ -181,8 +175,8 @@ private slots: // Setup { Mail mail("sink.dummy.instance1"); - Sink::Store::create(mail).exec().waitForFinished(); - Sink::Store::create(mail).exec().waitForFinished(); + VERIFYEXEC(Sink::Store::create(mail)); + VERIFYEXEC(Sink::Store::create(mail)); Sink::Query query; query.resourceFilter("sink.dummy.instance1"); @@ -211,7 +205,7 @@ private slots: // Setup { Folder folder("sink.dummy.instance1"); - Sink::Store::create(folder).exec().waitForFinished(); + VERIFYEXEC(Sink::Store::create(folder)); } // Test @@ -622,20 +616,14 @@ private slots: resource2.setResourceType("sink.dummy"); VERIFYEXEC(Store::create(resource2)); - Folder folder1(resource1.identifier()); - VERIFYEXEC(Sink::Store::create(folder1)); - Folder folder2(resource2.identifier()); - VERIFYEXEC(Sink::Store::create(folder2)); + VERIFYEXEC(Sink::Store::create(Folder{resource1.identifier()})); + VERIFYEXEC(Sink::Store::create(Folder{resource2.identifier()})); - VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << resource1.identifier())); - VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << resource2.identifier())); - - // Test - Sink::Query query; - query.resourceContainsFilter("cap1"); + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(resource1.identifier())); + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(resource2.identifier())); // We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto folders = Sink::Store::read(query); + auto folders = Sink::Store::read(Sink::Query{}.resourceContainsFilter("cap1")); QCOMPARE(folders.size(), 1); } @@ -1063,30 +1051,18 @@ private slots: QDateTime now{QDate{2017, 2, 3}, QTime{10, 0, 0}}; QDateTime later{QDate{2017, 2, 3}, QTime{11, 0, 0}}; - { - auto mail1 = Mail::createEntity("sink.dummy.instance1"); - mail1.setExtractedMessageId("mail1"); - mail1.setFolder(folder1); - mail1.setExtractedDate(now); - mail1.setImportant(false); - VERIFYEXEC(Sink::Store::create(mail1)); - } - { - auto mail2 = Mail::createEntity("sink.dummy.instance1"); - mail2.setExtractedMessageId("mail2"); - mail2.setFolder(folder1); - mail2.setExtractedDate(earlier); - mail2.setImportant(false); - VERIFYEXEC(Sink::Store::create(mail2)); - } - { - auto mail3 = Mail::createEntity("sink.dummy.instance1"); - mail3.setExtractedMessageId("mail3"); - mail3.setFolder(folder1); - mail3.setExtractedDate(later); - mail3.setImportant(true); - VERIFYEXEC(Sink::Store::create(mail3)); - } + auto createMail = [] (const QByteArray &messageid, const Folder &folder, const QDateTime &date, bool important) { + auto mail = Mail::createEntity("sink.dummy.instance1"); + mail.setExtractedMessageId(messageid); + mail.setFolder(folder); + mail.setExtractedDate(date); + mail.setImportant(important); + return mail; + }; + + VERIFYEXEC(Sink::Store::create(createMail("mail1", folder1, now, false))); + VERIFYEXEC(Sink::Store::create(createMail("mail2", folder1, earlier, false))); + VERIFYEXEC(Sink::Store::create(createMail("mail3", folder1, later, true))); // Ensure all local data is processed VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); -- cgit v1.2.3 From d3cb4e649177443e8ecfd7f86d136fc0a319e2f3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 12 May 2017 14:00:54 +0200 Subject: Don't add resources that don't match the query during a livequery --- tests/querytest.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 72eca86..4ff1be8 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -625,6 +625,41 @@ private slots: // We fetch before the data is available and rely on the live query mechanism to deliver the actual data auto folders = Sink::Store::read(Sink::Query{}.resourceContainsFilter("cap1")); QCOMPARE(folders.size(), 1); + + //TODO this should be part of the regular cleanup between tests + VERIFYEXEC(Store::remove(resource1)); + VERIFYEXEC(Store::remove(resource2)); + } + + void testFilteredLiveResourceSubQuery() + { + using namespace Sink; + using namespace Sink::ApplicationDomain; + + //Setup + auto resource1 = ApplicationDomainType::createEntity(); + resource1.setResourceType("sink.dummy"); + resource1.setCapabilities(QByteArrayList() << "cap1"); + VERIFYEXEC(Store::create(resource1)); + VERIFYEXEC(Store::create(Folder{resource1.identifier()})); + VERIFYEXEC(ResourceControl::flushMessageQueue(resource1.identifier())); + + auto model = Sink::Store::loadModel(Query{Query::LiveQuery}.resourceContainsFilter("cap1")); + QTRY_COMPARE(model->rowCount(), 1); + + auto resource2 = ApplicationDomainType::createEntity(); + resource2.setCapabilities(QByteArrayList() << "cap2"); + resource2.setResourceType("sink.dummy"); + VERIFYEXEC(Store::create(resource2)); + VERIFYEXEC(Store::create(Folder{resource2.identifier()})); + VERIFYEXEC(ResourceControl::flushMessageQueue(resource2.identifier())); + + //The new resource should be filtered and thus not make it in here + QCOMPARE(model->rowCount(), 1); + + //TODO this should be part of the regular cleanup between tests + VERIFYEXEC(Store::remove(resource1)); + VERIFYEXEC(Store::remove(resource2)); } void testLivequeryUnmatchInThread() -- cgit v1.2.3 From e382924f1a90b5a27eba2e8c5981f6a4fe7892c9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 10 Jun 2017 09:37:08 +0200 Subject: Fixed incremental queries The incremental querying broke as soon as a revision update came in since it would nuke the base-set. This fixes it, but it's definitely not pretty. --- tests/querytest.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 4ff1be8..714e549 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -381,6 +381,7 @@ private slots: { // Setup Folder::Ptr folderEntity; + const auto date = QDateTime(QDate(2015, 7, 7), QTime(12, 0)); { Folder folder("sink.dummy.instance1"); Sink::Store::create(folder).exec().waitForFinished(); @@ -398,7 +399,6 @@ private slots: folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!folderEntity->identifier().isEmpty()); - const auto date = QDateTime(QDate(2015, 7, 7), QTime(12, 0)); { Mail mail("sink.dummy.instance1"); mail.setExtractedMessageId("testSecond"); @@ -428,6 +428,11 @@ private slots: query.filter(*folderEntity); query.sort(); query.limit(1); + query.setFlags(Query::LiveQuery); + query.reduce(Query::Reduce::Selector::max()) + .count("count") + .collect("unreadCollected") + .collect("importantCollected"); // Ensure all local data is processed VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); @@ -443,6 +448,26 @@ private slots: QCOMPARE(model->rowCount(), 2); // We can't make any assumptions about the order of the indexes // QCOMPARE(model->index(1, 0).data(Sink::Store::DomainObjectRole).value()->getProperty("messageId").toByteArray(), QByteArray("testSecond")); + + //New revisions always go through + { + Mail mail("sink.dummy.instance1"); + mail.setExtractedMessageId("testInjected"); + mail.setFolder(folderEntity->identifier()); + mail.setExtractedDate(date.addDays(-2)); + Sink::Store::create(mail).exec().waitForFinished(); + } + QTRY_COMPARE(model->rowCount(), 3); + + //Ensure we can continue fetching after the incremental update + model->fetchMore(QModelIndex()); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(), 4); + + //Ensure we have fetched all + model->fetchMore(QModelIndex()); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(), 4); } void testReactToNewResource() -- cgit v1.2.3 From ae1c5a0a53d1fd351b6fd33e8a46ad1034874489 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 14 Jun 2017 12:39:29 +0200 Subject: Deal with both CRLF and LF mime messages. IMAP always requires CRLF, and so does the MIME standard, KMIME expects LF-only. We now just try to always use CRLF on disk, but convert LF-only messages should we have to (e.g. because copied over from maildir or so). --- tests/interresourcemovetest.cpp | 2 +- tests/mailsynctest.cpp | 2 +- tests/mailtest.cpp | 18 +++++++++--------- tests/mailthreadtest.cpp | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/interresourcemovetest.cpp b/tests/interresourcemovetest.cpp index 3ac6ad4..5438bc7 100644 --- a/tests/interresourcemovetest.cpp +++ b/tests/interresourcemovetest.cpp @@ -48,7 +48,7 @@ class InterResourceMoveTest : public QObject m.subject(true)->fromUnicodeString(subject, "utf8"); m.messageID(true)->setIdentifier(uid); m.assemble(); - return m.encodedContent(); + return m.encodedContent(true); } private slots: diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp index 5d51fbc..27b29a5 100644 --- a/tests/mailsynctest.cpp +++ b/tests/mailsynctest.cpp @@ -275,7 +275,7 @@ void MailSyncTest::testListMails() QVERIFY(!data.isEmpty()); KMime::Message m; - m.setContent(data); + m.setContent(KMime::CRLFtoLF(data)); m.parse(); QCOMPARE(mail->getSubject(), m.subject(true)->asUnicodeString()); QVERIFY(!mail->getFolder().isEmpty()); diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp index e1361e4..cbb56d5 100644 --- a/tests/mailtest.cpp +++ b/tests/mailtest.cpp @@ -152,7 +152,7 @@ void MailTest::testCreateModifyDeleteMail() message->assemble(); auto mail = Mail::create(mResourceInstanceIdentifier); - mail.setMimeMessage(message->encodedContent()); + mail.setMimeMessage(message->encodedContent(true)); mail.setFolder(folder); VERIFYEXEC(Store::create(mail)); @@ -166,7 +166,7 @@ void MailTest::testCreateModifyDeleteMail() QCOMPARE(mail.getFolder(), folder.identifier()); QVERIFY(QFile(mail.getMimeMessagePath()).exists()); KMime::Message m; - m.setContent(mail.getMimeMessage()); + m.setContent(KMime::CRLFtoLF(mail.getMimeMessage())); m.parse(); QCOMPARE(m.subject(true)->asUnicodeString(), subject); }); @@ -182,7 +182,7 @@ void MailTest::testCreateModifyDeleteMail() auto message2 = KMime::Message::Ptr::create(); message2->subject(true)->fromUnicodeString(subject2, "utf8"); message2->assemble(); - mail.setMimeMessage(message2->encodedContent()); + mail.setMimeMessage(message2->encodedContent(true)); VERIFYEXEC(Store::modify(mail)); VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); @@ -195,7 +195,7 @@ void MailTest::testCreateModifyDeleteMail() QCOMPARE(mail.getFolder(), folder.identifier()); QVERIFY(QFile(mail.getMimeMessagePath()).exists()); KMime::Message m; - m.setContent(mail.getMimeMessage()); + m.setContent(KMime::CRLFtoLF(mail.getMimeMessage())); m.parse(); QCOMPARE(m.subject(true)->asUnicodeString(), subject2); }); @@ -237,7 +237,7 @@ void MailTest::testMoveMail() message->assemble(); auto mail = Mail::create(mResourceInstanceIdentifier); - mail.setMimeMessage(message->encodedContent()); + mail.setMimeMessage(message->encodedContent(true)); mail.setFolder(folder); VERIFYEXEC(Store::create(mail)); @@ -289,7 +289,7 @@ void MailTest::testMarkMailAsRead() message->assemble(); auto mail = Mail::create(mResourceInstanceIdentifier); - mail.setMimeMessage(message->encodedContent()); + mail.setMimeMessage(message->encodedContent(true)); mail.setFolder(folder); mail.setUnread(true); VERIFYEXEC(Store::create(mail)); @@ -341,7 +341,7 @@ void MailTest::testCreateDraft() message->assemble(); auto mail = ApplicationDomain::Mail::create(mResourceInstanceIdentifier); - mail.setMimeMessage(message->encodedContent()); + mail.setMimeMessage(message->encodedContent(true)); mail.setDraft(true); VERIFYEXEC(Store::create(mail)); @@ -391,7 +391,7 @@ void MailTest::testModifyMailToDraft() message->assemble(); auto mail = ApplicationDomain::Mail::create(mResourceInstanceIdentifier); - mail.setMimeMessage(message->encodedContent()); + mail.setMimeMessage(message->encodedContent(true)); mail.setDraft(false); mail.setFolder(folder); @@ -438,7 +438,7 @@ void MailTest::testModifyMailToTrash() message->assemble(); auto mail = ApplicationDomain::Mail::create(mResourceInstanceIdentifier); - mail.setMimeMessage(message->encodedContent()); + mail.setMimeMessage(message->encodedContent(true)); mail.setTrash(false); mail.setFolder(folder); diff --git a/tests/mailthreadtest.cpp b/tests/mailthreadtest.cpp index 02b29f6..741eb78 100644 --- a/tests/mailthreadtest.cpp +++ b/tests/mailthreadtest.cpp @@ -117,7 +117,7 @@ void MailThreadTest::testIndexInMixedOrder() { auto mail = Mail::create(mResourceInstanceIdentifier); - mail.setMimeMessage(message3->encodedContent()); + mail.setMimeMessage(message3->encodedContent(true)); mail.setFolder(folder); VERIFYEXEC(Store::create(mail)); } @@ -140,7 +140,7 @@ void MailThreadTest::testIndexInMixedOrder() { auto mail = Mail::create(mResourceInstanceIdentifier); - mail.setMimeMessage(message2->encodedContent()); + mail.setMimeMessage(message2->encodedContent(true)); mail.setFolder(folder); VERIFYEXEC(Store::create(mail)); } @@ -156,7 +156,7 @@ void MailThreadTest::testIndexInMixedOrder() { auto mail = Mail::create(mResourceInstanceIdentifier); - mail.setMimeMessage(message1->encodedContent()); + mail.setMimeMessage(message1->encodedContent(true)); mail.setFolder(folder); VERIFYEXEC(Store::create(mail)); } -- cgit v1.2.3 From ead1720e78ca49837e1365e4b5dfb1b3f43632bc Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 14 Jun 2017 13:24:43 +0200 Subject: Use asyncverify where we can Otherwise the test is not aborted because the job doesn't get any error set --- tests/mailsynctest.cpp | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp index 27b29a5..75454c0 100644 --- a/tests/mailsynctest.cpp +++ b/tests/mailsynctest.cpp @@ -224,7 +224,8 @@ void MailSyncTest::testListNewSubFolder() for (const auto &folder : folders) { names << folder->getName(); } - QVERIFY(names.contains("sub1")); + ASYNCVERIFY(names.contains("sub1")); + return KAsync::null(); }); VERIFYEXEC(job); } @@ -252,7 +253,8 @@ void MailSyncTest::testListRemovedSubFolder() for (const auto &folder : folders) { names << folder->getName(); } - QVERIFY(!names.contains("sub1")); + ASYNCVERIFY(!names.contains("sub1")); + return KAsync::null(); }); VERIFYEXEC(job); } @@ -268,18 +270,19 @@ void MailSyncTest::testListMails() VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); auto job = Store::fetchAll(query).then([](const QList &mails) { - QCOMPARE(mails.size(), 1); + ASYNCCOMPARE(mails.size(), 1); auto mail = mails.first(); - QVERIFY(mail->getSubject().startsWith(QString("[Nepomuk] Jenkins build is still unstable"))); + ASYNCVERIFY(mail->getSubject().startsWith(QString("[Nepomuk] Jenkins build is still unstable"))); const auto data = mail->getMimeMessage(); - QVERIFY(!data.isEmpty()); + ASYNCVERIFY(!data.isEmpty()); KMime::Message m; m.setContent(KMime::CRLFtoLF(data)); m.parse(); - QCOMPARE(mail->getSubject(), m.subject(true)->asUnicodeString()); - QVERIFY(!mail->getFolder().isEmpty()); - QVERIFY(mail->getDate().isValid()); + ASYNCCOMPARE(mail->getSubject(), m.subject(true)->asUnicodeString()); + ASYNCVERIFY(!mail->getFolder().isEmpty()); + ASYNCVERIFY(mail->getDate().isValid()); + return KAsync::null(); }); VERIFYEXEC(job); } @@ -300,10 +303,11 @@ void MailSyncTest::testResyncMails() VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); auto job = Store::fetchAll(query).then([](const QList &mails) { - QCOMPARE(mails.size(), 1); + ASYNCCOMPARE(mails.size(), 1); auto mail = mails.first(); - QVERIFY(!mail->getSubject().isEmpty()); - QVERIFY(!mail->getMimeMessagePath().isEmpty()); + ASYNCVERIFY(!mail->getSubject().isEmpty()); + ASYNCVERIFY(!mail->getMimeMessagePath().isEmpty()); + return KAsync::null(); }); VERIFYEXEC(job); } @@ -328,7 +332,8 @@ void MailSyncTest::testFetchNewRemovedMessages() { auto job = Store::fetchAll(query).then([](const QList &mails) { - QCOMPARE(mails.size(), 2); + ASYNCCOMPARE(mails.size(), 2); + return KAsync::null(); }); VERIFYEXEC(job); } @@ -340,7 +345,8 @@ void MailSyncTest::testFetchNewRemovedMessages() { auto job = Store::fetchAll(query).then([](const QList &mails) { - QCOMPARE(mails.size(), 1); + ASYNCCOMPARE(mails.size(), 1); + return KAsync::null(); }); VERIFYEXEC(job); } @@ -363,7 +369,8 @@ void MailSyncTest::testFlagChange() { auto job = Store::fetchAll(query).then([](const QList &mails) { - QCOMPARE(mails.size(), 0); + ASYNCCOMPARE(mails.size(), 0); + return KAsync::null(); }); VERIFYEXEC(job); } @@ -376,8 +383,9 @@ void MailSyncTest::testFlagChange() { auto job = Store::fetchAll(query).then([](const QList &mails) { - QCOMPARE(mails.size(), 1); - QVERIFY(mails.first()->getImportant()); + ASYNCCOMPARE(mails.size(), 1); + ASYNCVERIFY(mails.first()->getImportant()); + return KAsync::null(); }); VERIFYEXEC(job); } @@ -392,8 +400,9 @@ void MailSyncTest::testSyncSingleFolder() Folder::Ptr folder; { auto job = Store::fetchAll(Sink::Query{}.resourceFilter(mResourceInstanceIdentifier).filter("test")).template then([&](const QList &folders) { - QCOMPARE(folders.size(), 1); + ASYNCCOMPARE(folders.size(), 1); folder = folders.first(); + return KAsync::null(); }); VERIFYEXEC(job); } @@ -417,11 +426,13 @@ void MailSyncTest::testSyncSingleMail() Mail::Ptr mail; { auto job = Store::fetchAll(Sink::Query{}.resourceFilter(mResourceInstanceIdentifier)).template then([&](const QList &mails) { - QVERIFY(mails.size() >= 1); + ASYNCVERIFY(mails.size() >= 1); mail = mails.first(); + return KAsync::null(); }); VERIFYEXEC(job); } + QVERIFY(mail); auto syncScope = Sink::SyncScope{ApplicationDomain::getTypeName()}; syncScope.resourceFilter(mResourceInstanceIdentifier); -- cgit v1.2.3 From 06f996a139a5ac660e98163fac796f94c1a6468f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 27 Jun 2017 20:57:31 +0200 Subject: Ensure we can deal with non-null terminated strings. --- tests/domainadaptortest.cpp | 51 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index df44819..2aed0a9 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp @@ -17,17 +17,19 @@ class TestFactory : public DomainTypeAdaptorFactory { public: - TestFactory() - { - } + TestFactory() = default; }; class TestMailFactory : public DomainTypeAdaptorFactory { public: - TestMailFactory() - { - } + TestMailFactory() = default; +}; + +class TestContactFactory : public DomainTypeAdaptorFactory +{ +public: + TestContactFactory() = default; }; /** @@ -135,6 +137,43 @@ private slots: } } + + void testContact() + { + auto writeMapper = QSharedPointer::create(); + Sink::ApplicationDomain::TypeImplementation::configure(*writeMapper); + + auto binaryData = QByteArray::fromRawData("\xEF\xBF\xBD\x00\xEF\xBF", 5); + + Sink::ApplicationDomain::Contact contact; + contact.setPhoto(binaryData); + QVERIFY(!contact.getPhoto().isEmpty()); + + flatbuffers::FlatBufferBuilder metadataFbb; + auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); + metadataBuilder.add_revision(1); + auto metadataBuffer = metadataBuilder.Finish(); + Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); + + flatbuffers::FlatBufferBuilder mailFbb; + auto pos = createBufferPart(contact, mailFbb, *writeMapper); + Sink::ApplicationDomain::Buffer::FinishContactBuffer(mailFbb, pos); + + flatbuffers::FlatBufferBuilder fbb; + Sink::EntityBuffer::assembleEntityBuffer( + fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), mailFbb.GetBufferPointer(), mailFbb.GetSize(), mailFbb.GetBufferPointer(), mailFbb.GetSize()); + + { + std::string data(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); + Sink::EntityBuffer buffer((void *)(data.data()), data.size()); + + TestContactFactory factory; + auto adaptor = factory.createAdaptor(buffer.entity()); + Sink::ApplicationDomain::Contact readContact{QByteArray{}, QByteArray{}, 0, adaptor}; + QCOMPARE(readContact.getPhoto(), contact.getPhoto()); + } + + } }; QTEST_MAIN(DomainAdaptorTest) -- cgit v1.2.3