test: canary fetch/update for jitter testcase.

Change-Id: I8402328f880addb1170e8e778b64aa4f12d18718
This commit is contained in:
Leo Yuriev 2017-04-23 19:00:28 +03:00
parent ce9c4acea6
commit 32937ac63b
3 changed files with 50 additions and 4 deletions

View File

@ -31,27 +31,29 @@ bool testcase_jitter::run() {
if (flipcoin()) {
jitter_delay();
txn_begin(true);
fetch_canary();
jitter_delay();
txn_end(false);
txn_end(flipcoin());
}
jitter_delay();
txn_begin(mode_readonly());
jitter_delay();
if (!mode_readonly()) {
fetch_canary();
update_canary(1);
/* TODO:
* - db_sequence()
* - db_setsize()
* ...
*/
}
txn_end(false);
txn_end(flipcoin());
if (flipcoin()) {
jitter_delay();
txn_begin(true);
jitter_delay();
txn_end(false);
txn_end(flipcoin());
}
jitter_delay();

View File

@ -252,6 +252,43 @@ bool testcase::should_continue() const {
return result;
}
void testcase::fetch_canary() {
mdbx_canary canary_now;
log_trace(">> fetch_canary");
int rc = mdbx_canary_get(txn_guard.get(), &canary_now);
if (rc != MDB_SUCCESS)
failure_perror("mdbx_canary_get()", rc);
if (canary_now.v < last.canary.v)
failure("fetch_canary: %" PRIu64 " canary-now.v) < %" PRIu64
"(canary-last.v)",
canary_now.v, last.canary.v);
if (canary_now.y < last.canary.y)
failure("fetch_canary: %" PRIu64 "(canary-now.y) < %" PRIu64
"(canary-last.y)",
canary_now.y, last.canary.y);
last.canary = canary_now;
log_trace("<< fetch_canary: db-sequence %" PRIu64
", db-sequence.txnid %" PRIu64,
last.canary.y, last.canary.v);
}
void testcase::update_canary(uint64_t increment) {
mdbx_canary canary_now = last.canary;
log_trace(">> update_canary: sequence %" PRIu64 " += %" PRIu64, canary_now.y,
increment);
canary_now.y += increment;
int rc = mdbx_canary_put(txn_guard.get(), &canary_now);
if (rc != MDB_SUCCESS)
failure_perror("mdbx_canary_put()", rc);
log_trace(">> update_canary: sequence = %" PRIu64, canary_now.y);
}
//-----------------------------------------------------------------------------
bool test_execute(const actor_config &config) {

View File

@ -88,11 +88,17 @@ protected:
size_t nops_completed;
chrono::time start_timestamp;
struct {
mdbx_canary canary;
} last;
void db_prepare();
void db_open();
void db_close();
void txn_begin(bool readonly);
void txn_end(bool abort);
void fetch_canary();
void update_canary(uint64_t increment);
bool wait4start();
void report(size_t nops_done);
@ -107,6 +113,7 @@ public:
testcase(const actor_config &config, const mdbx_pid_t pid)
: config(config), pid(pid), nops_completed(0) {
start_timestamp.reset();
memset(&last, 0, sizeof(last));
}
virtual bool setup();