summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_tip_authorize.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-01-29 18:12:30 +0100
committerChristian Grothoff <christian@grothoff.org>2021-01-29 18:12:30 +0100
commit10a3b45df075ec974f787783db9afeff09a54c88 (patch)
tree8cb6cf0acf274a3c594980b5331242b537f5c99f /src/testing/testing_api_cmd_tip_authorize.c
parent38b8097d94f794287c0dea3fbbe1f80cac46a69f (diff)
downloadmerchant-10a3b45df075ec974f787783db9afeff09a54c88.tar.gz
merchant-10a3b45df075ec974f787783db9afeff09a54c88.tar.bz2
merchant-10a3b45df075ec974f787783db9afeff09a54c88.zip
retry if reserve is so far unknown (404) to merchant, instead of using short timeout that may be too short on some systems
Diffstat (limited to 'src/testing/testing_api_cmd_tip_authorize.c')
-rw-r--r--src/testing/testing_api_cmd_tip_authorize.c80
1 files changed, 68 insertions, 12 deletions
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,10 +92,35 @@ 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
* tip_expiration).
@@ -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;