Tests flexibility.

It is now possible to launch the bank from
the testing-lib regardless of it being served
via HTTP or UWSGI.
This commit is contained in:
Marcello Stanisci 2018-05-04 15:46:07 +02:00
parent 5fda47780a
commit 40b27a8210
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
6 changed files with 73 additions and 11 deletions

View File

@ -5,7 +5,9 @@ currency = KUDOS
URL = payto://x-taler-bank/localhost:8081/1 URL = payto://x-taler-bank/localhost:8081/1
[bank] [bank]
SERVE = http
HTTP_PORT = 8081 HTTP_PORT = 8081
DATABASE = postgres:///talercheck
[exchange-wire-test] [exchange-wire-test]
bank_url = http://localhost:8081/ bank_url = http://localhost:8081/

View File

@ -27,7 +27,9 @@ UNIX_MATCH_GID = YES
currency = KUDOS currency = KUDOS
[bank] [bank]
serve = http
http_port = 8081 http_port = 8081
database = postgres:///talercheck
[account-1] [account-1]
URL = payto://x-taler-bank/localhost:8081/1 URL = payto://x-taler-bank/localhost:8081/1

View File

@ -164,7 +164,7 @@ main(int argc,
return 77; return 77;
if (NULL == (bankd = if (NULL == (bankd =
TALER_TESTING_run_bank (CONFIG_FILE))) TALER_TESTING_run_bank (CONFIG_FILE, bank_url)))
return 77; return 77;
ret = TALER_TESTING_setup (&run, ret = TALER_TESTING_setup (&run,

View File

@ -85,7 +85,7 @@ run (void *cls,
struct TALER_TESTING_Command commands[] = { struct TALER_TESTING_Command commands[] = {
TALER_TESTING_cmd_bank_history ("history-0", TALER_TESTING_cmd_bank_history ("history-0",
bank_url, twister_url,
EXCHANGE_ACCOUNT_NUMBER, EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH, TALER_BANK_DIRECTION_BOTH,
NULL, NULL,
@ -124,10 +124,12 @@ main (int argc,
GNUNET_log_setup ("test-bank-api-twisted", GNUNET_log_setup ("test-bank-api-twisted",
"DEBUG", NULL); "DEBUG", NULL);
if (NULL == (bank_url = TALER_TESTING_prepare_bank (CONFIG_FILE))) if (NULL == (bank_url = TALER_TESTING_prepare_bank
(CONFIG_FILE)))
return 77; return 77;
if (NULL == (bankd = TALER_TESTING_run_bank (CONFIG_FILE))) if (NULL == (bankd = TALER_TESTING_run_bank
(CONFIG_FILE, bank_url)))
return 77; return 77;
if (NULL == (twister_url = TALER_TESTING_prepare_twister if (NULL == (twister_url = TALER_TESTING_prepare_twister

View File

@ -57,11 +57,63 @@ struct TALER_BANK_AuthenticationData AUTHS[] = {
* be started. * be started.
*/ */
struct GNUNET_OS_Process * struct GNUNET_OS_Process *
TALER_TESTING_run_bank (const char *config_filename) TALER_TESTING_run_bank (const char *config_filename,
const char *bank_url)
{ {
/* to fetch: dbname+serving_method+base_url */
struct GNUNET_OS_Process *bank_proc; struct GNUNET_OS_Process *bank_proc;
unsigned int iter; unsigned int iter;
char *wget_cmd;
char *database;
char *serve_cfg;
char *serve_arg;
struct GNUNET_CONFIGURATION_Handle *cfg;
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK !=
GNUNET_CONFIGURATION_load (cfg,
config_filename))
{
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
exit (77);
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"bank",
"database",
&database))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
"bank",
"database");
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
exit (77);
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"bank",
"serve",
&serve_cfg))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
"bank",
"serve");
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
exit (77);
}
serve_arg = "serve-http";
if (0 != strcmp ("http", serve_cfg))
serve_arg = "serve-uwsgi";
bank_proc = GNUNET_OS_start_process bank_proc = GNUNET_OS_start_process
(GNUNET_NO, (GNUNET_NO,
@ -70,11 +122,16 @@ TALER_TESTING_run_bank (const char *config_filename)
"taler-bank-manage", "taler-bank-manage",
"taler-bank-manage", "taler-bank-manage",
"-c", config_filename, "-c", config_filename,
"--with-db=postgres:///talercheck", "--with-db", database,
"serve-http", NULL); serve_arg, NULL);
if (NULL == bank_proc) if (NULL == bank_proc)
BANK_FAIL (); BANK_FAIL ();
GNUNET_asprintf (&wget_cmd,
"wget -q -t 1 -T 1 %s"
" -o /dev/null -O /dev/null",
bank_url);
/* give child time to start and bind against the socket */ /* give child time to start and bind against the socket */
fprintf (stderr, fprintf (stderr,
"Waiting for `taler-bank-manage' to be ready"); "Waiting for `taler-bank-manage' to be ready");
@ -96,9 +153,7 @@ TALER_TESTING_run_bank (const char *config_filename)
sleep (1); sleep (1);
iter++; iter++;
} }
/*FIXME: no hardcode port*/ while (0 != system (wget_cmd));
while (0 != system ("wget -q -t 1 -T 1 http://127.0.0.1:8081/" \
" -o /dev/null -O /dev/null"));
fprintf (stderr, "\n"); fprintf (stderr, "\n");
return bank_proc; return bank_proc;

View File

@ -62,7 +62,8 @@
* be started. * be started.
*/ */
struct GNUNET_OS_Process * struct GNUNET_OS_Process *
TALER_TESTING_run_bank (const char *config_filename); TALER_TESTING_run_bank (const char *config_filename,
const char *bank_url);
/** /**
* Prepare the bank execution. Check if the port is available * Prepare the bank execution. Check if the port is available