mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-20 05:08:21 +08:00
Add test case for txn try
This commit is contained in:
parent
2f1f4b19a0
commit
088e811da4
@ -67,6 +67,7 @@ void testcase_setup(const char *casename, actor_params ¶ms,
|
|||||||
configure_actor(last_space_id, ac_hill, nullptr, params);
|
configure_actor(last_space_id, ac_hill, nullptr, params);
|
||||||
configure_actor(last_space_id, ac_jitter, nullptr, params);
|
configure_actor(last_space_id, ac_jitter, nullptr, params);
|
||||||
configure_actor(last_space_id, ac_hill, nullptr, params);
|
configure_actor(last_space_id, ac_hill, nullptr, params);
|
||||||
|
configure_actor(last_space_id, ac_try, nullptr, params);
|
||||||
log_notice("<<< testcase_setup(%s): done", casename);
|
log_notice("<<< testcase_setup(%s): done", casename);
|
||||||
} else {
|
} else {
|
||||||
failure("unknown testcase `%s`", casename);
|
failure("unknown testcase `%s`", casename);
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#define ACTOR_ID_MAX INT16_MAX
|
#define ACTOR_ID_MAX INT16_MAX
|
||||||
|
|
||||||
enum actor_testcase { ac_none, ac_hill, ac_deadread, ac_deadwrite, ac_jitter };
|
enum actor_testcase { ac_none, ac_hill, ac_deadread, ac_deadwrite, ac_jitter, ac_try };
|
||||||
|
|
||||||
enum actor_status {
|
enum actor_status {
|
||||||
as_unknown,
|
as_unknown,
|
||||||
|
@ -29,6 +29,8 @@ const char *testcase2str(const actor_testcase testcase) {
|
|||||||
return "deadwrite";
|
return "deadwrite";
|
||||||
case ac_jitter:
|
case ac_jitter:
|
||||||
return "jitter";
|
return "jitter";
|
||||||
|
case ac_try:
|
||||||
|
return "try";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,6 +445,9 @@ bool test_execute(const actor_config &config) {
|
|||||||
case ac_jitter:
|
case ac_jitter:
|
||||||
test.reset(new testcase_jitter(config, pid));
|
test.reset(new testcase_jitter(config, pid));
|
||||||
break;
|
break;
|
||||||
|
case ac_try:
|
||||||
|
test.reset(new testcase_try(config, pid));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
test.reset(new testcase(config, pid));
|
test.reset(new testcase(config, pid));
|
||||||
break;
|
break;
|
||||||
|
11
test/test.h
11
test/test.h
@ -190,3 +190,14 @@ public:
|
|||||||
bool run();
|
bool run();
|
||||||
bool teardown();
|
bool teardown();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class testcase_try : public testcase {
|
||||||
|
typedef testcase inherited;
|
||||||
|
|
||||||
|
public:
|
||||||
|
testcase_try(const actor_config &config, const mdbx_pid_t pid)
|
||||||
|
: testcase(config, pid) {}
|
||||||
|
bool setup();
|
||||||
|
bool run();
|
||||||
|
bool teardown();
|
||||||
|
};
|
||||||
|
38
test/try.cc
Normal file
38
test/try.cc
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
bool testcase_try::setup() {
|
||||||
|
log_trace(">> setup");
|
||||||
|
if (!inherited::setup())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
log_trace("<< setup");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool testcase_try::run() {
|
||||||
|
db_open();
|
||||||
|
assert(!txn_guard);
|
||||||
|
|
||||||
|
MDBX_txn *txn = nullptr;
|
||||||
|
MDBX_txn *txn2 = nullptr;
|
||||||
|
int rc =
|
||||||
|
mdbx_txn_begin(db_guard.get(), nullptr, 0, &txn);
|
||||||
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
|
failure_perror("mdbx_txn_begin(MDBX_TRYTXN)", rc);
|
||||||
|
else {
|
||||||
|
rc = mdbx_txn_begin(db_guard.get(), nullptr, MDBX_TRYTXN, &txn2);
|
||||||
|
if (unlikely(rc != MDBX_BUSY))
|
||||||
|
failure_perror("mdbx_txn_begin(MDBX_TRYTXN)", rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
txn_guard.reset(txn);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool testcase_try::teardown() {
|
||||||
|
log_trace(">> teardown");
|
||||||
|
cursor_guard.release();
|
||||||
|
txn_guard.release();
|
||||||
|
db_guard.release();
|
||||||
|
return inherited::teardown();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user