diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-04-01 09:41:28 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-04-01 10:02:41 +0200 |
commit | 8d2d52fcfd3c42a82b7f86c6f3c5009461f1de9f (patch) | |
tree | 042e2db12927d289fce3a2fab8486e03ac4c9049 /tests | |
parent | 53b76e66f5527a5f9442173279b0a01f1f07da46 (diff) | |
download | sink-8d2d52fcfd3c42a82b7f86c6f3c5009461f1de9f.tar.gz sink-8d2d52fcfd3c42a82b7f86c6f3c5009461f1de9f.zip |
Avoid missing revision updates while a query is running.
Instead we have to remember that something has changed and rerun an
incremental query.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/querytest.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 2a12979..81b7cdc 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp | |||
@@ -13,6 +13,8 @@ | |||
13 | #include "test.h" | 13 | #include "test.h" |
14 | #include "testutils.h" | 14 | #include "testutils.h" |
15 | #include "applicationdomaintype.h" | 15 | #include "applicationdomaintype.h" |
16 | #include "queryrunner.h" | ||
17 | #include "adaptorfactoryregistry.h" | ||
16 | 18 | ||
17 | #include <KMime/Message> | 19 | #include <KMime/Message> |
18 | 20 | ||
@@ -1229,6 +1231,55 @@ private slots: | |||
1229 | } | 1231 | } |
1230 | } | 1232 | } |
1231 | 1233 | ||
1234 | void testQueryRunnerDontMissUpdates() | ||
1235 | { | ||
1236 | // Setup | ||
1237 | auto folder1 = Folder::createEntity<Folder>("sink.dummy.instance1"); | ||
1238 | VERIFYEXEC(Sink::Store::create<Folder>(folder1)); | ||
1239 | |||
1240 | QDateTime now{QDate{2017, 2, 3}, QTime{10, 0, 0}}; | ||
1241 | |||
1242 | auto createMail = [] (const QByteArray &messageid, const Folder &folder, const QDateTime &date, bool important) { | ||
1243 | auto mail = Mail::createEntity<Mail>("sink.dummy.instance1"); | ||
1244 | mail.setExtractedMessageId(messageid); | ||
1245 | mail.setFolder(folder); | ||
1246 | mail.setExtractedDate(date); | ||
1247 | mail.setImportant(important); | ||
1248 | return mail; | ||
1249 | }; | ||
1250 | |||
1251 | VERIFYEXEC(Sink::Store::create(createMail("mail1", folder1, now, false))); | ||
1252 | |||
1253 | // Ensure all local data is processed | ||
1254 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); | ||
1255 | |||
1256 | Query query; | ||
1257 | query.setFlags(Query::LiveQuery); | ||
1258 | |||
1259 | Sink::ResourceContext resourceContext{"sink.dummy.instance1", "sink.dummy", Sink::AdaptorFactoryRegistry::instance().getFactories("sink.dummy")}; | ||
1260 | Sink::Log::Context logCtx; | ||
1261 | auto runner = new QueryRunner<Mail>(query, resourceContext, ApplicationDomain::getTypeName<Mail>(), logCtx); | ||
1262 | runner->delayNextQuery(); | ||
1263 | |||
1264 | auto emitter = runner->emitter(); | ||
1265 | QList<Mail::Ptr> added; | ||
1266 | emitter->onAdded([&](Mail::Ptr mail) { | ||
1267 | added << mail; | ||
1268 | }); | ||
1269 | |||
1270 | emitter->fetch(); | ||
1271 | VERIFYEXEC(Sink::Store::create(createMail("mail2", folder1, now, false))); | ||
1272 | QTRY_COMPARE(added.size(), 2); | ||
1273 | |||
1274 | runner->delayNextQuery(); | ||
1275 | VERIFYEXEC(Sink::Store::create(createMail("mail3", folder1, now, false))); | ||
1276 | //The second revision update is supposed to come in while the initial revision update is still in the query. | ||
1277 | //So wait a bit to make sure the query is currently runnning. | ||
1278 | QTest::qWait(500); | ||
1279 | VERIFYEXEC(Sink::Store::create(createMail("mail4", folder1, now, false))); | ||
1280 | QTRY_COMPARE(added.size(), 4); | ||
1281 | } | ||
1282 | |||
1232 | /* | 1283 | /* |
1233 | * This test is here to ensure we don't crash if we call removeFromDisk with a running query. | 1284 | * This test is here to ensure we don't crash if we call removeFromDisk with a running query. |
1234 | */ | 1285 | */ |