From ccd61612c51d7f8a92349a2d4855efc583a35b5b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 11 Jan 2015 20:57:57 +0100 Subject: Finally working multithreaded reads from lmdb? --- tests/storagetest.cpp | 54 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index a405de0..6c1d02b 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -46,8 +46,11 @@ private: } return keyMatch; }, - [&success](const Akonadi2::Storage::Error &) { success = false; } - ); + [&success](const Akonadi2::Storage::Error &error) { + qDebug() << QString::fromStdString(error.message); + success = false; + } + ); return success && keyMatch; } @@ -138,29 +141,36 @@ private Q_SLOTS: const int count = 10000; populate(count); - - bool error = false; - //Try to concurrently read - QList > futures; - const int concurrencyLevel = 10; - for (int num = 0; num < concurrencyLevel; num++) { - futures << QtConcurrent::run([this, count, &error](){ - Akonadi2::Storage storage(testDataPath, dbName); - for (int i = 0; i < count; i++) { - if (!verify(storage, i)) { - error = true; - break; + // QTest::qWait(500); + + //We repeat the test a bunch of times since failing is relatively random + for (int tries = 0; tries < 10; tries++) { + bool error = false; + //Try to concurrently read + QList > futures; + const int concurrencyLevel = 20; + for (int num = 0; num < concurrencyLevel; num++) { + futures << QtConcurrent::run([this, count, &error](){ + Akonadi2::Storage storage(testDataPath, dbName, Akonadi2::Storage::ReadOnly); + Akonadi2::Storage storage2(testDataPath, dbName + "2", Akonadi2::Storage::ReadOnly); + for (int i = 0; i < count; i++) { + if (!verify(storage, i)) { + error = true; + break; + } } - } - }); - } - for(auto future : futures) { - future.waitForFinished(); + }); + } + for(auto future : futures) { + future.waitForFinished(); + } + QVERIFY(!error); } - QVERIFY(!error); - Akonadi2::Storage storage(testDataPath, dbName); - storage.removeFromDisk(); + { + Akonadi2::Storage storage(testDataPath, dbName); + storage.removeFromDisk(); + } } }; -- cgit v1.2.3