From 9fa528c5fceefd53303a604625d13cf0cdbb109e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 3 Jan 2018 15:34:35 +0100 Subject: Use read-write locks for finer grained control to sDbi and sEnvironments There are only a few cases where have to access the list of dbis or environments, so we can normally get away with just read-locking. This seems to fix a segfault that was possibly caused be an environment being reused that has already been freed in another thread. The read-only lock when initially retrieving the environment seems to fix that. --- tests/querytest.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'tests') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 0844d72..1584c48 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -1182,6 +1182,78 @@ private slots: QCOMPARE(mail->getProperty("folders").toList().size(), 2); } } + + /* + * This test is here to ensure we don't crash if we call removeFromDisk with a running query. + */ + void testRemoveFromDiskWithRunningQuery() + { + { + // 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(); + + Sink::Query query; + query.resourceFilter("sink.dummy.instance1"); + + // Ensure all local data is processed + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); + + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(), 1); + + folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); + QVERIFY(!folderEntity->identifier().isEmpty()); + + { + Mail mail("sink.dummy.instance1"); + mail.setExtractedMessageId("testSecond"); + mail.setFolder(folderEntity->identifier()); + mail.setExtractedDate(date.addDays(-1)); + Sink::Store::create(mail).exec().waitForFinished(); + } + { + Mail mail("sink.dummy.instance1"); + mail.setExtractedMessageId("testLatest"); + mail.setFolder(folderEntity->identifier()); + mail.setExtractedDate(date); + Sink::Store::create(mail).exec().waitForFinished(); + } + { + Mail mail("sink.dummy.instance1"); + mail.setExtractedMessageId("testLast"); + mail.setFolder(folderEntity->identifier()); + mail.setExtractedDate(date.addDays(-2)); + Sink::Store::create(mail).exec().waitForFinished(); + } + } + + // Test + Sink::Query query; + query.resourceFilter("sink.dummy.instance1"); + 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")); + + auto model = Sink::Store::loadModel(query); + } + + //FIXME: this will result in a crash in the above still running query. + VERIFYEXEC(Sink::Store::removeDataFromDisk(QByteArray("sink.dummy.instance1"))); + } + }; QTEST_MAIN(QueryTest) -- cgit v1.2.3