fix table dropping logic to ensure testcases run in fresh environment
This commit is contained in:
parent
e905e9e245
commit
8ff8c7b8c7
@ -311,8 +311,7 @@ shutdown_action (void *cls)
|
|||||||
GNUNET_OS_process_destroy (aggregator_proc);
|
GNUNET_OS_process_destroy (aggregator_proc);
|
||||||
aggregator_proc = NULL;
|
aggregator_proc = NULL;
|
||||||
}
|
}
|
||||||
plugin->drop_tables (plugin->cls,
|
plugin->drop_tables (plugin->cls);
|
||||||
session);
|
|
||||||
TALER_EXCHANGEDB_plugin_unload (plugin);
|
TALER_EXCHANGEDB_plugin_unload (plugin);
|
||||||
plugin = NULL;
|
plugin = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1856,11 +1856,7 @@ PERF_TALER_EXCHANGEDB_run_benchmark (const char *benchmark_name,
|
|||||||
}
|
}
|
||||||
/* Drop tables */
|
/* Drop tables */
|
||||||
{
|
{
|
||||||
struct TALER_EXCHANGEDB_Session *session;
|
ret = plugin->drop_tables (plugin->cls);
|
||||||
|
|
||||||
session = plugin->get_session (plugin->cls);
|
|
||||||
ret = plugin->drop_tables (plugin->cls,
|
|
||||||
session);
|
|
||||||
if (GNUNET_OK != ret)
|
if (GNUNET_OK != ret)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
|
@ -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.
|
* Function called by libpq whenever it wants to log something.
|
||||||
* We already log whenever we care, so this function does nothing
|
* We already log whenever we care, so this function does nothing
|
||||||
@ -211,6 +162,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
|
* Create the necessary tables if they are not present
|
||||||
*
|
*
|
||||||
|
@ -846,23 +846,7 @@ run (void *cls)
|
|||||||
result = 77;
|
result = 77;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (GNUNET_OK !=
|
(void) plugin->drop_tables (plugin->cls);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
plugin->create_tables (plugin->cls))
|
plugin->create_tables (plugin->cls))
|
||||||
{
|
{
|
||||||
@ -1283,10 +1267,8 @@ run (void *cls)
|
|||||||
plugin->free_reserve_history (plugin->cls,
|
plugin->free_reserve_history (plugin->cls,
|
||||||
rh);
|
rh);
|
||||||
rh = NULL;
|
rh = NULL;
|
||||||
if (NULL != session)
|
GNUNET_break (GNUNET_OK ==
|
||||||
GNUNET_break (GNUNET_OK ==
|
plugin->drop_tables (plugin->cls));
|
||||||
plugin->drop_tables (plugin->cls,
|
|
||||||
session));
|
|
||||||
if (NULL != dkp)
|
if (NULL != dkp)
|
||||||
destroy_denom_key_pair (dkp);
|
destroy_denom_key_pair (dkp);
|
||||||
if (NULL != cbc.sig.rsa_signature)
|
if (NULL != cbc.sig.rsa_signature)
|
||||||
|
@ -732,8 +732,7 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
|
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
(*drop_tables) (void *cls,
|
(*drop_tables) (void *cls);
|
||||||
struct TALER_EXCHANGEDB_Session *db);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user