diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-22 10:16:18 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-22 10:16:18 +0100 |
commit | 2beb09e8b3f4922a15ec0abde737d4cf9b9d4f8b (patch) | |
tree | 50115abf9b041d66ab9e4242af52cd16a7a9a3db /tests/querytest.cpp | |
parent | 280b1250c0a038c2cf09fae3848ed0adefecc430 (diff) | |
download | sink-2beb09e8b3f4922a15ec0abde737d4cf9b9d4f8b.tar.gz sink-2beb09e8b3f4922a15ec0abde737d4cf9b9d4f8b.zip |
Deal with removals in reduced queries
Diffstat (limited to 'tests/querytest.cpp')
-rw-r--r-- | tests/querytest.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
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: | |||
760 | QTRY_COMPARE(model->rowCount(), 0); | 760 | QTRY_COMPARE(model->rowCount(), 0); |
761 | } | 761 | } |
762 | 762 | ||
763 | void testLivequeryRemoveOneInThread() | ||
764 | { | ||
765 | // Setup | ||
766 | auto folder1 = Folder::createEntity<Folder>("sink.dummy.instance1"); | ||
767 | VERIFYEXEC(Sink::Store::create<Folder>(folder1)); | ||
768 | |||
769 | auto mail1 = Mail::createEntity<Mail>("sink.dummy.instance1"); | ||
770 | mail1.setExtractedMessageId("mail1"); | ||
771 | mail1.setFolder(folder1); | ||
772 | VERIFYEXEC(Sink::Store::create(mail1)); | ||
773 | auto mail2 = Mail::createEntity<Mail>("sink.dummy.instance1"); | ||
774 | mail2.setExtractedMessageId("mail2"); | ||
775 | mail2.setFolder(folder1); | ||
776 | VERIFYEXEC(Sink::Store::create(mail2)); | ||
777 | // Ensure all local data is processed | ||
778 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); | ||
779 | |||
780 | //Setup two folders with a mail each, ensure we only get the mail from the folder that matches the folder filter. | ||
781 | Query query; | ||
782 | query.setId("testLivequeryUnmatch"); | ||
783 | query.reduce<Mail::Folder>(Query::Reduce::Selector::max<Mail::Date>()).count("count").collect<Mail::Sender>("senders"); | ||
784 | query.sort<Mail::Date>(); | ||
785 | query.setFlags(Query::LiveQuery); | ||
786 | auto model = Sink::Store::loadModel<Mail>(query); | ||
787 | QTRY_COMPARE(model->rowCount(), 1); | ||
788 | QCOMPARE(model->data(model->index(0, 0, QModelIndex{}), Sink::Store::DomainObjectRole).value<Mail::Ptr>()->getProperty("count").toInt(), 2); | ||
789 | |||
790 | //After the removal, the thread size should be reduced by one | ||
791 | { | ||
792 | |||
793 | VERIFYEXEC(Sink::Store::remove(mail1)); | ||
794 | } | ||
795 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); | ||
796 | QTRY_COMPARE(model->rowCount(), 1); | ||
797 | QTRY_COMPARE(model->data(model->index(0, 0, QModelIndex{}), Sink::Store::DomainObjectRole).value<Mail::Ptr>()->getProperty("count").toInt(), 1); | ||
798 | |||
799 | //After the second removal, the thread should be gone | ||
800 | { | ||
801 | VERIFYEXEC(Sink::Store::remove(mail2)); | ||
802 | } | ||
803 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); | ||
804 | QTRY_COMPARE(model->rowCount(), 0); | ||
805 | } | ||
806 | |||
763 | void testDontUpdateNonLiveQuery() | 807 | void testDontUpdateNonLiveQuery() |
764 | { | 808 | { |
765 | // Setup | 809 | // Setup |