summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-10-16 17:31:10 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-10-16 17:31:10 +0200
commit422c12d85d3eca55eca6f23c140910150a5fd166 (patch)
tree52d7b466d73f2d1a3b4ba98b20d558c8c75dc96a /tests
parentad9e3074f2949a0ea604bc191109fa0ad7b8e2e4 (diff)
downloadsink-422c12d85d3eca55eca6f23c140910150a5fd166.tar.gz
sink-422c12d85d3eca55eca6f23c140910150a5fd166.zip
QUICK_TRY_VERIFY for quick polling in benchmarks
Diffstat (limited to 'tests')
-rw-r--r--tests/dummyresourcebenchmark.cpp2
-rw-r--r--tests/mailquerybenchmark.cpp17
-rw-r--r--tests/testutils.h8
3 files changed, 14 insertions, 13 deletions
diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp
index 868c5aa..674d4d6 100644
--- a/tests/dummyresourcebenchmark.cpp
+++ b/tests/dummyresourcebenchmark.cpp
@@ -73,7 +73,7 @@ private slots:
73 Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec(); 73 Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec();
74 74
75 // Wait for notification 75 // Wait for notification
76 QTRY_VERIFY(gotNotification); 76 QUICK_TRY_VERIFY(gotNotification);
77 77
78 QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1()); 78 QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1());
79 VERIFYEXEC(Sink::ResourceControl::shutdown("sink.dummy.instance1")); 79 VERIFYEXEC(Sink::ResourceControl::shutdown("sink.dummy.instance1"));
diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp
index 700eb94..ff61e81 100644
--- a/tests/mailquerybenchmark.cpp
+++ b/tests/mailquerybenchmark.cpp
@@ -37,6 +37,7 @@
37#include "mail_generated.h" 37#include "mail_generated.h"
38#include "createentity_generated.h" 38#include "createentity_generated.h"
39#include "getrssusage.h" 39#include "getrssusage.h"
40#include "testutils.h"
40 41
41using namespace Sink; 42using namespace Sink;
42using namespace Sink::ApplicationDomain; 43using namespace Sink::ApplicationDomain;
@@ -102,9 +103,7 @@ class MailQueryBenchmark : public QObject
102 bool done = false; 103 bool done = false;
103 emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); 104 emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; });
104 emitter->fetch(Mail::Ptr()); 105 emitter->fetch(Mail::Ptr());
105 while (!done) { 106 QUICK_TRY_VERIFY(!done);
106 QTest::qWait(1);
107 }
108 Q_ASSERT(list.size() == expectedSize); 107 Q_ASSERT(list.size() == expectedSize);
109 108
110 const auto elapsed = time.elapsed(); 109 const auto elapsed = time.elapsed();
@@ -218,9 +217,7 @@ private slots:
218 bool done = false; 217 bool done = false;
219 emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); 218 emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; });
220 emitter->fetch(Mail::Ptr()); 219 emitter->fetch(Mail::Ptr());
221 while (!done) { 220 QUICK_TRY_VERIFY(!done);
222 QTest::qWait(1);
223 }
224 QCOMPARE(added.size(), expectedSize); 221 QCOMPARE(added.size(), expectedSize);
225 222
226 auto initialQueryTime = time.elapsed(); 223 auto initialQueryTime = time.elapsed();
@@ -233,13 +230,9 @@ private slots:
233 context.mResourceAccess->revisionChanged(1000 + i * 100); 230 context.mResourceAccess->revisionChanged(1000 + i * 100);
234 } 231 }
235 //We should have 200 items in total in the end. 2000 mails / 10 folders => 200 reduced mails 232 //We should have 200 items in total in the end. 2000 mails / 10 folders => 200 reduced mails
236 while (added.count() != 200) { 233 QUICK_TRY_VERIFY(added.count() != 200);
237 QTest::qWait(1);
238 }
239 //We get one modification per thread from the first 100 (1000 mails / 10 folders), everything else is optimized away because we ignore repeated updates to the same thread. 234 //We get one modification per thread from the first 100 (1000 mails / 10 folders), everything else is optimized away because we ignore repeated updates to the same thread.
240 while (modified.count() != 100) { 235 QUICK_TRY_VERIFY(modified.count() != 100);
241 QTest::qWait(1);
242 }
243 auto incrementalQueryTime = time.elapsed(); 236 auto incrementalQueryTime = time.elapsed();
244 std::cout << "Incremental query took " << incrementalQueryTime << std::endl; 237 std::cout << "Incremental query took " << incrementalQueryTime << std::endl;
245 std::cout << "added " << added.count() << std::endl; 238 std::cout << "added " << added.count() << std::endl;
diff --git a/tests/testutils.h b/tests/testutils.h
index f89da38..6e935f3 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -45,3 +45,11 @@ do {\
45 if (!QTest::qVerify(result.errorCode(), #statement, "", __FILE__, __LINE__))\ 45 if (!QTest::qVerify(result.errorCode(), #statement, "", __FILE__, __LINE__))\
46 return;\ 46 return;\
47} while (0) 47} while (0)
48
49#define QUICK_TRY_VERIFY(statement) \
50do {\
51 static int timeout = 5000; \
52 for (int i = 0; i < timeout && #statement; i++) { \
53 QTest::qWait(1); \
54 } \
55} while (0)