gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-exchange] 02/02: Faking the time.


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] 02/02: Faking the time.
Date: Wed, 03 Apr 2019 16:07:43 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository exchange.

commit 35c064b93739795832598893b1885ff7cfd9faf8
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Apr 3 16:07:04 2019 +0200

    Faking the time.
    
    Cherry-pick tests now uses the now-faked version
    of taler-exchange-keyup.  Fails.
---
 src/include/taler_testing_lib.h                    | 16 +++++
 .../test_exchange_api_keys_cherry_picking_new.c    | 40 +++++++----
 src/lib/testing_api_cmd_bank_check.c               | 24 ++++---
 src/lib/testing_api_cmd_exec_keyup.c               | 78 +++++++++++++++++++---
 4 files changed, 126 insertions(+), 32 deletions(-)

diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index 711a1323..7c2f6f29 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 4702b29d..9760d91b 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 265cba17..67dbc0e1 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 576aab3c..d534db06 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.

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]