summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-02-27 22:19:21 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-02-27 22:50:23 +0100
commit1b31818b3cd48be19e2e29eefe91ecec2cbb69e2 (patch)
tree1c245ae319dc8b99ed62e04d4f1b2f6cc399de24 /tests
parentc51f447a476b1f5c3781bcea0ad19e969ba7564e (diff)
downloadsink-1b31818b3cd48be19e2e29eefe91ecec2cbb69e2.tar.gz
sink-1b31818b3cd48be19e2e29eefe91ecec2cbb69e2.zip
Make opening dbis non-racy
Dbis can only be opened by one thread and should then be shared accross all threads after committing the transaction to create the dbi. This requires us to initially open all db's, which in turn requires us to know the correct flags. This patch stores the flags to open each db in a separate db, and then opens up all databases on initial start. If a new database is created that dbi is as well shared as soon as the transaction is committed (before the dbi is private to the transaction).
Diffstat (limited to 'tests')
-rw-r--r--tests/storagetest.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp
index 5a517c7..7202628 100644
--- a/tests/storagetest.cpp
+++ b/tests/storagetest.cpp
@@ -451,6 +451,42 @@ private slots:
451 db.findLatest(uid, [&](const QByteArray &key, const QByteArray &value) { result = value; }); 451 db.findLatest(uid, [&](const QByteArray &key, const QByteArray &value) { result = value; });
452 QCOMPARE(result, QByteArray("value2")); 452 QCOMPARE(result, QByteArray("value2"));
453 } 453 }
454
455 void testTransactionVisibility()
456 {
457 auto readValue = [](const Sink::Storage::DataStore::NamedDatabase &db, const QByteArray) {
458 QByteArray result;
459 db.scan("key1", [&](const QByteArray &, const QByteArray &value) {
460 result = value;
461 return true;
462 });
463 return result;
464 };
465 {
466 Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite);
467 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite);
468
469 auto db = transaction.openDatabase("testTransactionVisibility", nullptr, false);
470 db.write("key1", "foo");
471 QCOMPARE(readValue(db, "key1"), QByteArray("foo"));
472
473 {
474 auto transaction2 = store.createTransaction(Sink::Storage::DataStore::ReadOnly);
475 auto db2 = transaction2
476 .openDatabase("testTransactionVisibility", nullptr, false);
477 QCOMPARE(readValue(db2, "key1"), QByteArray());
478 }
479 transaction.commit();
480 {
481 auto transaction2 = store.createTransaction(Sink::Storage::DataStore::ReadOnly);
482 auto db2 = transaction2
483 .openDatabase("testTransactionVisibility", nullptr, false);
484 QCOMPARE(readValue(db2, "key1"), QByteArray("foo"));
485 }
486
487 }
488 }
489
454}; 490};
455 491
456QTEST_MAIN(StorageTest) 492QTEST_MAIN(StorageTest)