summaryrefslogtreecommitdiffstats
path: root/tests/dummyresourcebenchmark.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dummyresourcebenchmark.cpp')
-rw-r--r--tests/dummyresourcebenchmark.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp
index 4c649a9..ed448f0 100644
--- a/tests/dummyresourcebenchmark.cpp
+++ b/tests/dummyresourcebenchmark.cpp
@@ -45,18 +45,50 @@ private Q_SLOTS:
45 removeFromDisk("org.kde.dummy.instance1.index.uid"); 45 removeFromDisk("org.kde.dummy.instance1.index.uid");
46 } 46 }
47 47
48 static KAsync::Job<void> waitForCompletion(QList<KAsync::Future<void> > &futures)
49 {
50 auto context = new QObject;
51 return KAsync::start<void>([futures, context](KAsync::Future<void> &future) {
52 const auto total = futures.size();
53 auto count = QSharedPointer<int>::create();
54 int i = 0;
55 for (KAsync::Future<void> subFuture : futures) {
56 i++;
57 if (subFuture.isFinished()) {
58 *count += 1;
59 continue;
60 }
61 //FIXME bind lifetime all watcher to future (repectively the main job
62 auto watcher = QSharedPointer<KAsync::FutureWatcher<void> >::create();
63 QObject::connect(watcher.data(), &KAsync::FutureWatcher<void>::futureReady,
64 [count, total, &future](){
65 *count += 1;
66 if (*count == total) {
67 future.setFinished();
68 }
69 });
70 watcher->setFuture(subFuture);
71 context->setProperty(QString("future%1").arg(i).toLatin1().data(), QVariant::fromValue(watcher));
72 }
73 }).then<void>([context]() {
74 delete context;
75 });
76 }
77
48 void testWriteToFacadeAndQueryByUid() 78 void testWriteToFacadeAndQueryByUid()
49 { 79 {
50 QTime time; 80 QTime time;
51 time.start(); 81 time.start();
52 int num = 10000; 82 int num = 10000;
83 QList<KAsync::Future<void> > waitCondition;
53 for (int i = 0; i < num; i++) { 84 for (int i = 0; i < num; i++) {
54 Akonadi2::ApplicationDomain::Event event; 85 Akonadi2::ApplicationDomain::Event event;
55 event.setProperty("uid", "testuid"); 86 event.setProperty("uid", "testuid");
56 QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); 87 QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid"));
57 event.setProperty("summary", "summaryValue"); 88 event.setProperty("summary", "summaryValue");
58 Akonadi2::Store::create<Akonadi2::ApplicationDomain::Event>(event, "org.kde.dummy.instance1"); 89 waitCondition << Akonadi2::Store::create<Akonadi2::ApplicationDomain::Event>(event, "org.kde.dummy.instance1").exec();
59 } 90 }
91 waitForCompletion(waitCondition).exec().waitForFinished();
60 auto appendTime = time.elapsed(); 92 auto appendTime = time.elapsed();
61 93
62 //Ensure everything is processed 94 //Ensure everything is processed