From a96c7177aae60c37041406ff0879992e58ef2f50 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 6 Apr 2016 12:04:51 +0200 Subject: get simple aggregation test to pass --- src/exchange/taler-exchange-aggregator.c | 42 +++++++++++++++++++++++---- src/exchange/test_taler_exchange_aggregator.c | 22 +++++++------- src/wire/plugin_wire_test.c | 2 +- 3 files changed, 50 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c index 3726d32fa..def6d0be4 100644 --- a/src/exchange/taler-exchange-aggregator.c +++ b/src/exchange/taler-exchange-aggregator.c @@ -237,8 +237,9 @@ shutdown_task (void *cls, json_decref (au->wire); au = NULL; GNUNET_free (au); - } + TALER_EXCHANGEDB_plugin_unload (db_plugin); + TALER_WIRE_plugin_unload (wire_plugin); } @@ -366,6 +367,9 @@ deposit_cb (void *cls, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &au->wtid, sizeof (au->wtid)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Starting aggregation under WTID %s\n", + TALER_B2S (&au->wtid)); if (GNUNET_OK != db_plugin->insert_aggregation_tracking (db_plugin->cls, au->session, @@ -523,8 +527,11 @@ run_aggregation (void *cls, unsigned int i; int ret; + task = NULL; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Checking for ready deposits to aggregate\n"); if (NULL == (session = db_plugin->get_session (db_plugin->cls, test_mode))) { @@ -563,6 +570,8 @@ run_aggregation (void *cls, global_ret = GNUNET_SYSERR; return; } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "No more ready deposits, going to sleep\n"); if (GNUNET_YES == test_mode) { /* in test mode, shutdown if we end up being idle */ @@ -578,6 +587,9 @@ run_aggregation (void *cls, return; } /* Now try to find other deposits to aggregate */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Found ready deposit for %s, aggregating\n", + TALER_B2S (&au->merchant_pub)); ret = db_plugin->iterate_matching_deposits (db_plugin->cls, session, &au->h_wire, @@ -608,6 +620,8 @@ run_aggregation (void *cls, if ( (0 == au->total_amount.value) && (0 == au->total_amount.fraction) ) { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Aggregate value too low for transfer\n"); /* Rollback ongoing transaction, as we will not use the respective WTID and thus need to remove the tracking data */ db_plugin->rollback (db_plugin->cls, @@ -660,6 +674,15 @@ run_aggregation (void *cls, NULL); return; } + { + char *amount_s; + + amount_s = TALER_amount_to_string (&au->total_amount); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Preparing wire transfer of %s to %s\n", + amount_s, + TALER_B2S (&au->merchant_pub)); + } au->ph = wire_plugin->prepare_wire_transfer (wire_plugin->cls, au->wire, &au->total_amount, @@ -757,7 +780,8 @@ prepare_cb (void *cls, NULL); return; } - + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Preparation complete, switching to transfer mode\n"); /* run alternative task: actually do wire transfer! */ task = GNUNET_SCHEDULER_add_now (&run_transfers, NULL); @@ -817,6 +841,8 @@ wire_confirm_cb (void *cls, NULL); return; } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Wire transfer complete\n"); /* continue with #run_transfers(), just to guard against the unlikely case that there are more. */ task = GNUNET_SCHEDULER_add_now (&run_transfers, @@ -840,6 +866,9 @@ wire_prepare_cb (void *cls, size_t buf_size) { wpd->row_id = rowid; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Starting wire transfer %llu\n", + rowid); wpd->eh = wire_plugin->execute_wire_transfer (wire_plugin->cls, buf, buf_size, @@ -872,6 +901,9 @@ run_transfers (void *cls, int ret; struct TALER_EXCHANGEDB_Session *session; + task = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Checking for pending wire transfers\n"); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; if (NULL == (session = db_plugin->get_session (db_plugin->cls, @@ -911,6 +943,8 @@ run_transfers (void *cls, if (GNUNET_NO == ret) { /* no more prepared wire transfers, go back to aggregation! */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "No more pending wire transfers, starting aggregation\n"); db_plugin->rollback (db_plugin->cls, session); task = GNUNET_SCHEDULER_add_now (&run_aggregation, @@ -934,7 +968,7 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { task = GNUNET_SCHEDULER_add_now (&run_transfers, - cls); + NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, cls); @@ -991,8 +1025,6 @@ main (int argc, global_ret = GNUNET_OK; GNUNET_SCHEDULER_run (&run, NULL); - TALER_EXCHANGEDB_plugin_unload (db_plugin); - TALER_WIRE_plugin_unload (wire_plugin); return (GNUNET_SYSERR == global_ret) ? 1 : 0; } diff --git a/src/exchange/test_taler_exchange_aggregator.c b/src/exchange/test_taler_exchange_aggregator.c index 22bc8e277..f34dea837 100644 --- a/src/exchange/test_taler_exchange_aggregator.c +++ b/src/exchange/test_taler_exchange_aggregator.c @@ -668,25 +668,19 @@ run_test () .label = "run-aggregator-deposit-1" }, - /* The above step is already known to fail (with an error message) - right now, so we skip the rest of the test. */ - { - .opcode = OPCODE_TERMINATE_SKIP, - .label = "testcase-incomplete-terminating-with-skip" - }, - - { .opcode = OPCODE_EXPECT_TRANSACTION, .label = "expect-deposit-1", - .details.expect_transaction.debit_account = 1, + .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, .details.expect_transaction.amount = "EUR:1" }, + { .opcode = OPCODE_EXPECT_TRANSACTIONS_EMPTY, .label = "expect-empty-transactions-on-start" }, + /* test idempotency: run again on transactions already done */ { .opcode = OPCODE_DATABASE_DEPOSIT, @@ -703,6 +697,11 @@ run_test () .label = "expect-empty-transactions-on-start" }, + { + .opcode = OPCODE_TERMINATE_SUCCESS, + .label = "testcase-incomplete-terminating-with-skip" + }, + { .opcode = OPCODE_TERMINATE_SKIP, .label = "testcase-incomplete-terminating-with-skip" @@ -804,7 +803,6 @@ handle_mhd_request (void *cls, GNUNET_break_op (0); return MHD_NO; } - /* FIXME: to be implemented! */ pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX, con_cls, upload_data, @@ -848,6 +846,10 @@ handle_mhd_request (void *cls, transactions_tail, t); } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Receiving incoming wire transfer: %llu->%llu\n", + (unsigned long long) t->debit_account, + (unsigned long long) t->credit_account); json_decref (json); resp = MHD_create_response_from_buffer (0, "", MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response (connection, diff --git a/src/wire/plugin_wire_test.c b/src/wire/plugin_wire_test.c index 357449af6..9d0667680 100644 --- a/src/wire/plugin_wire_test.c +++ b/src/wire/plugin_wire_test.c @@ -178,7 +178,7 @@ context_task (void *cls, rs, ws, &context_task, - cls); + tc); GNUNET_NETWORK_fdset_destroy (rs); GNUNET_NETWORK_fdset_destroy (ws); } -- cgit v1.2.3