Faking the time.

Cherry-pick tests now uses the now-faked version
of taler-exchange-keyup.  Fails.
This commit is contained in:
Marcello Stanisci 2019-04-03 16:07:04 +02:00
parent 219f702926
commit 35c064b937
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
4 changed files with 126 additions and 32 deletions

View File

@ -919,6 +919,22 @@ struct TALER_TESTING_Command
TALER_TESTING_cmd_exec_keyup (const char *label, TALER_TESTING_cmd_exec_keyup (const char *label,
const char *config_filename); const char *config_filename);
/**
* Make the "keyup" CMD, with "--timestamp" option.
*
* @param label command label.
* @param config_filename configuration filename.
* @param now Unix timestamp representing the fake "now".
*
* @return the command.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_exec_keyup_with_now
(const char *label,
const char *config_filename,
struct GNUNET_TIME_Absolute now);
/** /**
* Make a "auditor sign" CMD. * Make a "auditor sign" CMD.
* *

View File

@ -35,6 +35,7 @@
#include "taler_fakebank_lib.h" #include "taler_fakebank_lib.h"
#include "taler_testing_lib.h" #include "taler_testing_lib.h"
/** /**
* Configuration file we use. One (big) configuration is used * Configuration file we use. One (big) configuration is used
* for the various components for this test. * for the various components for this test.
@ -53,6 +54,23 @@
#define CONFIG_FILE_EXTENDED_2 \ #define CONFIG_FILE_EXTENDED_2 \
"test_exchange_api_keys_cherry_picking_extended_2.conf" "test_exchange_api_keys_cherry_picking_extended_2.conf"
/**
* Current time.
*/
struct GNUNET_TIME_Absolute now;
/**
* Adds to the current time. XXX, open question: shall we
* also _set_ the global current time after the faking?
*
* @param relative number of _seconds_ to add to the current time.
* @return a new absolute time, modified according to @e relative.
*/
#define NOWPLUSSECS(secs) \
GNUNET_TIME_absolute_add \
(now, \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
secs))
/** /**
* Exchange base URL; mainly purpose is to make the compiler happy. * Exchange base URL; mainly purpose is to make the compiler happy.
*/ */
@ -140,20 +158,18 @@ run (void *cls,
is->exchanged, is->exchanged,
SIGUSR1), SIGUSR1),
/** /**
* 1 DK with 80s spend duration. * 1 DK with 80s withdraw duration. Lookahead_sign is 60s.
*/ */
TALER_TESTING_cmd_check_keys ("check-keys-1", TALER_TESTING_cmd_check_keys ("check-keys-1",
1, /* generation */ 1, /* generation */
1), 1),
TALER_TESTING_cmd_sleep ("sleep",
10),
/** /**
* We set lookahead_sign to 90s. * We now set lookahead_sign to 90s, and fake 10s passed.
*/ */
TALER_TESTING_cmd_exec_keyup ("keyup-2", TALER_TESTING_cmd_exec_keyup_with_now ("keyup-2",
CONFIG_FILE_EXTENDED), CONFIG_FILE_EXTENDED,
NOWPLUSSECS (10)),
TALER_TESTING_cmd_exec_auditor_sign ("sign-keys-1", TALER_TESTING_cmd_exec_auditor_sign ("sign-keys-1",
CONFIG_FILE_EXTENDED), CONFIG_FILE_EXTENDED),
@ -170,10 +186,10 @@ run (void *cls,
2, /* generation */ 2, /* generation */
2), 2),
TALER_TESTING_cmd_sleep ("sleep", /* Must fake 20s lapse now. */
20), TALER_TESTING_cmd_exec_keyup_with_now ("keyup-3",
TALER_TESTING_cmd_exec_keyup ("keyup-3", CONFIG_FILE_EXTENDED,
CONFIG_FILE_EXTENDED), NOWPLUSSECS (20)),
TALER_TESTING_cmd_exec_auditor_sign ("sign-keys-2", TALER_TESTING_cmd_exec_auditor_sign ("sign-keys-2",
CONFIG_FILE), CONFIG_FILE),
TALER_TESTING_cmd_signal ("trigger-keys-reload-2", TALER_TESTING_cmd_signal ("trigger-keys-reload-2",

View File

@ -335,12 +335,13 @@ check_bank_empty_traits (void *cls,
struct TALER_TESTING_Command struct TALER_TESTING_Command
TALER_TESTING_cmd_check_bank_empty (const char *label) TALER_TESTING_cmd_check_bank_empty (const char *label)
{ {
struct TALER_TESTING_Command cmd;
cmd.label = label; struct TALER_TESTING_Command cmd = {
cmd.run = &check_bank_empty_run; .label = label,
cmd.cleanup = &check_bank_empty_cleanup; .run = &check_bank_empty_run,
cmd.traits = &check_bank_empty_traits; .cleanup = &check_bank_empty_cleanup,
.traits = &check_bank_empty_traits
};
return cmd; return cmd;
} }
@ -364,16 +365,17 @@ TALER_TESTING_cmd_check_bank_transfer_with_ref
{ {
struct BankCheckState *bcs; struct BankCheckState *bcs;
struct TALER_TESTING_Command cmd;
bcs = GNUNET_new (struct BankCheckState); bcs = GNUNET_new (struct BankCheckState);
bcs->deposit_reference = deposit_reference; bcs->deposit_reference = deposit_reference;
cmd.label = label; struct TALER_TESTING_Command cmd = {
cmd.cls = bcs; .label = label,
cmd.run = &check_bank_transfer_run; .cls = bcs,
cmd.cleanup = &check_bank_transfer_cleanup; .run = &check_bank_transfer_run,
cmd.traits = &check_bank_transfer_traits; .cleanup = &check_bank_transfer_cleanup,
.traits = &check_bank_transfer_traits
};
return cmd; return cmd;
} }

View File

@ -46,6 +46,18 @@ struct KeyupState
* Configuration file used by the command. * Configuration file used by the command.
*/ */
const char *config_filename; const char *config_filename;
/**
* If GNUNET_YES, then the fake @e now value will be
* passed to taler-exchange-keyup via the --timestamp
* option.
*/
unsigned int with_now;
/**
* User-provided fake now.
*/
struct GNUNET_TIME_Absolute now;
}; };
@ -63,6 +75,21 @@ keyup_run (void *cls,
{ {
struct KeyupState *ks = cls; struct KeyupState *ks = cls;
if (GNUNET_YES == ks->with_now)
{
ks->keyup_proc = GNUNET_OS_start_process
(GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL,
NULL, NULL, NULL,
"taler-exchange-keyup",
"taler-exchange-keyup",
"-c", ks->config_filename,
"-o", "auditor.in",
"--timestamp",
GNUNET_STRINGS_absolute_time_to_string (ks->now),
NULL);
}
else
ks->keyup_proc = GNUNET_OS_start_process ks->keyup_proc = GNUNET_OS_start_process
(GNUNET_NO, (GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL, GNUNET_OS_INHERIT_STD_ALL,
@ -138,6 +165,39 @@ keyup_traits (void *cls,
} }
/**
* Make the "keyup" CMD, with "--timestamp" option.
*
* @param label command label.
* @param config_filename configuration filename.
* @param now Unix timestamp representing the fake "now".
*
* @return the command.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_exec_keyup_with_now
(const char *label,
const char *config_filename,
struct GNUNET_TIME_Absolute now)
{
struct KeyupState *ks;
ks = GNUNET_new (struct KeyupState);
ks->config_filename = config_filename;
ks->now = now;
ks->with_now = GNUNET_YES;
struct TALER_TESTING_Command cmd = {
.cls = ks,
.label = label,
.run = &keyup_run,
.cleanup = &keyup_cleanup,
.traits = &keyup_traits
};
return cmd;
}
/** /**
* Make the "keyup" CMD. * Make the "keyup" CMD.
* *