diff --git a/shirakami/test/ApiTest.cpp b/shirakami/test/ApiTest.cpp index 0245da6..76cdad2 100644 --- a/shirakami/test/ApiTest.cpp +++ b/shirakami/test/ApiTest.cpp @@ -1442,6 +1442,10 @@ TEST_F(ShirakamiApiTest, tracking) { } TEST_F(ShirakamiApiTest, transaction_begin_and_commit) { + // verify two conflicting transactions repeat begin/commit and finally meet the goal + // note: even if this test fails intermittently, you don't need to worry if re-run is successful + // due to the environment or resource, the test may fail in low probability + constexpr std::size_t retry = 200; DatabaseOptions options; options.attribute(KEY_LOCATION, path()); DatabaseHandle db; @@ -1500,7 +1504,7 @@ TEST_F(ShirakamiApiTest, transaction_begin_and_commit) { ASSERT_EQ(transaction_exec(db, {}, &S::prepare, &s), StatusCode::OK); auto r1 = std::async(std::launch::async, [&] { std::size_t count = 5; - for (std::size_t i = 0U; i < 100U; ++i) { + for (std::size_t i = 0U; i < retry; ++i) { if (S::run(db, s)) { count--; if (count == 0) { @@ -1513,7 +1517,7 @@ TEST_F(ShirakamiApiTest, transaction_begin_and_commit) { }); std::size_t count = 5; bool success = false; - for (std::size_t i = 0U; i < 100U; ++i) { + for (std::size_t i = 0U; i < retry; ++i) { if (S::run(db, s)) { count--; if (count == 0) { diff --git a/shirakami/test/ccTest.cpp b/shirakami/test/ccTest.cpp index de776b4..6b694fc 100644 --- a/shirakami/test/ccTest.cpp +++ b/shirakami/test/ccTest.cpp @@ -290,8 +290,26 @@ TEST_F(ShirakamiCCTest, scan_and_delete) { EXPECT_EQ(tx3->commit(), StatusCode::OK); return true; }); - EXPECT_GE(r1.get(), 2); EXPECT_TRUE(r2.get()); + { + std::unique_ptr tx{}; + EXPECT_EQ(StatusCode::OK, db->create_transaction(tx)); + std::unique_ptr st{}; + EXPECT_EQ(db->get_storage("S", st), StatusCode::OK); + std::unique_ptr it{}; + EXPECT_EQ(st->scan(tx.get(), + "", EndPointKind::UNBOUND, + "", EndPointKind::UNBOUND, + it), StatusCode::OK); + auto iter = test_iterator(std::move(it)); + StatusCode rc{}; + std::size_t row_count = 0; + while((rc = iter->next()) == StatusCode::OK) { + ++row_count; + } + EXPECT_EQ(tx->commit(), StatusCode::OK); + EXPECT_EQ(row_count, 0); + } EXPECT_EQ(db->close(), StatusCode::OK); }