diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-11-07 22:01:22 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-11-07 22:01:22 +0100 |
commit | edfc078b18effea43865a093df69e5fcb1c3475d (patch) | |
tree | 337364b4716d51ddf4b0acbd2758aaf805ba66a4 /src/lib | |
parent | add872255341a80476cac82a43a41dfba8b05d10 (diff) |
fix /public/poll-payment implementation and tests
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/merchant_api_poll_payment.c | 22 | ||||
-rw-r--r-- | src/lib/test_merchant_api.c | 20 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_poll_payment.c | 16 |
3 files changed, 54 insertions, 4 deletions
diff --git a/src/lib/merchant_api_poll_payment.c b/src/lib/merchant_api_poll_payment.c index e89948e1..024595db 100644 --- a/src/lib/merchant_api_poll_payment.c +++ b/src/lib/merchant_api_poll_payment.c @@ -90,8 +90,22 @@ handle_poll_payment_finished (void *cls, cpo->job = NULL; - if (MHD_HTTP_OK != response_code) + switch (response_code) { + case MHD_HTTP_NOT_FOUND: + cpo->cb (cpo->cb_cls, + response_code, + json, + GNUNET_NO, + GNUNET_NO, + NULL, + NULL); + TALER_MERCHANT_poll_payment_cancel (cpo); + return; + case MHD_HTTP_OK: + /* see below */ + break; + default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Polling payment failed with HTTP status code %u\n", (unsigned int) response_code); @@ -107,6 +121,7 @@ handle_poll_payment_finished (void *cls, return; } + /* HTTP OK */ if (! json_boolean_value (json_object_get (json, "paid"))) { const char *taler_pay_uri = json_string_value (json_object_get (json, @@ -233,6 +248,11 @@ TALER_MERCHANT_poll_payment (struct GNUNET_CURL_Context *ctx, (0 != ts) ? "timeout" : NULL, timeout_s, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Long poll timeout is %s/%llu, url is %s\n", + timeout_s, + (unsigned long long) timeout.rel_value_us, + cpo->url); GNUNET_free (h_contract_s); GNUNET_free (timeout_s); eh = curl_easy_init (); diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c index 4517f48b..165a9d71 100644 --- a/src/lib/test_merchant_api.c +++ b/src/lib/test_merchant_api.c @@ -283,6 +283,18 @@ run (void *cls, MHD_HTTP_OK, "create-proposal-1", GNUNET_NO), + TALER_TESTING_cmd_poll_payment_start ("poll-payment-1", + merchant_url, + "create-proposal-1", + GNUNET_TIME_UNIT_MILLISECONDS), + TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-conclude-1", + MHD_HTTP_OK, + "poll-payment-1", + GNUNET_NO), + TALER_TESTING_cmd_poll_payment_start ("poll-payment-2", + merchant_url, + "create-proposal-1", + GNUNET_TIME_UNIT_MINUTES), TALER_TESTING_cmd_pay ("deposit-simple", merchant_url, MHD_HTTP_OK, @@ -291,6 +303,10 @@ run (void *cls, "EUR:5", "EUR:4.99", "EUR:0.01"), + TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-conclude-2", + MHD_HTTP_OK, + "poll-payment-2", + GNUNET_YES), TALER_TESTING_cmd_check_payment ("check-payment-2", merchant_url, MHD_HTTP_OK, @@ -1048,7 +1064,7 @@ main (int argc, unsetenv ("XDG_DATA_HOME"); unsetenv ("XDG_CONFIG_HOME"); - GNUNET_log_setup ("test-merchant-api-new", + GNUNET_log_setup ("test-merchant-api", "DEBUG", NULL); if (NULL == @@ -1098,4 +1114,4 @@ main (int argc, } -/* end of test_merchant_api_new.c */ +/* end of test_merchant_api.c */ diff --git a/src/lib/testing_api_cmd_poll_payment.c b/src/lib/testing_api_cmd_poll_payment.c index 14d71961..9cef2211 100644 --- a/src/lib/testing_api_cmd_poll_payment.c +++ b/src/lib/testing_api_cmd_poll_payment.c @@ -191,7 +191,9 @@ conclude_task (void *cls) } now = GNUNET_TIME_absolute_get (); if ( (GNUNET_NO == cps->paid) && - (cps->deadline.abs_value_us < now.abs_value_us) ) + (GNUNET_TIME_absolute_add (cps->deadline, + GNUNET_TIME_UNIT_SECONDS).abs_value_us < + now.abs_value_us) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected answer to be delayed until %llu, but got response at %llu\n", @@ -236,6 +238,17 @@ poll_payment_cb (void *cls, { struct PollPaymentStartState *cps = cls; + if (MHD_HTTP_OK != http_status) + { + char *log = json_dumps (obj, + JSON_COMPACT); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Poll payment returned %u: %s\n", + http_status, + log); + free (log); + } cps->cpo = NULL; cps->paid = paid; cps->http_status = http_status; @@ -380,6 +393,7 @@ poll_payment_conclude_run (void *cls, const struct TALER_TESTING_Command *poll_cmd; struct PollPaymentStartState *cps; + ppc->is = is; poll_cmd = TALER_TESTING_interpreter_lookup_command (is, ppc->start_reference); |