gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated (719854d4 -> 10a3b45d)


From: gnunet
Subject: [taler-merchant] branch master updated (719854d4 -> 10a3b45d)
Date: Fri, 29 Jan 2021 18:12:37 +0100

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

grothoff pushed a change to branch master
in repository merchant.

    from 719854d4 do not fail during postinst if systemctl is unavailable
     new 38b8097d allow permutations in order of reserves returned to still 
count as acceptable
     new 10a3b45d retry if reserve is so far unknown (404) to merchant, instead 
of using short timeout that may be too short on some systems

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backend/taler-merchant-httpd_reserves.c |   6 ++
 src/backenddb/plugin_merchantdb_postgres.c  |   5 +-
 src/testing/test_merchant_api.c             |   8 --
 src/testing/testing_api_cmd_get_reserves.c  | 111 +++++++++++++++++-----------
 src/testing/testing_api_cmd_tip_authorize.c |  80 +++++++++++++++++---
 5 files changed, 142 insertions(+), 68 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_reserves.c 
b/src/backend/taler-merchant-httpd_reserves.c
index b05a22aa..2853675f 100644
--- a/src/backend/taler-merchant-httpd_reserves.c
+++ b/src/backend/taler-merchant-httpd_reserves.c
@@ -210,6 +210,12 @@ reserve_cb (void *cls,
                 "Failed to commit reserve activation to database (%d)\n",
                 (int) qs);
   }
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Reserve activated with initial balance %s\n",
+                TALER_amount2s (balance));
+  }
   free_reserve (r);
 }
 
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index c9854942..babc47ca 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -5256,15 +5256,14 @@ RETRY:
   {
     struct TALER_Amount remaining;
 
-    if (0 >=
+    if (0 >
         TALER_amount_subtract (&remaining,
                                &exchange_initial_balance,
                                &tips_committed))
     {
       GNUNET_break (0);
       postgres_rollback (pg);
-      return
-        TALER_EC_GENERIC_DB_INVARIANT_FAILURE;
+      return TALER_EC_GENERIC_DB_INVARIANT_FAILURE;
     }
     if (0 >
         TALER_amount_cmp (&remaining,
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 93ebab34..57241524 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -855,10 +855,6 @@ run (void *cls,
                                                    payer_payto,
                                                    "create-reserve-tip-1"),
     cmd_exec_wirewatch ("wirewatch-3"),
-    /* Sleep so the merchant discovers that the reserve exists at the exchange
-       before trying to authorize a tip. */
-    TALER_TESTING_cmd_sleep ("wait-reserve-1",
-                             1),
     TALER_TESTING_cmd_tip_authorize ("authorize-tip-1",
                                      merchant_url,
                                      EXCHANGE_URL,
@@ -981,8 +977,6 @@ run (void *cls,
                                                    payer_payto,
                                                    "create-reserve-tip-2"),
     cmd_exec_wirewatch ("wirewatch-4"),
-    TALER_TESTING_cmd_sleep ("wait-reserve-2",
-                             1),
     TALER_TESTING_cmd_tip_authorize_from_reserve_with_ec (
       "authorize-tip-insufficient-funds",
       merchant_url,
@@ -1000,14 +994,12 @@ run (void *cls,
                                           "fake-tip-authorization",
                                           pickup_amounts_1,
                                           
TALER_EC_MERCHANT_GENERIC_TIP_ID_UNKNOWN),
-
     TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-2",
                                              merchant_url,
                                              MHD_HTTP_OK,
                                              "create-reserve-tip-1",
                                              "create-reserve-tip-2",
                                              NULL),
-
     TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-tip-1",
                                                merchant_url,
                                                "create-reserve-tip-1",
diff --git a/src/testing/testing_api_cmd_get_reserves.c 
b/src/testing/testing_api_cmd_get_reserves.c
index 22e0e1cd..f673d70b 100644
--- a/src/testing/testing_api_cmd_get_reserves.c
+++ b/src/testing/testing_api_cmd_get_reserves.c
@@ -74,6 +74,8 @@ get_reserves_cb (void *cls,
 {
   /* FIXME, deeper checks should be implemented here. */
   struct GetReservesState *grs = cls;
+  bool matched[reserves_length];
+  bool fail = false;
 
   grs->rgh = NULL;
   if (grs->http_status != hr->http_status)
@@ -97,60 +99,79 @@ get_reserves_cb (void *cls,
       return;
     }
     // FIXME: check if the data returned matches that from the POST / PATCH
+    memset (matched, 0, sizeof (matched));
     for (unsigned int i = 0; i < reserves_length; ++i)
-    {
-      const struct TALER_TESTING_Command *reserve_cmd;
-
-      reserve_cmd = TALER_TESTING_interpreter_lookup_command (
-        grs->is,
-        grs->reserves[i]);
+      for (unsigned int j = 0; j < reserves_length; ++j)
       {
-        const struct TALER_ReservePublicKeyP *reserve_pub;
+        const struct TALER_TESTING_Command *reserve_cmd;
+        bool match = true;
 
-        if (GNUNET_OK !=
-            TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
-                                                 0,
-                                                 &reserve_pub))
-        {
-          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      "Could not fetch reserve public key\n");
-          TALER_TESTING_interpreter_fail (grs->is);
-          return;
-        }
-        if (0 != GNUNET_memcmp (&reserves[i].reserve_pub,
-                                reserve_pub))
+        reserve_cmd = TALER_TESTING_interpreter_lookup_command (
+          grs->is,
+          grs->reserves[j]);
         {
-          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      "Reserve public key does not match\n");
-          TALER_TESTING_interpreter_fail (grs->is);
-          return;
-        }
-      }
-      {
-        const struct TALER_Amount *initial;
+          const struct TALER_ReservePublicKeyP *reserve_pub;
 
-        if (GNUNET_OK !=
-            TALER_TESTING_get_trait_amount_obj (reserve_cmd,
-                                                0,
-                                                &initial))
-        {
-          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      "Could not fetch reserve initial balance\n");
-          TALER_TESTING_interpreter_fail (grs->is);
-          return;
+          if (GNUNET_OK !=
+              TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
+                                                   0,
+                                                   &reserve_pub))
+          {
+            GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                        "Could not fetch reserve public key\n");
+            TALER_TESTING_interpreter_fail (grs->is);
+            return;
+          }
+          if (0 != GNUNET_memcmp (&reserves[i].reserve_pub,
+                                  reserve_pub))
+          {
+            GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                        "Reserve public key does not match, got %s\n",
+                        TALER_B2S (&reserves[i].reserve_pub));
+            GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                        "Reserve public key does not match, expected %s\n",
+                        TALER_B2S (reserve_pub));
+            match = false;
+          }
         }
-        if ((GNUNET_OK != TALER_amount_cmp_currency (
-               &reserves[i].merchant_initial_amount,
-               initial)) ||
-            (0 != TALER_amount_cmp (&reserves[i].merchant_initial_amount,
-                                    initial)))
         {
-          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      "Reserve initial amount does not match\n");
-          TALER_TESTING_interpreter_fail (grs->is);
-          return;
+          const struct TALER_Amount *initial;
+
+          if (GNUNET_OK !=
+              TALER_TESTING_get_trait_amount_obj (reserve_cmd,
+                                                  0,
+                                                  &initial))
+          {
+            GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                        "Could not fetch reserve initial balance\n");
+            TALER_TESTING_interpreter_fail (grs->is);
+            return;
+          }
+          if ((GNUNET_OK !=
+               TALER_amount_cmp_currency (&reserves[i].merchant_initial_amount,
+                                          initial)) ||
+              (0 != TALER_amount_cmp (&reserves[i].merchant_initial_amount,
+                                      initial)))
+          {
+            GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                        "Reserve initial amount does not match, got %s\n",
+                        TALER_amount2s (&reserves[i].merchant_initial_amount));
+            GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                        "Reserve initial amount does not match, wanted %s\n",
+                        TALER_amount2s (initial));
+            match = false;
+          }
         }
