aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-04-03 16:07:04 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-04-03 16:07:04 +0200
commit35c064b93739795832598893b1885ff7cfd9faf8 (patch)
tree36dc79df5790f97ec56604f395e01e8ea5c73311
parent219f702926c61adedea9458e07a6936e76cfe13e (diff)
Faking the time.
Cherry-pick tests now uses the now-faked version of taler-exchange-keyup. Fails.
-rw-r--r--src/include/taler_testing_lib.h16
-rw-r--r--src/lib/test_exchange_api_keys_cherry_picking_new.c40
-rw-r--r--src/lib/testing_api_cmd_bank_check.c24
-rw-r--r--src/lib/testing_api_cmd_exec_keyup.c78
4 files changed, 126 insertions, 32 deletions
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index 711a13235..7c2f6f29a 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -920,6 +920,22 @@ TALER_TESTING_cmd_exec_keyup (const char *label,
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.
*
* @param label command label
diff --git a/src/lib/test_exchange_api_keys_cherry_picking_new.c b/src/lib/test_exchange_api_keys_cherry_picking_new.c
index 4702b29d0..9760d91ba 100644
--- a/src/lib/test_exchange_api_keys_cherry_picking_new.c
+++ b/src/lib/test_exchange_api_keys_cherry_picking_new.c
@@ -35,6 +35,7 @@
#include "taler_fakebank_lib.h"
#include "taler_testing_lib.h"
+
/**
* Configuration file we use. One (big) configuration is used
* for the various components for this test.
@@ -54,6 +55,23 @@
"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.
*/
static char *exchange_url;
@@ -140,20 +158,18 @@ run (void *cls,
is->exchanged,
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",
1, /* generation */
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",
- CONFIG_FILE_EXTENDED),
+ TALER_TESTING_cmd_exec_keyup_with_now ("keyup-2",
+ CONFIG_FILE_EXTENDED,
+ NOWPLUSSECS (10)),
+
TALER_TESTING_cmd_exec_auditor_sign ("sign-keys-1",
CONFIG_FILE_EXTENDED),
@@ -170,10 +186,10 @@ run (void *cls,
2, /* generation */
2),
- TALER_TESTING_cmd_sleep ("sleep",
- 20),
- TALER_TESTING_cmd_exec_keyup ("keyup-3",
- CONFIG_FILE_EXTENDED),
+ /* Must fake 20s lapse now. */
+ TALER_TESTING_cmd_exec_keyup_with_now ("keyup-3",
+ CONFIG_FILE_EXTENDED,
+ NOWPLUSSECS (20)),
TALER_TESTING_cmd_exec_auditor_sign ("sign-keys-2",
CONFIG_FILE),
TALER_TESTING_cmd_signal ("trigger-keys-reload-2",
diff --git a/src/lib/testing_api_cmd_bank_check.c b/src/lib/testing_api_cmd_bank_check.c
index 265cba176..67dbc0e19 100644
--- a/src/lib/testing_api_cmd_bank_check.c
+++ b/src/lib/testing_api_cmd_bank_check.c
@@ -335,12 +335,13 @@ check_bank_empty_traits (void *cls,
struct TALER_TESTING_Command
TALER_TESTING_cmd_check_bank_empty (const char *label)
{
- struct TALER_TESTING_Command cmd;
- cmd.label = label;
- cmd.run = &check_bank_empty_run;
- cmd.cleanup = &check_bank_empty_cleanup;
- cmd.traits = &check_bank_empty_traits;
+ struct TALER_TESTING_Command cmd = {
+ .label = label,
+ .run = &check_bank_empty_run,
+ .cleanup = &check_bank_empty_cleanup,
+ .traits = &check_bank_empty_traits
+ };
return cmd;
}
@@ -364,16 +365,17 @@ TALER_TESTING_cmd_check_bank_transfer_with_ref
{
struct BankCheckState *bcs;
- struct TALER_TESTING_Command cmd;
bcs = GNUNET_new (struct BankCheckState);
bcs->deposit_reference = deposit_reference;
- cmd.label = label;
- cmd.cls = bcs;
- cmd.run = &check_bank_transfer_run;
- cmd.cleanup = &check_bank_transfer_cleanup;
- cmd.traits = &check_bank_transfer_traits;
+ struct TALER_TESTING_Command cmd = {
+ .label = label,
+ .cls = bcs,
+ .run = &check_bank_transfer_run,
+ .cleanup = &check_bank_transfer_cleanup,
+ .traits = &check_bank_transfer_traits
+ };
return cmd;
}
diff --git a/src/lib/testing_api_cmd_exec_keyup.c b/src/lib/testing_api_cmd_exec_keyup.c
index 576aab3c7..d534db06e 100644
--- a/src/lib/testing_api_cmd_exec_keyup.c
+++ b/src/lib/testing_api_cmd_exec_keyup.c
@@ -46,6 +46,18 @@ struct KeyupState
* Configuration file used by the command.
*/
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,15 +75,30 @@ keyup_run (void *cls,
{
struct KeyupState *ks = cls;
- 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",
- NULL);
+ 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
+ (GNUNET_NO,
+ GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL, NULL,
+ "taler-exchange-keyup",
+ "taler-exchange-keyup",
+ "-c", ks->config_filename,
+ "-o", "auditor.in",
+ NULL);
if (NULL == ks->keyup_proc)
{
@@ -139,6 +166,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.
*
* @param label command label.