diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-05-18 17:19:32 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-05-18 17:19:32 +0200 |
commit | 8ff8c7b8c7015970c65849e0550ed4a0e54be2ad (patch) | |
tree | 244fcee453b05aedbd8375bfcb3a25ab7e3a46cd | |
parent | e905e9e245149627bdecd14370c3bde3fd079375 (diff) |
fix table dropping logic to ensure testcases run in fresh environment
-rw-r--r-- | src/exchange/test_taler_exchange_aggregator.c | 3 | ||||
-rw-r--r-- | src/exchangedb/perf_taler_exchangedb_interpreter.c | 6 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 112 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 24 | ||||
-rw-r--r-- | src/include/taler_exchangedb_plugin.h | 3 |
5 files changed, 69 insertions, 79 deletions
diff --git a/src/exchange/test_taler_exchange_aggregator.c b/src/exchange/test_taler_exchange_aggregator.c index a88d222c3..411bef029 100644 --- a/src/exchange/test_taler_exchange_aggregator.c +++ b/src/exchange/test_taler_exchange_aggregator.c @@ -311,8 +311,7 @@ shutdown_action (void *cls) GNUNET_OS_process_destroy (aggregator_proc); aggregator_proc = NULL; } - plugin->drop_tables (plugin->cls, - session); + plugin->drop_tables (plugin->cls); TALER_EXCHANGEDB_plugin_unload (plugin); plugin = NULL; } diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.c b/src/exchangedb/perf_taler_exchangedb_interpreter.c index 661cfeef3..5a2eed95f 100644 --- a/src/exchangedb/perf_taler_exchangedb_interpreter.c +++ b/src/exchangedb/perf_taler_exchangedb_interpreter.c @@ -1856,11 +1856,7 @@ PERF_TALER_EXCHANGEDB_run_benchmark (const char *benchmark_name, } /* Drop tables */ { - struct TALER_EXCHANGEDB_Session *session; - - session = plugin->get_session (plugin->cls); - ret = plugin->drop_tables (plugin->cls, - session); + ret = plugin->drop_tables (plugin->cls); if (GNUNET_OK != ret) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index cda2df0d0..44096f17f 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -128,55 +128,6 @@ struct PostgresClosure }; - - -/** - * Drop all Taler tables. This should only be used by testcases. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param session database session to use - * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure - */ -static int -postgres_drop_tables (void *cls, - struct TALER_EXCHANGEDB_Session *session) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Dropping ALL tables\n"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS prewire;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS aggregation_tracking;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS deposits;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS refresh_out;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS refresh_commit_coin;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS refresh_commit_link;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS refunds;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS refresh_order;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS refresh_sessions;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS known_coins;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS reserves_out;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS reserves_in;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS reserves;"); - SQLEXEC_ (session->conn, - "DROP TABLE IF EXISTS denominations;"); - return GNUNET_OK; - SQLEXEC_fail: - return GNUNET_SYSERR; -} - - /** * Function called by libpq whenever it wants to log something. * We already log whenever we care, so this function does nothing @@ -212,6 +163,69 @@ pq_notice_processor_cb (void *arg, /** + * Drop all Taler tables. This should only be used by testcases. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure + */ +static int +postgres_drop_tables (void *cls) +{ + struct PostgresClosure *pc = cls; + PGconn *conn; + + conn = PQconnectdb (pc->connection_cfg_str); + if (CONNECTION_OK != + PQstatus (conn)) + { + TALER_LOG_ERROR ("Database connection failed: %s\n", + PQerrorMessage (conn)); + GNUNET_break (0); + return GNUNET_SYSERR; + } + PQsetNoticeReceiver (conn, + &pq_notice_receiver_cb, + NULL); + PQsetNoticeProcessor (conn, + &pq_notice_processor_cb, + NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Dropping ALL tables\n"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS prewire;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS aggregation_tracking;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS deposits;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS refresh_out;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS refresh_commit_coin;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS refresh_commit_link;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS refunds;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS refresh_order;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS refresh_sessions CASCADE;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS known_coins CASCADE;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS reserves_out;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS reserves_in;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS reserves;"); + SQLEXEC_ (conn, + "DROP TABLE IF EXISTS denominations CASCADE;"); + return GNUNET_OK; + SQLEXEC_fail: + return GNUNET_SYSERR; +} + + +/** * Create the necessary tables if they are not present * * @param cls the `struct PostgresClosure` with the plugin-specific state diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 3169f06db..9b84d739d 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -846,23 +846,7 @@ run (void *cls) result = 77; return; } - if (GNUNET_OK != - plugin->create_tables (plugin->cls)) - { - result = 77; - goto drop; - } - if (NULL != - (session = plugin->get_session (plugin->cls))) - { - if (GNUNET_OK != - plugin->drop_tables (plugin->cls, - session)) - { - result = 77; - goto drop; - } - } + (void) plugin->drop_tables (plugin->cls); if (GNUNET_OK != plugin->create_tables (plugin->cls)) { @@ -1283,10 +1267,8 @@ run (void *cls) plugin->free_reserve_history (plugin->cls, rh); rh = NULL; - if (NULL != session) - GNUNET_break (GNUNET_OK == - plugin->drop_tables (plugin->cls, - session)); + GNUNET_break (GNUNET_OK == + plugin->drop_tables (plugin->cls)); if (NULL != dkp) destroy_denom_key_pair (dkp); if (NULL != cbc.sig.rsa_signature) diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 2cc3b439c..4c6f546f9 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -732,8 +732,7 @@ struct TALER_EXCHANGEDB_Plugin * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure */ int - (*drop_tables) (void *cls, - struct TALER_EXCHANGEDB_Session *db); + (*drop_tables) (void *cls); /** |