summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-07 11:27:40 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-07 11:27:40 +0200
commit3657dcd309f30b704801dcaf3e43b71ef703c0de (patch)
treef7b1cadf66c19b39c3eee9b34573bb965b7db2dd /tests
parentf52ed4fd64994985f1061c5fcd20dccaa61fbc67 (diff)
downloadsink-3657dcd309f30b704801dcaf3e43b71ef703c0de.tar.gz
sink-3657dcd309f30b704801dcaf3e43b71ef703c0de.zip
Somewhat useless stress test...
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/dbwriter.cpp45
-rw-r--r--tests/storagetest.cpp37
3 files changed, 85 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index c77a736..2b3e7b1 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -16,6 +16,9 @@ add_library(sink_test SHARED testimplementations.cpp getrssusage.cpp mailtest.cp
16qt5_use_modules(sink_test Core Test Concurrent) 16qt5_use_modules(sink_test Core Test Concurrent)
17target_link_libraries(sink_test sink libhawd KF5::Mime) 17target_link_libraries(sink_test sink libhawd KF5::Mime)
18 18
19add_executable(dbwriter dbwriter.cpp)
20target_link_libraries(dbwriter sink)
21
19include(SinkTest) 22include(SinkTest)
20 23
21manual_tests ( 24manual_tests (
diff --git a/tests/dbwriter.cpp b/tests/dbwriter.cpp
new file mode 100644
index 0000000..902a607
--- /dev/null
+++ b/tests/dbwriter.cpp
@@ -0,0 +1,45 @@
1#include <QByteArrayList>
2#include <QDebug>
3#include <storage.h>
4
5int main(int argc, char *argv[])
6{
7
8 QByteArrayList arguments;
9 for (int i = 0; i < argc; i++) {
10 arguments << argv[i];
11 }
12 auto testDataPath = arguments.value(1);
13 auto dbName = arguments.value(2);
14 auto count = arguments.value(3).toInt();
15
16 if (Sink::Storage::DataStore(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly).exists()) {
17 Sink::Storage::DataStore(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite).removeFromDisk();
18 }
19
20 qWarning() << "Creating db: " << testDataPath << dbName << count;
21 Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite);
22 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite);
23 for (int i = 0; i < count; i++) {
24 if (!transaction) {
25 qWarning() << "No valid transaction";
26 return -1;
27 }
28 transaction.openDatabase("a", nullptr, false).write(QByteArray::number(i), "a");
29 transaction.openDatabase("b", nullptr, false).write(QByteArray::number(i), "b");
30 transaction.openDatabase("c", nullptr, false).write(QByteArray::number(i), "c");
31 transaction.openDatabase("p", nullptr, false).write(QByteArray::number(i), "c");
32 transaction.openDatabase("q", nullptr, false).write(QByteArray::number(i), "c");
33 if (i > (count/2)) {
34 for (int d = 0; d < 40; d++) {
35 transaction.openDatabase("db" + QByteArray::number(d), nullptr, false).write(QByteArray::number(i), "a");
36 }
37 }
38 if ((i % 1000) == 0) {
39 transaction.commit();
40 transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite);
41 }
42 }
43 qWarning() << "Creating db done.";
44 return 0;
45}
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp
index dfb91ec..9e9bad9 100644
--- a/tests/storagetest.cpp
+++ b/tests/storagetest.cpp
@@ -505,6 +505,43 @@ private slots:
505 transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); 505 transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly);
506 } 506 }
507 } 507 }
508
509 /*
510 * This test is meant to find problems with the multi-process architecture and initial database creation.
511 * If we create named databases dynamically (not all up front), it is possilbe that we violate the rule
512 * that mdb_open_dbi may only be used by a single thread at a time.
513 * This test is meant to stress that condition.
514 *
515 * However, it yields absolutely nothing.
516 */
517 void testReadDuringExternalProcessWrite()
518 {
519 QSKIP("Not running multiprocess test");
520
521 QList<QFuture<void>> futures;
522 for (int i = 0; i < 5; i++) {
523 futures << QtConcurrent::run([&]() {
524 QTRY_VERIFY(Sink::Storage::DataStore(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly).exists());
525 Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly);
526 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly);
527 for (int i = 0; i < 100000; i++) {
528 transaction.openDatabase("a", nullptr, false);
529 transaction.openDatabase("b", nullptr, false);
530 transaction.openDatabase("c", nullptr, false);
531 transaction.openDatabase("p", nullptr, false);
532 transaction.openDatabase("q", nullptr, false);
533 }
534 });
535 }
536
537 //Start writing to the db from a separate process
538 QVERIFY(QProcess::startDetached(QCoreApplication::applicationDirPath() + "/dbwriter", QStringList() << testDataPath << dbName << QString::number(100000)));
539
540 for (auto future : futures) {
541 future.waitForFinished();
542 }
543
544 }
508}; 545};
509 546
510QTEST_MAIN(StorageTest) 547QTEST_MAIN(StorageTest)