Fixing twisted tests.
It has been observed that when a "twisted" test has "very little" commands in the stack, it uses to fail since the proxied service cannot be reached. This commit puts some delay before the first command gets run by the test interpreter; both in the form of a "blind" sleep, and with a more structured 'wget' loop.
This commit is contained in:
parent
ca718b9f1f
commit
5c49663309
@ -587,6 +587,7 @@ handle_reject (struct TALER_FAKEBANK_Handle *h,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle incoming HTTP request for /history
|
* Handle incoming HTTP request for /history
|
||||||
*
|
*
|
||||||
@ -596,9 +597,40 @@ handle_reject (struct TALER_FAKEBANK_Handle *h,
|
|||||||
* @return MHD result code
|
* @return MHD result code
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
handle_history_new (struct TALER_FAKEBANK_Handle *h,
|
handle_home_page (struct TALER_FAKEBANK_Handle *h,
|
||||||
struct MHD_Connection *connection,
|
struct MHD_Connection *connection,
|
||||||
void **con_cls)
|
void **con_cls)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
struct MHD_Response *resp;
|
||||||
|
#define HELLOMSG "Hello, Fakebank!"
|
||||||
|
|
||||||
|
resp = MHD_create_response_from_buffer
|
||||||
|
(strlen (HELLOMSG),
|
||||||
|
HELLOMSG,
|
||||||
|
MHD_RESPMEM_MUST_COPY);
|
||||||
|
|
||||||
|
ret = MHD_queue_response (connection,
|
||||||
|
MHD_HTTP_OK,
|
||||||
|
resp);
|
||||||
|
|
||||||
|
MHD_destroy_response (resp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle incoming HTTP request for /history
|
||||||
|
*
|
||||||
|
* @param h the fakebank handle
|
||||||
|
* @param connection the connection
|
||||||
|
* @param con_cls place to store state, not used
|
||||||
|
* @return MHD result code
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
handle_history (struct TALER_FAKEBANK_Handle *h,
|
||||||
|
struct MHD_Connection *connection,
|
||||||
|
void **con_cls)
|
||||||
{
|
{
|
||||||
struct HistoryArgs ha;
|
struct HistoryArgs ha;
|
||||||
struct HistoryRangeIds hri;
|
struct HistoryRangeIds hri;
|
||||||
@ -763,6 +795,18 @@ handle_mhd_request (void *cls,
|
|||||||
{
|
{
|
||||||
struct TALER_FAKEBANK_Handle *h = cls;
|
struct TALER_FAKEBANK_Handle *h = cls;
|
||||||
|
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
|
"Fakebank, serving: %s\n",
|
||||||
|
url);
|
||||||
|
|
||||||
|
|
||||||
|
if ( (0 == strcasecmp (url,
|
||||||
|
"/")) &&
|
||||||
|
(0 == strcasecmp (method,
|
||||||
|
MHD_HTTP_METHOD_GET)) )
|
||||||
|
return handle_home_page (h,
|
||||||
|
connection,
|
||||||
|
con_cls);
|
||||||
if ( (0 == strcasecmp (url,
|
if ( (0 == strcasecmp (url,
|
||||||
"/admin/add/incoming")) &&
|
"/admin/add/incoming")) &&
|
||||||
(0 == strcasecmp (method,
|
(0 == strcasecmp (method,
|
||||||
@ -792,9 +836,9 @@ handle_mhd_request (void *cls,
|
|||||||
"/history")) &&
|
"/history")) &&
|
||||||
(0 == strcasecmp (method,
|
(0 == strcasecmp (method,
|
||||||
MHD_HTTP_METHOD_GET)) )
|
MHD_HTTP_METHOD_GET)) )
|
||||||
return handle_history_new (h,
|
return handle_history (h,
|
||||||
connection,
|
connection,
|
||||||
con_cls);
|
con_cls);
|
||||||
|
|
||||||
/* Unexpected URL path, just close the connection. */
|
/* Unexpected URL path, just close the connection. */
|
||||||
/* we're rather impolite here, but it's a testcase. */
|
/* we're rather impolite here, but it's a testcase. */
|
||||||
|
@ -82,6 +82,10 @@ run (void *cls,
|
|||||||
struct TALER_TESTING_Interpreter *is)
|
struct TALER_TESTING_Interpreter *is)
|
||||||
{
|
{
|
||||||
struct TALER_TESTING_Command commands[] = {
|
struct TALER_TESTING_Command commands[] = {
|
||||||
|
|
||||||
|
TALER_TESTING_cmd_wait_service ("wait-service",
|
||||||
|
"http://localhost:8888/"),
|
||||||
|
|
||||||
TALER_TESTING_cmd_bank_history ("history-0",
|
TALER_TESTING_cmd_bank_history ("history-0",
|
||||||
TWISTED_BANK_URL,
|
TWISTED_BANK_URL,
|
||||||
EXCHANGE_ACCOUNT_NUMBER,
|
EXCHANGE_ACCOUNT_NUMBER,
|
||||||
|
@ -75,18 +75,23 @@ static void
|
|||||||
run (void *cls,
|
run (void *cls,
|
||||||
struct TALER_TESTING_Interpreter *is)
|
struct TALER_TESTING_Interpreter *is)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct TALER_TESTING_Command commands[] = {
|
struct TALER_TESTING_Command commands[] = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can't use the "wait service" CMD here because the
|
||||||
|
* fakebank runs inside the same process of the test.
|
||||||
|
*/
|
||||||
|
TALER_TESTING_cmd_sleep ("wait interface",
|
||||||
|
2),
|
||||||
|
|
||||||
TALER_TESTING_cmd_bank_history ("history-0",
|
TALER_TESTING_cmd_bank_history ("history-0",
|
||||||
twister_url,
|
TWISTED_BANK_URL,
|
||||||
EXCHANGE_ACCOUNT_NUMBER,
|
EXCHANGE_ACCOUNT_NUMBER,
|
||||||
TALER_BANK_DIRECTION_BOTH,
|
TALER_BANK_DIRECTION_BOTH,
|
||||||
GNUNET_NO,
|
GNUNET_NO,
|
||||||
NULL,
|
NULL,
|
||||||
5),
|
5),
|
||||||
/**
|
|
||||||
* End the suite. Fixme: better to have a label for this
|
|
||||||
* too, as it shows a "(null)" token on logs.
|
|
||||||
*/
|
|
||||||
TALER_TESTING_cmd_end ()
|
TALER_TESTING_cmd_end ()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,8 +125,9 @@ main (int argc,
|
|||||||
unsetenv ("XDG_DATA_HOME");
|
unsetenv ("XDG_DATA_HOME");
|
||||||
unsetenv ("XDG_CONFIG_HOME");
|
unsetenv ("XDG_CONFIG_HOME");
|
||||||
|
|
||||||
GNUNET_log_setup ("test-bank-api-twisted",
|
GNUNET_log_setup ("test-bank-api-with-fakebank-twisted",
|
||||||
"DEBUG", NULL);
|
"DEBUG",
|
||||||
|
NULL);
|
||||||
|
|
||||||
if (NULL == (fakebank_url = TALER_TESTING_prepare_fakebank
|
if (NULL == (fakebank_url = TALER_TESTING_prepare_fakebank
|
||||||
(CONFIG_FILE,
|
(CONFIG_FILE,
|
||||||
|
@ -1441,6 +1441,19 @@ TALER_TESTING_cmd_sleep (const char *label,
|
|||||||
unsigned int duration_s);
|
unsigned int duration_s);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This CMD simply tries to connect via HTTP to the
|
||||||
|
* service addressed by @a url. It attemps 10 times
|
||||||
|
* before giving up and make the test fail.
|
||||||
|
*
|
||||||
|
* @param label label for the command.
|
||||||
|
* @param url complete URL to connect to.
|
||||||
|
*/
|
||||||
|
struct TALER_TESTING_Command
|
||||||
|
TALER_TESTING_cmd_wait_service (const char *label,
|
||||||
|
const char *url);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a "check keys" command. This type of command
|
* Make a "check keys" command. This type of command
|
||||||
* checks whether the number of denomination keys from
|
* checks whether the number of denomination keys from
|
||||||
|
@ -144,8 +144,6 @@ static void
|
|||||||
run (void *cls,
|
run (void *cls,
|
||||||
struct TALER_TESTING_Interpreter *is)
|
struct TALER_TESTING_Interpreter *is)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This batch aims to trigger the 409 Conflict
|
* This batch aims to trigger the 409 Conflict
|
||||||
* response from a refresh-reveal operation.
|
* response from a refresh-reveal operation.
|
||||||
|
@ -40,6 +40,25 @@ struct SleepState
|
|||||||
unsigned int duration;
|
unsigned int duration;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No traits to offer, just provide a stub to be called when
|
||||||
|
* some CMDs iterates through the list of all the commands.
|
||||||
|
*
|
||||||
|
* @param cls closure.
|
||||||
|
* @param ret[out] result.
|
||||||
|
* @param trait name of the trait.
|
||||||
|
* @param index index number of the trait to return.
|
||||||
|
*
|
||||||
|
* @return #GNUNET_OK on success.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
sleep_traits (void *cls,
|
||||||
|
const void **ret,
|
||||||
|
const char *trait,
|
||||||
|
unsigned int index)
|
||||||
|
{
|
||||||
|
return GNUNET_NO;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the command.
|
* Run the command.
|
||||||
@ -97,8 +116,106 @@ TALER_TESTING_cmd_sleep (const char *label,
|
|||||||
.cls = ss,
|
.cls = ss,
|
||||||
.label = label,
|
.label = label,
|
||||||
.run = &sleep_run,
|
.run = &sleep_run,
|
||||||
.cleanup = &sleep_cleanup
|
.cleanup = &sleep_cleanup,
|
||||||
|
.traits = &sleep_traits
|
||||||
};
|
};
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanup the state from a "wait service" CMD.
|
||||||
|
*
|
||||||
|
* @param cls closure.
|
||||||
|
* @param cmd the command which is being cleaned up.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
wait_service_cleanup (void *cls,
|
||||||
|
const struct TALER_TESTING_Command *cmd)
|
||||||
|
{
|
||||||
|
/* nothing to clean. */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No traits to offer, just provide a stub to be called when
|
||||||
|
* some CMDs iterates through the list of all the commands.
|
||||||
|
*
|
||||||
|
* @param cls closure.
|
||||||
|
* @param ret[out] result.
|
||||||
|
* @param trait name of the trait.
|
||||||
|
* @param index index number of the trait to return.
|
||||||
|
*
|
||||||
|
* @return #GNUNET_OK on success.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
wait_service_traits (void *cls,
|
||||||
|
const void **ret,
|
||||||
|
const char *trait,
|
||||||
|
unsigned int index)
|
||||||
|
{
|
||||||
|
return GNUNET_NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a "wait service" CMD.
|
||||||
|
*
|
||||||
|
* @param cls closure.
|
||||||
|
* @param cmd the command being run.
|
||||||
|
* @param is the interpreter state.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
wait_service_run (void *cls,
|
||||||
|
const struct TALER_TESTING_Command *cmd,
|
||||||
|
struct TALER_TESTING_Interpreter *is)
|
||||||
|
{
|
||||||
|
unsigned int iter = 0;
|
||||||
|
const char *url = cmd->cls;
|
||||||
|
char *wget_cmd;
|
||||||
|
|
||||||
|
GNUNET_asprintf (&wget_cmd,
|
||||||
|
"wget -q -t 1 -T 1 %s\n",
|
||||||
|
url);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
fprintf (stderr, ".");
|
||||||
|
|
||||||
|
if (10 == iter++)
|
||||||
|
{
|
||||||
|
TALER_LOG_ERROR ("Could not reach the proxied service\n");
|
||||||
|
TALER_TESTING_interpreter_fail (is);
|
||||||
|
GNUNET_free (wget_cmd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (0 != system (wget_cmd));
|
||||||
|
|
||||||
|
GNUNET_free (wget_cmd);
|
||||||
|
TALER_TESTING_interpreter_next (is);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This CMD simply tries to connect via HTTP to the
|
||||||
|
* service addressed by @a url. It attemps 10 times
|
||||||
|
* before giving up and make the test fail.
|
||||||
|
*
|
||||||
|
* @param label label for the command.
|
||||||
|
* @param url complete URL to connect to.
|
||||||
|
*/
|
||||||
|
struct TALER_TESTING_Command
|
||||||
|
TALER_TESTING_cmd_wait_service (const char *label,
|
||||||
|
const char *url)
|
||||||
|
{
|
||||||
|
struct TALER_TESTING_Command cmd = {
|
||||||
|
.label = label,
|
||||||
|
.run = wait_service_run,
|
||||||
|
.cleanup = wait_service_cleanup,
|
||||||
|
.traits = wait_service_traits,
|
||||||
|
.cls = (void *) url
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end of testing_api_cmd_sleep.c */
|
||||||
|
Loading…
Reference in New Issue
Block a user