From 2beb09e8b3f4922a15ec0abde737d4cf9b9d4f8b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 22 Feb 2018 10:16:18 +0100 Subject: Deal with removals in reduced queries --- tests/querytest.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/querytest.cpp') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index ec6438d..f65d477 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -760,6 +760,50 @@ private slots: QTRY_COMPARE(model->rowCount(), 0); } + void testLivequeryRemoveOneInThread() + { + // Setup + auto folder1 = Folder::createEntity("sink.dummy.instance1"); + VERIFYEXEC(Sink::Store::create(folder1)); + + auto mail1 = Mail::createEntity("sink.dummy.instance1"); + mail1.setExtractedMessageId("mail1"); + mail1.setFolder(folder1); + VERIFYEXEC(Sink::Store::create(mail1)); + auto mail2 = Mail::createEntity("sink.dummy.instance1"); + mail2.setExtractedMessageId("mail2"); + mail2.setFolder(folder1); + VERIFYEXEC(Sink::Store::create(mail2)); + // Ensure all local data is processed + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); + + //Setup two folders with a mail each, ensure we only get the mail from the folder that matches the folder filter. + Query query; + query.setId("testLivequeryUnmatch"); + query.reduce(Query::Reduce::Selector::max()).count("count").collect("senders"); + query.sort(); + query.setFlags(Query::LiveQuery); + auto model = Sink::Store::loadModel(query); + QTRY_COMPARE(model->rowCount(), 1); + QCOMPARE(model->data(model->index(0, 0, QModelIndex{}), Sink::Store::DomainObjectRole).value()->getProperty("count").toInt(), 2); + + //After the removal, the thread size should be reduced by one + { + + VERIFYEXEC(Sink::Store::remove(mail1)); + } + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); + QTRY_COMPARE(model->rowCount(), 1); + QTRY_COMPARE(model->data(model->index(0, 0, QModelIndex{}), Sink::Store::DomainObjectRole).value()->getProperty("count").toInt(), 1); + + //After the second removal, the thread should be gone + { + VERIFYEXEC(Sink::Store::remove(mail2)); + } + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); + QTRY_COMPARE(model->rowCount(), 0); + } + void testDontUpdateNonLiveQuery() { // Setup -- cgit v1.2.3