mdbx-test: minor extension for jitter test case.

Trivial test for https://github.com/erthink/libmdbx/issues/146.

Change-Id: If5b365ebedf8609c9ec12569d5e5173799379195
This commit is contained in:
Leonid Yuriev 2020-12-17 15:42:23 +03:00
parent d77af0bc1f
commit 760f1654c2
2 changed files with 52 additions and 0 deletions

View File

@ -14,6 +14,14 @@
#include "test.h"
void testcase_jitter::check_dbi_error(int expect, const char *stage) {
MDBX_stat stat;
int err = mdbx_dbi_stat(txn_guard.get(), dbi, &stat, sizeof(stat));
if (err != expect)
failure("unexpected result for %s dbi-handle: expect %d, got %d", stage,
expect, err);
}
bool testcase_jitter::run() {
int err;
size_t upper_limit = config.params.size_upper;
@ -24,6 +32,47 @@ bool testcase_jitter::run() {
jitter_delay();
db_open();
if (!dbi && !mode_readonly()) {
// create table
txn_begin(false);
dbi = db_table_open(true);
check_dbi_error(MDBX_SUCCESS, "created-uncommitted");
// note: here and below the 4-byte length keys and value are used
// to be compatible with any Db-flags given from command line.
MDBX_val key = {(void *)"k000", 4}, value = {(void *)"v001", 4};
err = mdbx_put(txn_guard.get(), dbi, &key, &value, MDBX_UPSERT);
if (err != MDBX_SUCCESS)
failure_perror("jitter.put-1", err);
txn_end(false);
// drop & re-create table, but abort txn
txn_begin(false);
check_dbi_error(MDBX_SUCCESS, "created-committed");
err = mdbx_drop(txn_guard.get(), dbi, true);
if (unlikely(err != MDBX_SUCCESS))
failure_perror("mdbx_drop(delete=true)", err);
check_dbi_error(MDBX_BAD_DBI, "dropped-uncommitted");
dbi = db_table_open(true);
check_dbi_error(MDBX_SUCCESS, "recreated-uncommitted");
txn_end(true);
// check after aborted txn
txn_begin(false);
value = {(void *)"v002", 4};
err = mdbx_put(txn_guard.get(), dbi, &key, &value, MDBX_UPSERT);
if (err != MDBX_BAD_DBI)
failure_perror("jitter.put-2", err);
check_dbi_error(MDBX_BAD_DBI, "dropped-recreated-aborted");
// restore DBI
dbi = db_table_open(false);
check_dbi_error(MDBX_SUCCESS, "dropped-recreated-aborted+reopened");
value = {(void *)"v003", 4};
err = mdbx_put(txn_guard.get(), dbi, &key, &value, MDBX_UPSERT);
if (err != MDBX_SUCCESS)
failure_perror("jitter.put-3", err);
txn_end(false);
}
if (upper_limit < 1) {
MDBX_envinfo info;
err = mdbx_env_info_ex(db_guard.get(), txn_guard.get(), &info,

View File

@ -287,6 +287,9 @@ public:
};
class testcase_jitter : public testcase {
protected:
void check_dbi_error(int expect, const char *stage);
public:
testcase_jitter(const actor_config &config, const mdbx_pid_t pid)
: testcase(config, pid) {}