enable using python bank with benchmark

This commit is contained in:
Christian Grothoff 2020-03-19 21:44:54 +01:00
parent f76e7c46e6
commit 7a1c6769e4
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 199 additions and 103 deletions

View File

@ -40,25 +40,33 @@ host = localhost
# Adjust $HOME to match remote target! # Adjust $HOME to match remote target!
dir = $HOME/repos/taler/exchange/src/benchmark dir = $HOME/repos/taler/exchange/src/benchmark
[bank]
HTTP_PORT = 8082
SERVE = http
MAX_DEBT = EUR:100000000000.0
MAX_DEBT_BANK = EUR:1000000000000000.0
[benchmark] [benchmark]
USER_PAYTO_URI = payto://x-taler-bank/localhost:8082/42 USER_PAYTO_URI = payto://x-taler-bank/localhost:8082/42
[exchange-account-2] [exchange-account-2]
# What is the payto://-URL of the exchange (to generate wire response) # What is the payto://-URL of the exchange (to generate wire response)
PAYTO_URI = "payto://x-taler-bank/localhost:8082/2" PAYTO_URI = "payto://x-taler-bank/localhost:8082/Exchange"
# What is the bank account (with the "Taler Bank" demo system)? Must end with "/". # What is the bank account (with the "Taler Bank" demo system)? Must end with "/".
WIRE_GATEWAY_URL = http://localhost:8082/2/ WIRE_GATEWAY_URL = http://localhost:8082/taler-wire-gateway/Exchange/
# This is the response we give out for the /wire request. It provides # This is the response we give out for the /wire request. It provides
# wallets with the bank information for transfers to the exchange. # wallets with the bank information for transfers to the exchange.
WIRE_RESPONSE = ${TALER_CONFIG_HOME}/account-2.json WIRE_RESPONSE = ${TALER_CONFIG_HOME}/account-exchange.json
# Authentication information for basic authentication # Authentication information for basic authentication
WIRE_GATEWAY_AUTH_METHOD = "basic" WIRE_GATEWAY_AUTH_METHOD = "basic"
username = user username = Exchange
password = pass password = x
enable_debit = YES enable_debit = YES
enable_credit = YES enable_credit = YES
[fees-x-taler-bank] [fees-x-taler-bank]
# Fees for the forseeable future... # Fees for the forseeable future...
# If you see this after 2017, update to match the next 10 years... # If you see this after 2017, update to match the next 10 years...

View File

