Skip to content

Commit

Permalink
test: avoid cc related test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
kuron99 committed Apr 17, 2024
1 parent 5e2bd90 commit cf360bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 6 additions & 2 deletions shirakami/test/ApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
20 changes: 19 additions & 1 deletion shirakami/test/ccTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transaction> tx{};
EXPECT_EQ(StatusCode::OK, db->create_transaction(tx));
std::unique_ptr<Storage> st{};
EXPECT_EQ(db->get_storage("S", st), StatusCode::OK);
std::unique_ptr<Iterator> 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);
}

Expand Down

0 comments on commit cf360bd

Please sign in to comment.