From 422c12d85d3eca55eca6f23c140910150a5fd166 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 16 Oct 2017 17:31:10 +0200 Subject: QUICK_TRY_VERIFY for quick polling in benchmarks --- tests/dummyresourcebenchmark.cpp | 2 +- tests/mailquerybenchmark.cpp | 17 +++++------------ tests/testutils.h | 8 ++++++++ 3 files changed, 14 insertions(+), 13 deletions(-) (limited to 'tests') 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: Sink::Store::create(event).exec(); // Wait for notification - QTRY_VERIFY(gotNotification); + QUICK_TRY_VERIFY(gotNotification); QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1()); 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 @@ #include "mail_generated.h" #include "createentity_generated.h" #include "getrssusage.h" +#include "testutils.h" using namespace Sink; using namespace Sink::ApplicationDomain; @@ -102,9 +103,7 @@ class MailQueryBenchmark : public QObject bool done = false; emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); emitter->fetch(Mail::Ptr()); - while (!done) { - QTest::qWait(1); - } + QUICK_TRY_VERIFY(!done); Q_ASSERT(list.size() == expectedSize); const auto elapsed = time.elapsed(); @@ -218,9 +217,7 @@ private slots: bool done = false; emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); emitter->fetch(Mail::Ptr()); - while (!done) { - QTest::qWait(1); - } + QUICK_TRY_VERIFY(!done); QCOMPARE(added.size(), expectedSize); auto initialQueryTime = time.elapsed(); @@ -233,13 +230,9 @@ private slots: context.mResourceAccess->revisionChanged(1000 + i * 100); } //We should have 200 items in total in the end. 2000 mails / 10 folders => 200 reduced mails - while (added.count() != 200) { - QTest::qWait(1); - } + QUICK_TRY_VERIFY(added.count() != 200); //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. - while (modified.count() != 100) { - QTest::qWait(1); - } + QUICK_TRY_VERIFY(modified.count() != 100); auto incrementalQueryTime = time.elapsed(); std::cout << "Incremental query took " << incrementalQueryTime << std::endl; 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 {\ if (!QTest::qVerify(result.errorCode(), #statement, "", __FILE__, __LINE__))\ return;\ } while (0) + +#define QUICK_TRY_VERIFY(statement) \ +do {\ + static int timeout = 5000; \ + for (int i = 0; i < timeout && #statement; i++) { \ + QTest::qWait(1); \ + } \ +} while (0) -- cgit v1.2.3