+        if (match)
+          matched[i] = true;
       }
+    for (unsigned int i = 0; i < reserves_length; ++i)
+      if (! matched[i])
+        fail = true;
+    if (fail)
+    {
+      TALER_TESTING_interpreter_fail (grs->is);
+      return;
     }
     break;
   default:
diff --git a/src/testing/testing_api_cmd_tip_authorize.c 
b/src/testing/testing_api_cmd_tip_authorize.c
index 4f4d5b66..62868ecd 100644
--- a/src/testing/testing_api_cmd_tip_authorize.c
+++ b/src/testing/testing_api_cmd_tip_authorize.c
@@ -92,9 +92,34 @@ struct TipAuthorizeState
    * The interpreter state.
    */
   struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * Task used for retries.
+   */
+  struct GNUNET_SCHEDULER_Task *retry_task;
+
+  /**
+   * How long do we wait between retries?
+   */
+  struct GNUNET_TIME_Relative backoff;
+
+  /**
+   * How many retries are left?
+   */
+  unsigned int retries_left;
+
 };
 
 
+/**
+ * Run the main logic of talking to the merchant.
+ *
+ * @param cls a `struct TipAuthorizeState`.
+ */
+static void
+do_retry (void *cls);
+
+
 /**
  * Callback for a /tip-authorize request.  Set into the state
  * what was returned from the backend (@a tip_id and @a
@@ -118,6 +143,21 @@ tip_authorize_cb (void *cls,
   tas->tao = NULL;
   if (tas->http_status != hr->http_status)
   {
+    if ( (MHD_HTTP_NOT_FOUND == hr->http_status) &&
+         (0 < tas->retries_left) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Reserve authorization failed. Reserve may not yet be ready, 
retrying %u more times.\n",
+                  tas->retries_left);
+      tas->retries_left--;
+      tas->backoff = GNUNET_TIME_randomized_backoff (tas->backoff,
+                                                     GNUNET_TIME_UNIT_SECONDS);
+      tas->retry_task = GNUNET_SCHEDULER_add_delayed (tas->backoff,
+                                                      &do_retry,
+                                                      tas);
+      return;
+    }
+
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Unexpected response code %u (%d) to command %s\n",
                 hr->http_status,
@@ -197,10 +237,22 @@ tip_authorize_run (void *cls,
 {
   struct TipAuthorizeState *tas = cls;
 
+  tas->retries_left = 16;
   tas->is = is;
+  tas->retry_task = GNUNET_SCHEDULER_add_now (&do_retry,
+                                              tas);
+}
+
+
+static void
+do_retry (void *cls)
+{
+  struct TipAuthorizeState *tas = cls;
+
+  tas->retry_task = NULL;
   if (NULL == tas->reserve_reference)
   {
-    tas->tao = TALER_MERCHANT_tip_authorize (is->ctx,
+    tas->tao = TALER_MERCHANT_tip_authorize (tas->is->ctx,
                                              tas->merchant_url,
                                              "http://merchant.com/pickup";,
                                              &tas->amount,
@@ -220,7 +272,7 @@ tip_authorize_run (void *cls,
                    TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
                                                         0,
                                                         &reserve_pub));
-    tas->tao = TALER_MERCHANT_tip_authorize2 (is->ctx,
+    tas->tao = TALER_MERCHANT_tip_authorize2 (tas->is->ctx,
                                               tas->merchant_url,
                                               reserve_pub,
                                               "http://merchant.com/pickup";,
@@ -229,7 +281,6 @@ tip_authorize_run (void *cls,
                                               &tip_authorize_cb,
                                               tas);
   }
-
   GNUNET_assert (NULL != tas->tao);
 }
 
@@ -276,6 +327,11 @@ tip_authorize_cleanup (void *cls,
                        " did not complete\n");
     TALER_MERCHANT_tip_authorize_cancel (tas->tao);
   }
+  if (NULL != tas->retry_task)
+  {
+    GNUNET_SCHEDULER_cancel (tas->retry_task);
+    tas->retry_task = NULL;
+  }
   GNUNET_free (tas);
 }
 
@@ -314,15 +370,15 @@ TALER_TESTING_cmd_tip_authorize_with_ec (const char 
*label,
 
 
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_tip_authorize_from_reserve_with_ec (const char *label,
-                                                      const char *merchant_url,
-                                                      const char *exchange_url,
-                                                      const char *
-                                                      reserve_reference,
-                                                      unsigned int http_status,
-                                                      const char 
*justification,
-                                                      const char *amount,
-                                                      enum TALER_ErrorCode ec)
+TALER_TESTING_cmd_tip_authorize_from_reserve_with_ec (
+  const char *label,
+  const char *merchant_url,
+  const char *exchange_url,
+  const char *reserve_reference,
+  unsigned int http_status,
+  const char *justification,
+  const char *amount,
+  enum TALER_ErrorCode ec)
 {
   struct TipAuthorizeState *tas;
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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