Fix history CMD loop, + make fakebank demonize.

This latter enable us to call the "check-service" CMD
against the Fakebank, instead of doing forced X seconds
sleep.
This commit is contained in:
Marcello Stanisci 2019-04-11 00:10:00 +02:00
parent 0d3758807b
commit 12aa516024
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
5 changed files with 57 additions and 34 deletions

View File

@ -980,7 +980,9 @@ TALER_FAKEBANK_start (uint16_t port)
h = GNUNET_new (struct TALER_FAKEBANK_Handle); h = GNUNET_new (struct TALER_FAKEBANK_Handle);
h->mhd_bank = MHD_start_daemon (MHD_USE_DEBUG h->mhd_bank = MHD_start_daemon (MHD_USE_DEBUG
#if EPOLL_SUPPORT #if EPOLL_SUPPORT
| MHD_USE_EPOLL | MHD_USE_EPOLL_INTERNAL_THREAD
#else
| MHD_USE_INTERNAL_POLLING_THREAD
#endif #endif
| MHD_USE_DUAL_STACK, | MHD_USE_DUAL_STACK,
port, port,

View File

@ -40,26 +40,27 @@
#define CONFIG_FILE "bank.conf" #define CONFIG_FILE "bank.conf"
/** /**
* Adds to the current time. * Add seconds.
* *
* @param relative number of _seconds_ to add to the current time. * @param base absolute time to add seconds to.
* @param relative number of seconds to add.
* @return a new absolute time, modified according to @e relative. * @return a new absolute time, modified according to @e relative.
*/ */
#define NOWPLUSSECS(secs) \ #define ADDSECS(base, secs) \
GNUNET_TIME_absolute_add \ GNUNET_TIME_absolute_add \
(now, \ (base, \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
secs)) secs))
/** /**
* Subtracts from the current time. * Subtract seconds.
* *
* @param relative number of _seconds_ to add to the current time. * @param base absolute time to subtract seconds to.
* @param secs relative number of _seconds_ to subtract.
* @return a new absolute time, modified according to @e relative. * @return a new absolute time, modified according to @e relative.
*/ */
#define NOWMINUSSECS(secs) \ #define SUBSECS(base, secs) \
GNUNET_TIME_absolute_subtract \ GNUNET_TIME_absolute_subtract \
(now, \ (base, \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
secs)) secs))
/** /**
@ -84,12 +85,8 @@ run (void *cls,
{ {
extern struct TALER_BANK_AuthenticationData AUTHS[]; extern struct TALER_BANK_AuthenticationData AUTHS[];
struct GNUNET_TIME_Absolute now; struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Bank serves at `%s'\n",
bank_url);
now = GNUNET_TIME_absolute_get ();
struct TALER_TESTING_Command commands[] = { struct TALER_TESTING_Command commands[] = {
TALER_TESTING_cmd_bank_history ("history-0", TALER_TESTING_cmd_bank_history ("history-0",
@ -106,9 +103,10 @@ run (void *cls,
EXCHANGE_ACCOUNT_NUMBER, EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH, TALER_BANK_DIRECTION_BOTH,
GNUNET_NO, GNUNET_NO,
NOWMINUSSECS (5), SUBSECS (now,
NOWPLUSSECS (5)), 5),
ADDSECS (now,
5)),
TALER_TESTING_cmd_fakebank_transfer_with_subject TALER_TESTING_cmd_fakebank_transfer_with_subject
("deposit-1", ("deposit-1",
"KUDOS:5.01", "KUDOS:5.01",
@ -173,8 +171,10 @@ run (void *cls,
EXCHANGE_ACCOUNT_NUMBER, EXCHANGE_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_BOTH, TALER_BANK_DIRECTION_BOTH,
GNUNET_NO, GNUNET_NO,
NOWMINUSSECS (5), SUBSECS (now,
NOWPLUSSECS (5)), 50),
ADDSECS (now,
5)),
TALER_TESTING_cmd_bank_reject ("reject-1", TALER_TESTING_cmd_bank_reject ("reject-1",
bank_url, bank_url,

View File

@ -82,8 +82,8 @@ run (void *cls,
* Can't use the "wait service" CMD here because the * Can't use the "wait service" CMD here because the
* fakebank runs inside the same process of the test. * fakebank runs inside the same process of the test.
*/ */
TALER_TESTING_cmd_sleep ("wait interface", TALER_TESTING_cmd_wait_service ("wait-service",
2), TWISTED_BANK_URL),
TALER_TESTING_cmd_bank_history ("history-0", TALER_TESTING_cmd_bank_history ("history-0",
TWISTED_BANK_URL, TWISTED_BANK_URL,

View File

@ -1,4 +1,4 @@
/* /*
This file is part of TALER This file is part of TALER
Copyright (C) 2018 Taler Systems SA Copyright (C) 2018 Taler Systems SA
@ -354,12 +354,13 @@ build_history (struct TALER_TESTING_Interpreter *is,
(add_incoming_cmd, 0, &row_id_start)); (add_incoming_cmd, 0, &row_id_start));
} }
GNUNET_assert ((0 != hs->num_results) || GNUNET_assert ((0 != hs->num_results) || /* "/history" */
(GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != /* "/history-range" */
hs->start_date.abs_value_us)); hs->start_date.abs_value_us));
if (0 == is->ip) if (0 == is->ip)
{ {
TALER_LOG_DEBUG ("Checking history at first CMD..\n");
*rh = NULL; *rh = NULL;
return 0; return 0;
} }
@ -416,14 +417,19 @@ build_history (struct TALER_TESTING_Interpreter *is,
} }
/* Seek "/history-range" starting row, _if_ that's the case */ /* Seek "/history-range" starting row, _if_ that's the case */
if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != if ((GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us !=
hs->start_date.abs_value_us) hs->start_date.abs_value_us) && (GNUNET_YES != ok))
{ {
const struct GNUNET_TIME_Absolute *timestamp; const struct GNUNET_TIME_Absolute *timestamp;
TALER_TESTING_get_trait_absolute_time (pos, TALER_TESTING_get_trait_absolute_time (pos,
0, 0,
&timestamp); &timestamp);
TALER_LOG_DEBUG
("Seeking first row, start vs timestamp: %llu vs %llu\n",
hs->start_date.abs_value_us,
timestamp->abs_value_us);
if (hs->start_date.abs_value_us <= timestamp->abs_value_us) if (hs->start_date.abs_value_us <= timestamp->abs_value_us)
{ {
total = 0; total = 0;
@ -436,10 +442,15 @@ build_history (struct TALER_TESTING_Interpreter *is,
if (GNUNET_NO == ok) if (GNUNET_NO == ok)
continue; /* skip until we find the marker */ continue; /* skip until we find the marker */
TALER_LOG_DEBUG ("Found first row\n");
if (build_history_hit_limit (total, if (build_history_hit_limit (total,
hs, hs,
pos)) pos))
{
TALER_LOG_DEBUG ("Hit history limit\n");
break; break;
}
cancelled = test_cancelled (is, off); cancelled = test_cancelled (is, off);
@ -478,11 +489,11 @@ build_history (struct TALER_TESTING_Interpreter *is,
} }
} }
GNUNET_assert (GNUNET_YES == ok); GNUNET_assert (GNUNET_YES == ok);
if (0 == total) if (0 == total)
{ {
TALER_LOG_DEBUG ("Checking history at first CMD.. (2)\n");
*rh = NULL; *rh = NULL;
return 0; return 0;
} }
@ -517,8 +528,10 @@ build_history (struct TALER_TESTING_Interpreter *is,
if (*row_id_start == *row_id) if (*row_id_start == *row_id)
{ {
/* Warning: this zeroing is superfluous, as total doesn't /**
* get incremented if 'start' was given and couldn't be found. * Warning: this zeroing is superfluous, as
* total doesn't get incremented if 'start'
* was given and couldn't be found.
*/ */
total = 0; total = 0;
ok = GNUNET_YES; ok = GNUNET_YES;
@ -527,14 +540,19 @@ build_history (struct TALER_TESTING_Interpreter *is,
} }
/* Seek "/history-range" starting row, _if_ that's the case */ /* Seek "/history-range" starting row, _if_ that's the case */
if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != if ((GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us !=
hs->start_date.abs_value_us) hs->start_date.abs_value_us) && (GNUNET_YES != ok))
{ {
const struct GNUNET_TIME_Absolute *timestamp; const struct GNUNET_TIME_Absolute *timestamp;
TALER_TESTING_get_trait_absolute_time (pos, TALER_TESTING_get_trait_absolute_time (pos,
0, 0,
&timestamp); &timestamp);
TALER_LOG_DEBUG
("Seeking first row, start vs timestamp (2): %llu vs %llu\n",
hs->start_date.abs_value_us,
timestamp->abs_value_us);
if (hs->start_date.abs_value_us <= timestamp->abs_value_us) if (hs->start_date.abs_value_us <= timestamp->abs_value_us)
{ {
total = 0; total = 0;
@ -543,6 +561,8 @@ build_history (struct TALER_TESTING_Interpreter *is,
} }
} }
TALER_LOG_INFO ("Found first row (2)\n");
if (GNUNET_NO == ok) if (GNUNET_NO == ok)
{ {
TALER_LOG_INFO ("Skip on `%s'\n", TALER_LOG_INFO ("Skip on `%s'\n",
@ -554,7 +574,7 @@ build_history (struct TALER_TESTING_Interpreter *is,
hs, hs,
pos)) pos))
{ {
TALER_LOG_INFO ("hit limit specified by command\n"); TALER_LOG_INFO ("Hit history limit (2)\n");
break; break;
} }
@ -1149,6 +1169,7 @@ TALER_TESTING_cmd_bank_history_range_with_dates
hs->account_no = account_no; hs->account_no = account_no;
hs->direction = direction; hs->direction = direction;
hs->ascending = ascending; hs->ascending = ascending;
hs->start_row_reference = NULL;
hs->start_date = start_date; hs->start_date = start_date;
hs->end_date = end_date; hs->end_date = end_date;

View File

@ -75,7 +75,7 @@
* @return a new absolute time, modified according to @e relative. * @return a new absolute time, modified according to @e relative.
*/ */
#define SUBSECS(base, secs) \ #define SUBSECS(base, secs) \
GNUNET_TIME_absolute_sub \ GNUNET_TIME_absolute_subtract \
(base, \ (base, \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
secs)) secs))