From 3657dcd309f30b704801dcaf3e43b71ef703c0de Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 7 May 2017 11:27:40 +0200 Subject: Somewhat useless stress test... --- tests/CMakeLists.txt | 3 +++ tests/dbwriter.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ tests/storagetest.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tests/dbwriter.cpp 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 qt5_use_modules(sink_test Core Test Concurrent) target_link_libraries(sink_test sink libhawd KF5::Mime) +add_executable(dbwriter dbwriter.cpp) +target_link_libraries(dbwriter sink) + include(SinkTest) manual_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 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + + QByteArrayList arguments; + for (int i = 0; i < argc; i++) { + arguments << argv[i]; + } + auto testDataPath = arguments.value(1); + auto dbName = arguments.value(2); + auto count = arguments.value(3).toInt(); + + if (Sink::Storage::DataStore(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly).exists()) { + Sink::Storage::DataStore(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite).removeFromDisk(); + } + + qWarning() << "Creating db: " << testDataPath << dbName << count; + Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite); + for (int i = 0; i < count; i++) { + if (!transaction) { + qWarning() << "No valid transaction"; + return -1; + } + transaction.openDatabase("a", nullptr, false).write(QByteArray::number(i), "a"); + transaction.openDatabase("b", nullptr, false).write(QByteArray::number(i), "b"); + transaction.openDatabase("c", nullptr, false).write(QByteArray::number(i), "c"); + transaction.openDatabase("p", nullptr, false).write(QByteArray::number(i), "c"); + transaction.openDatabase("q", nullptr, false).write(QByteArray::number(i), "c"); + if (i > (count/2)) { + for (int d = 0; d < 40; d++) { + transaction.openDatabase("db" + QByteArray::number(d), nullptr, false).write(QByteArray::number(i), "a"); + } + } + if ((i % 1000) == 0) { + transaction.commit(); + transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite); + } + } + qWarning() << "Creating db done."; + return 0; +} 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: transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); } } + + /* + * This test is meant to find problems with the multi-process architecture and initial database creation. + * If we create named databases dynamically (not all up front), it is possilbe that we violate the rule + * that mdb_open_dbi may only be used by a single thread at a time. + * This test is meant to stress that condition. + * + * However, it yields absolutely nothing. + */ + void testReadDuringExternalProcessWrite() + { + QSKIP("Not running multiprocess test"); + + QList> futures; + for (int i = 0; i < 5; i++) { + futures << QtConcurrent::run([&]() { + QTRY_VERIFY(Sink::Storage::DataStore(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly).exists()); + Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly); + auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); + for (int i = 0; i < 100000; i++) { + transaction.openDatabase("a", nullptr, false); + transaction.openDatabase("b", nullptr, false); + transaction.openDatabase("c", nullptr, false); + transaction.openDatabase("p", nullptr, false); + transaction.openDatabase("q", nullptr, false); + } + }); + } + + //Start writing to the db from a separate process + QVERIFY(QProcess::startDetached(QCoreApplication::applicationDirPath() + "/dbwriter", QStringList() << testDataPath << dbName << QString::number(100000))); + + for (auto future : futures) { + future.waitForFinished(); + } + + } }; QTEST_MAIN(StorageTest) -- cgit v1.2.3