@ -110,11 +110,21 @@ static struct GNUNET_TIME_Relative duration;
*/ */
static struct TALER_TESTING_Command *all_commands; static struct TALER_TESTING_Command *all_commands;
/**
* Name of our configuration file.
*/
static char *cfg_filename;
/** /**
* Exit code. * Exit code.
*/ */
static int result; static int result;
/**
* Use the fakebank instead of the Python bank.
*/
static int use_fakebank;
/** /**
* How many coins we want to create per client and reserve. * How many coins we want to create per client and reserve.
*/ */
@ -135,6 +145,11 @@ static unsigned int refresh_rate = 10;
*/ */
static unsigned int howmany_clients = 1; static unsigned int howmany_clients = 1;
/**
* Bank configuration to use.
*/
static struct TALER_TESTING_BankConfiguration bc;
/** /**
* Log level used during the run. * Log level used during the run.
*/ */
@ -475,6 +490,7 @@ parallel_benchmark (TALER_TESTING_Main main_cb,
pid_t cpids[howmany_clients]; pid_t cpids[howmany_clients];
pid_t fakebank = -1; pid_t fakebank = -1;
int wstatus; int wstatus;
struct GNUNET_OS_Process *bankd = NULL;
struct GNUNET_OS_Process *auditord = NULL; struct GNUNET_OS_Process *auditord = NULL;
struct GNUNET_OS_Process *exchanged = NULL; struct GNUNET_OS_Process *exchanged = NULL;
struct GNUNET_OS_Process *wirewatch = NULL; struct GNUNET_OS_Process *wirewatch = NULL;
@ -483,22 +499,41 @@ parallel_benchmark (TALER_TESTING_Main main_cb,
if ( (MODE_CLIENT == mode) || (MODE_BOTH == mode) ) if ( (MODE_CLIENT == mode) || (MODE_BOTH == mode) )
{ {
/* start fakebank */ if (use_fakebank)
fakebank = fork ();
if (0 == fakebank)
{ {
GNUNET_log_setup ("benchmark-fakebank", /* start fakebank */
NULL == loglev ? "INFO" : loglev, fakebank = fork ();
logfile); if (0 == fakebank)
GNUNET_SCHEDULER_run (&launch_fakebank, {
NULL); GNUNET_log_setup ("benchmark-fakebank",
exit (0); NULL == loglev ? "INFO" : loglev,
logfile);
GNUNET_SCHEDULER_run (&launch_fakebank,
NULL);
exit (0);
}
if (-1 == fakebank)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
"fork");
return GNUNET_SYSERR;
}
} }
if (-1 == fakebank) else
{ {
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, /* start bank */
"fork"); if (GNUNET_OK !=
return GNUNET_SYSERR; TALER_TESTING_prepare_bank (cfg_filename,
GNUNET_NO,
"exchange-account-2",
&bc))
{
return 1;
}
bankd = TALER_TESTING_run_bank (cfg_filename,
"http://localhost:8082/");
if (NULL == bankd)
return 77;
} }
} }
@ -515,12 +550,20 @@ parallel_benchmark (TALER_TESTING_Main main_cb,
NULL); NULL);
if ( (NULL == exchanged) && (MODE_BOTH == mode) ) if ( (NULL == exchanged) && (MODE_BOTH == mode) )
{ {
GNUNET_assert (-1 != fakebank); if (-1 != fakebank)
kill (fakebank, {
SIGTERM); kill (fakebank,
waitpid (fakebank, SIGTERM);
&wstatus, waitpid (fakebank,
0); &wstatus,
0);
}
if (NULL != bankd)
{
GNUNET_OS_process_kill (bankd,
SIGTERM);
GNUNET_OS_process_destroy (bankd);
}
return 77; return 77;
} }
/* start auditor */ /* start auditor */
@ -537,12 +580,20 @@ parallel_benchmark (TALER_TESTING_Main main_cb,
SIGTERM); SIGTERM);
if (MODE_BOTH == mode) if (MODE_BOTH == mode)
{ {
GNUNET_assert (-1 != fakebank); if (-1 != fakebank)
kill (fakebank, {
SIGTERM); kill (fakebank,
waitpid (fakebank, SIGTERM);
&wstatus, waitpid (fakebank,
0); &wstatus,
0);
}
if (NULL != bankd)
{
GNUNET_OS_process_kill (bankd,
SIGTERM);
GNUNET_OS_process_destroy (bankd);
}
} }
GNUNET_OS_process_destroy (exchanged); GNUNET_OS_process_destroy (exchanged);
return 77; return 77;
@ -563,12 +614,20 @@ parallel_benchmark (TALER_TESTING_Main main_cb,
SIGTERM); SIGTERM);
if (MODE_BOTH == mode) if (MODE_BOTH == mode)
{ {
GNUNET_assert (-1 != fakebank); if (-1 != fakebank)
kill (fakebank, {
SIGTERM); kill (fakebank,
waitpid (fakebank, SIGTERM);
&wstatus, waitpid (fakebank,
0); &wstatus,
0);
}
if (NULL != bankd)
{
GNUNET_OS_process_kill (bankd,
SIGTERM);
GNUNET_OS_process_destroy (bankd);
}
} }
GNUNET_OS_process_destroy (exchanged); GNUNET_OS_process_destroy (exchanged);
return 77; return 77;
@ -618,12 +677,20 @@ parallel_benchmark (TALER_TESTING_Main main_cb,
SIGTERM); SIGTERM);
if ( (MODE_BOTH == mode) || (MODE_CLIENT == mode)) if ( (MODE_BOTH == mode) || (MODE_CLIENT == mode))
{ {
GNUNET_assert (-1 != fakebank); if (-1 != fakebank)
kill (fakebank, {
SIGTERM); kill (fakebank,
waitpid (fakebank, SIGTERM);
&wstatus, waitpid (fakebank,
0); &wstatus,
0);
}
if (NULL != bankd)
{
GNUNET_OS_process_kill (bankd,
SIGTERM);
GNUNET_OS_process_destroy (bankd);
}
} }
GNUNET_OS_process_wait (exchanged); GNUNET_OS_process_wait (exchanged);
GNUNET_OS_process_destroy (exchanged); GNUNET_OS_process_destroy (exchanged);
@ -757,19 +824,25 @@ parallel_benchmark (TALER_TESTING_Main main_cb,
if ( (MODE_CLIENT == mode) || (MODE_BOTH == mode) ) if ( (MODE_CLIENT == mode) || (MODE_BOTH == mode) )
{ {
/* stop fakebank */ /* stop fakebank */
GNUNET_assert (-1 != fakebank); if (-1 != fakebank)
if (0 != kill (fakebank,
SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"kill");
waitpid (fakebank,
&wstatus,
0);
if ( (! WIFEXITED (wstatus)) ||
(0 != WEXITSTATUS (wstatus)) )
{ {
GNUNET_break (0); kill (fakebank,
result = GNUNET_SYSERR; SIGTERM);
waitpid (fakebank,
&wstatus,
0);
if ( (! WIFEXITED (wstatus)) ||
(0 != WEXITSTATUS (wstatus)) )
{
GNUNET_break (0);
result = GNUNET_SYSERR;
}
}
if (NULL != bankd)
{
GNUNET_OS_process_kill (bankd,
SIGTERM);
GNUNET_OS_process_destroy (bankd);
} }
} }
return result; return result;
@ -787,7 +860,6 @@ int
main (int argc, main (int argc,
char *const *argv) char *const *argv)
{ {
char *cfg_filename = NULL;
struct GNUNET_GETOPT_CommandLineOption options[] = { struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_option_mandatory GNUNET_GETOPT_option_mandatory
(GNUNET_GETOPT_option_cfgfile (&cfg_filename)), (GNUNET_GETOPT_option_cfgfile (&cfg_filename)),
@ -824,6 +896,10 @@ main (int argc,
"LF", "LF",
"will log to file LF", "will log to file LF",
&logfile), &logfile),
GNUNET_GETOPT_option_flag ('f',
"fakebank",
"start a fakebank instead of the Python bank",
&use_fakebank),
GNUNET_GETOPT_option_flag ('K', GNUNET_GETOPT_option_flag ('K',
"linger", "linger",
"linger around until key press", "linger around until key press",
@ -949,10 +1025,13 @@ main (int argc,
} }
GNUNET_OS_process_wait (compute_wire_response); GNUNET_OS_process_wait (compute_wire_response);
GNUNET_OS_process_destroy (compute_wire_response); GNUNET_OS_process_destroy (compute_wire_response);
/* If we use the fakebank, we MUST reset the database as the fakebank
will have forgotten everything... */
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_TESTING_prepare_exchange (cfg_filename, TALER_TESTING_prepare_exchange (cfg_filename,
GNUNET_NO, (GNUNET_YES == use_fakebank)
? GNUNET_YES
: GNUNET_NO,
&ec)); &ec));
} }
else else

View File

@ -805,11 +805,13 @@ TALER_TESTING_run_fakebank (const char *bank_url,
* and reset database. * and reset database.
* *
* @param config_filename configuration file name. * @param config_filename configuration file name.
* @param reset_db should we reset the bank's database
* @param[out] bc set to the bank's configuration data * @param[out] bc set to the bank's configuration data
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
int int
TALER_TESTING_prepare_bank (const char *config_filename, TALER_TESTING_prepare_bank (const char *config_filename,
int reset_db,
const char *config_section, const char *config_section,
struct TALER_TESTING_BankConfiguration *bc); struct TALER_TESTING_BankConfiguration *bc);

View File

@ -171,6 +171,7 @@ main (int argc,
cfgfilename = CONFIG_FILE_PYBANK; cfgfilename = CONFIG_FILE_PYBANK;
if (GNUNET_OK != if (GNUNET_OK !=
TALER_TESTING_prepare_bank (CONFIG_FILE_PYBANK, TALER_TESTING_prepare_bank (CONFIG_FILE_PYBANK,
GNUNET_YES,
"exchange-account-2", "exchange-account-2",
&bc)) &bc))
{ {

View File

@ -177,6 +177,7 @@ main (int argc,
TALER_LOG_DEBUG ("Running against the Pybank.\n"); TALER_LOG_DEBUG ("Running against the Pybank.\n");
if (GNUNET_OK != if (GNUNET_OK !=
TALER_TESTING_prepare_bank (cfgfilename, TALER_TESTING_prepare_bank (cfgfilename,
GNUNET_YES,
"exchange-account-2", "exchange-account-2",
&bc)) &bc))
{ {

View File

@ -169,7 +169,7 @@ TALER_TESTING_run_bank (const char *config_filename,
GNUNET_free (serve_cfg); GNUNET_free (serve_cfg);
bank_proc = GNUNET_OS_start_process bank_proc = GNUNET_OS_start_process
(GNUNET_NO, (GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL, GNUNET_OS_INHERIT_STD_NONE,
NULL, NULL, NULL, NULL, NULL, NULL,
"taler-bank-manage-testing", "taler-bank-manage-testing",
"taler-bank-manage-testing", "taler-bank-manage-testing",
@ -222,6 +222,7 @@ TALER_TESTING_run_bank (const char *config_filename,
* and reset database. * and reset database.
* *
* @param config_filename configuration file name. * @param config_filename configuration file name.
* @param reset_db should we reset the bank's database
* @param config_section section of the configuration with the exchange's account * @param config_section section of the configuration with the exchange's account
* @param[out] bc set to the bank's configuration data * @param[out] bc set to the bank's configuration data
* @return the base url, or NULL upon errors. Must be freed * @return the base url, or NULL upon errors. Must be freed
@ -229,6 +230,7 @@ TALER_TESTING_run_bank (const char *config_filename,
*/ */
int int
TALER_TESTING_prepare_bank (const char *config_filename, TALER_TESTING_prepare_bank (const char *config_filename,
int reset_db,
const char *config_section, const char *config_section,
struct TALER_TESTING_BankConfiguration *bc) struct TALER_TESTING_BankConfiguration *bc)
{ {
@ -305,56 +307,59 @@ TALER_TESTING_prepare_bank (const char *config_filename,
} }
/* DB preparation */ /* DB preparation */
if (NULL == if (GNUNET_YES == reset_db)
(dbreset_proc = GNUNET_OS_start_process (
GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL,
NULL, NULL, NULL,
"taler-bank-manage",
"taler-bank-manage",
"-c", config_filename,
"--with-db", database,
"django",
"flush",
"--no-input", NULL)))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, if (NULL ==
"Failed to flush the bank db.\n"); (dbreset_proc = GNUNET_OS_start_process (
GNUNET_NO,
GNUNET_OS_INHERIT_STD_NONE,
NULL, NULL, NULL,
"taler-bank-manage",
"taler-bank-manage",
"-c", config_filename,
"--with-db", database,
"django",
"flush",
"--no-input", NULL)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to flush the bank db.\n");
GNUNET_free (database);
GNUNET_CONFIGURATION_destroy (cfg);
return GNUNET_SYSERR;
}
GNUNET_free (database); GNUNET_free (database);
GNUNET_CONFIGURATION_destroy (cfg);
return GNUNET_SYSERR;
}
GNUNET_free (database);
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
GNUNET_OS_process_wait_status (dbreset_proc, GNUNET_OS_process_wait_status (dbreset_proc,
&type, &type,
&code)) &code))
{ {
GNUNET_OS_process_destroy (dbreset_proc);
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
return GNUNET_SYSERR;
}
if ( (type == GNUNET_OS_PROCESS_EXITED) &&
(0 != code) )
{
fprintf (stderr,
"Failed to setup database\n");
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
return GNUNET_SYSERR;
}
if ( (type != GNUNET_OS_PROCESS_EXITED) ||
(0 != code) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected error running `taler-bank-manage django flush'!\n");
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
return GNUNET_SYSERR;
}
GNUNET_OS_process_destroy (dbreset_proc); GNUNET_OS_process_destroy (dbreset_proc);
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
return GNUNET_SYSERR;
} }
if ( (type == GNUNET_OS_PROCESS_EXITED) &&
(0 != code) )
{
fprintf (stderr,
"Failed to setup database\n");
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
return GNUNET_SYSERR;
}
if ( (type != GNUNET_OS_PROCESS_EXITED) ||
(0 != code) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected error running `taler-bank-manage django flush'!\n");
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
return GNUNET_SYSERR;
}
GNUNET_OS_process_destroy (dbreset_proc);
if (GNUNET_OK != if (GNUNET_OK !=
TALER_BANK_auth_parse_cfg (cfg, TALER_BANK_auth_parse_cfg (cfg,
config_section, config_section,