summaryrefslogtreecommitdiffstats
path: root/tests/storagetest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-11 20:57:57 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-11 20:57:57 +0100
commitccd61612c51d7f8a92349a2d4855efc583a35b5b (patch)
treeaf30a864c51d9fdf867bc51952e5ff27052c6b75 /tests/storagetest.cpp
parenta773a60c694bd3e112b33d6ce300d419ad56ccc2 (diff)
downloadsink-ccd61612c51d7f8a92349a2d4855efc583a35b5b.tar.gz
sink-ccd61612c51d7f8a92349a2d4855efc583a35b5b.zip
Finally working multithreaded reads from lmdb?
Diffstat (limited to 'tests/storagetest.cpp')
-rw-r--r--tests/storagetest.cpp54
1 files changed, 32 insertions, 22 deletions
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:
46 } 46 }
47 return keyMatch; 47 return keyMatch;
48 }, 48 },
49 [&success](const Akonadi2::Storage::Error &) { success = false; } 49 [&success](const Akonadi2::Storage::Error &error) {
50 ); 50 qDebug() << QString::fromStdString(error.message);
51 success = false;
52 }
53 );
51 return success && keyMatch; 54 return success && keyMatch;
52 } 55 }
53 56
@@ -138,29 +141,36 @@ private Q_SLOTS:
138 const int count = 10000; 141 const int count = 10000;
139 142
140 populate(count); 143 populate(count);
141 144 // QTest::qWait(500);
142 bool error = false; 145
143 //Try to concurrently read 146 //We repeat the test a bunch of times since failing is relatively random
144 QList<QFuture<void> > futures; 147 for (int tries = 0; tries < 10; tries++) {
145 const int concurrencyLevel = 10; 148 bool error = false;
146 for (int num = 0; num < concurrencyLevel; num++) { 149 //Try to concurrently read
147 futures << QtConcurrent::run([this, count, &error](){ 150 QList<QFuture<void> > futures;
148 Akonadi2::Storage storage(testDataPath, dbName); 151 const int concurrencyLevel = 20;
149 for (int i = 0; i < count; i++) { 152 for (int num = 0; num < concurrencyLevel; num++) {
150 if (!verify(storage, i)) { 153 futures << QtConcurrent::run([this, count, &error](){
151 error = true; 154 Akonadi2::Storage storage(testDataPath, dbName, Akonadi2::Storage::ReadOnly);
152 break; 155 Akonadi2::Storage storage2(testDataPath, dbName + "2", Akonadi2::Storage::ReadOnly);
156 for (int i = 0; i < count; i++) {
157 if (!verify(storage, i)) {
158 error = true;
159 break;
160 }
153 } 161 }
154 } 162 });
155 }); 163 }
156 } 164 for(auto future : futures) {
157 for(auto future : futures) { 165 future.waitForFinished();
158 future.waitForFinished(); 166 }
167 QVERIFY(!error);
159 } 168 }
160 QVERIFY(!error);
161 169
162 Akonadi2::Storage storage(testDataPath, dbName); 170 {
163 storage.removeFromDisk(); 171 Akonadi2::Storage storage(testDataPath, dbName);
172 storage.removeFromDisk();
173 }
164 } 174 }
165}; 175};
166 176