From ebaaf226ca3f7437e5f36fda12031b23c7c57336 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Thu, 2 Mar 2017 18:15:05 +1100 Subject: [PATCH] ctdb-tests: Generalize transaction_loop test Instead of hard-coding the database name, it's passed as an argument along with database type. Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/tests/simple/53_transaction_loop.sh | 9 ++++--- ctdb/tests/simple/54_transaction_loop_recovery.sh | 9 ++++--- ctdb/tests/src/transaction_loop.c | 31 ++++++++++++++--------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/ctdb/tests/simple/53_transaction_loop.sh b/ctdb/tests/simple/53_transaction_loop.sh index f00fe1e63a1..8291a8d55b1 100755 --- a/ctdb/tests/simple/53_transaction_loop.sh +++ b/ctdb/tests/simple/53_transaction_loop.sh @@ -19,8 +19,10 @@ set -e cluster_is_healthy -try_command_on_node 0 "$CTDB attach transaction_loop.tdb persistent" -try_command_on_node 0 "$CTDB wipedb transaction_loop.tdb" +TESTDB="persistent_trans.tdb" + +try_command_on_node 0 "$CTDB attach $TESTDB persistent" +try_command_on_node 0 "$CTDB wipedb $TESTDB" try_command_on_node 0 "$CTDB listnodes" num_nodes=$(echo "$out" | wc -l) @@ -30,7 +32,8 @@ if [ -z "$CTDB_TEST_TIMELIMIT" ] ; then fi t="$CTDB_TEST_WRAPPER $VALGRIND transaction_loop \ - -n ${num_nodes} -t ${CTDB_TEST_TIMELIMIT}" + -n ${num_nodes} -t ${CTDB_TEST_TIMELIMIT} \ + -D ${TESTDB} -T persistent -k testkey" echo "Running transaction_loop on all $num_nodes nodes." try_command_on_node -v -p all "$t" diff --git a/ctdb/tests/simple/54_transaction_loop_recovery.sh b/ctdb/tests/simple/54_transaction_loop_recovery.sh index db70c1b90db..a5d94ffbf89 100755 --- a/ctdb/tests/simple/54_transaction_loop_recovery.sh +++ b/ctdb/tests/simple/54_transaction_loop_recovery.sh @@ -40,8 +40,10 @@ cluster_is_healthy ctdb_restart_when_done -try_command_on_node 0 "$CTDB attach transaction_loop.tdb persistent" -try_command_on_node 0 "$CTDB wipedb transaction_loop.tdb" +TESTDB="persistent_trans.tdb" + +try_command_on_node 0 "$CTDB attach $TESTDB persistent" +try_command_on_node 0 "$CTDB wipedb $TESTDB" try_command_on_node 0 "$CTDB listnodes" num_nodes=$(echo "$out" | wc -l) @@ -51,7 +53,8 @@ if [ -z "$CTDB_TEST_TIMELIMIT" ] ; then fi t="$CTDB_TEST_WRAPPER $VALGRIND transaction_loop \ - -n ${num_nodes} -t ${CTDB_TEST_TIMELIMIT}" + -n ${num_nodes} -t ${CTDB_TEST_TIMELIMIT} \ + -D ${TESTDB} -T persistent -k testkey" echo "Starting recovery loop" recovery_loop_start diff --git a/ctdb/tests/src/transaction_loop.c b/ctdb/tests/src/transaction_loop.c index 0fd2953d1a1..66237512c87 100644 --- a/ctdb/tests/src/transaction_loop.c +++ b/ctdb/tests/src/transaction_loop.c @@ -26,10 +26,6 @@ #include "tests/src/test_options.h" #include "tests/src/cluster_wait.h" -#define TESTDB "transaction_loop.tdb" -#define TESTKEY "testkey" - - struct transaction_loop_state { struct tevent_context *ev; struct ctdb_client_context *client; @@ -56,7 +52,8 @@ static struct tevent_req *transaction_loop_send( struct tevent_context *ev, struct ctdb_client_context *client, struct ctdb_db_context *ctdb_db, - int num_nodes, int timelimit, int interactive) + int num_nodes, int timelimit, int interactive, + const char *keystr) { struct tevent_req *req, *subreq; struct transaction_loop_state *state; @@ -73,8 +70,8 @@ static struct tevent_req *transaction_loop_send( state->num_nodes = num_nodes; state->timelimit = timelimit; state->interactive = interactive; - state->key.dptr = discard_const(TESTKEY); - state->key.dsize = strlen(TESTKEY); + state->key.dptr = discard_const(keystr); + state->key.dsize = strlen(keystr); state->pnn = ctdb_client_pnn(client); state->old_counter = talloc_zero_array(state, uint32_t, num_nodes); if (tevent_req_nomem(state->old_counter, req)) { @@ -341,10 +338,11 @@ int main(int argc, const char *argv[]) struct ctdb_client_context *client; struct ctdb_db_context *ctdb_db; struct tevent_req *req; + uint8_t db_flags; int ret; bool status; - status = process_options_basic(argc, argv, &opts); + status = process_options_database(argc, argv, &opts); if (! status) { exit(1); } @@ -372,17 +370,26 @@ int main(int argc, const char *argv[]) exit(1); } - ret = ctdb_attach(ev, client, tevent_timeval_zero(), TESTDB, - CTDB_DB_FLAGS_PERSISTENT, &ctdb_db); + if (strcmp(opts->dbtype, "persistent") == 0) { + db_flags = CTDB_DB_FLAGS_PERSISTENT; + } else if (strcmp(opts->dbtype, "replicated") == 0) { + db_flags = CTDB_DB_FLAGS_REPLICATED; + } else { + fprintf(stderr, "Database must be persistent or replicated\n"); + exit(1); + } + + ret = ctdb_attach(ev, client, tevent_timeval_zero(), opts->dbname, + db_flags, &ctdb_db); if (ret != 0) { fprintf(stderr, "Failed to attach to persistent DB %s\n", - TESTDB); + opts->dbname); exit(1); } req = transaction_loop_send(mem_ctx, ev, client, ctdb_db, opts->num_nodes, opts->timelimit, - opts->interactive); + opts->interactive, opts->keystr); if (req == NULL) { fprintf(stderr, "Memory allocation error\n"); exit(1); -- 2.11.4.GIT