From d8f1f7b761a41fc027c53dcd85c2b07dd73c6d1b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 17 May 2022 11:21:20 +0200 Subject: integrate purse expiration into test, bugfixes --- src/testing/Makefile.am | 2 + src/testing/test_exchange_api-cs.conf | 8 ++ src/testing/test_exchange_api-rsa.conf | 9 ++ src/testing/test_exchange_p2p.c | 58 +++++++++++ src/testing/testing_api_cmd_exec_expire.c | 162 ++++++++++++++++++++++++++++++ src/testing/testing_api_cmd_exec_router.c | 161 +++++++++++++++++++++++++++++ src/testing/testing_api_cmd_purse_get.c | 1 + 7 files changed, 401 insertions(+) create mode 100644 src/testing/testing_api_cmd_exec_expire.c create mode 100644 src/testing/testing_api_cmd_exec_router.c (limited to 'src/testing') diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 4d3c6061a..42c4d8d6b 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -61,6 +61,8 @@ libtalertesting_la_SOURCES = \ testing_api_cmd_exec_aggregator.c \ testing_api_cmd_exec_auditor-offline.c \ testing_api_cmd_exec_closer.c \ + testing_api_cmd_exec_expire.c \ + testing_api_cmd_exec_router.c \ testing_api_cmd_exec_transfer.c \ testing_api_cmd_exec_wirewatch.c \ testing_api_cmd_insert_deposit.c \ diff --git a/src/testing/test_exchange_api-cs.conf b/src/testing/test_exchange_api-cs.conf index 79332d648..204718120 100644 --- a/src/testing/test_exchange_api-cs.conf +++ b/src/testing/test_exchange_api-cs.conf @@ -45,6 +45,14 @@ DB = postgres # exchange (or the twister) is actually listening. BASE_URL = "http://localhost:8081/" +# How big is an individual shard to be processed +# by taler-exchange-expire (in time). It may take +# this much time for an expired purse to be really +# cleaned up and the coins refunded. +EXPIRE_SHARD_SIZE = 300 ms + +EXPIRE_IDLE_SLEEP_INTERVAL = 1 s + [exchangedb-postgres] CONFIG = "postgres:///talercheck" diff --git a/src/testing/test_exchange_api-rsa.conf b/src/testing/test_exchange_api-rsa.conf index 1d4456623..be0e4bade 100644 --- a/src/testing/test_exchange_api-rsa.conf +++ b/src/testing/test_exchange_api-rsa.conf @@ -45,6 +45,15 @@ DB = postgres # exchange (or the twister) is actually listening. BASE_URL = "http://localhost:8081/" +# How big is an individual shard to be processed +# by taler-exchange-expire (in time). It may take +# this much time for an expired purse to be really +# cleaned up and the coins refunded. +EXPIRE_SHARD_SIZE = 300 ms + +EXPIRE_IDLE_SLEEP_INTERVAL = 1 s + + [exchangedb-postgres] CONFIG = "postgres:///talercheck" diff --git a/src/testing/test_exchange_p2p.c b/src/testing/test_exchange_p2p.c index b3e98daa4..ec3c660c4 100644 --- a/src/testing/test_exchange_p2p.c +++ b/src/testing/test_exchange_p2p.c @@ -277,6 +277,62 @@ run (void *cls, TALER_TESTING_cmd_end () }; + struct TALER_TESTING_Command expire[] = { + TALER_TESTING_cmd_purse_create_with_reserve ( + "purse-create-with-reserve-expire", + MHD_HTTP_OK, + "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}", + true /* upload contract */, + GNUNET_TIME_relative_multiply ( + GNUNET_TIME_UNIT_SECONDS, + 1), /* expiration */ + "create-reserve-1"), + TALER_TESTING_cmd_purse_poll ( + "pull-poll-purse-before-expire", + MHD_HTTP_GONE, + "purse-create-with-reserve-expire", + "EUR:1", + false, + GNUNET_TIME_UNIT_MINUTES), + TALER_TESTING_cmd_purse_create_with_deposit ( + "purse-with-deposit-expire", + MHD_HTTP_OK, + "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}", + true, /* upload contract */ + GNUNET_TIME_relative_multiply ( + GNUNET_TIME_UNIT_SECONDS, + 1), /* expiration */ + "withdraw-coin-1", + "EUR:1.01", + NULL), + TALER_TESTING_cmd_purse_poll ( + "push-poll-purse-before-expire", + MHD_HTTP_GONE, + "purse-with-deposit-expire", + "EUR:1", + true, + GNUNET_TIME_UNIT_MINUTES), + TALER_TESTING_cmd_sleep ("sleep", + 2 /* seconds */), + TALER_TESTING_cmd_exec_expire ("exec-expire", + config_file), + TALER_TESTING_cmd_purse_poll_finish ( + "push-merge-purse-poll-finish-expire", + GNUNET_TIME_relative_multiply ( + GNUNET_TIME_UNIT_SECONDS, + 15), + "push-poll-purse-before-expire"), + TALER_TESTING_cmd_purse_poll_finish ( + "pull-deposit-purse-poll-expire-finish", + GNUNET_TIME_relative_multiply ( + GNUNET_TIME_UNIT_SECONDS, + 15), + "pull-poll-purse-before-expire"), + // FIXME: check coin was refunded + // FIXME: check reserve purse capacity is back up! + TALER_TESTING_cmd_end () + }; + struct TALER_TESTING_Command commands[] = { /* setup exchange */ TALER_TESTING_cmd_auditor_add ("add-auditor-OK", @@ -313,6 +369,8 @@ run (void *cls, push), TALER_TESTING_cmd_batch ("pull", pull), + TALER_TESTING_cmd_batch ("expire", + expire), /* End the suite. */ TALER_TESTING_cmd_end () }; diff --git a/src/testing/testing_api_cmd_exec_expire.c b/src/testing/testing_api_cmd_exec_expire.c new file mode 100644 index 000000000..aabf37361 --- /dev/null +++ b/src/testing/testing_api_cmd_exec_expire.c @@ -0,0 +1,162 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3, + or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with TALER; see the file COPYING. If not, see + +*/ +/** + * @file testing/testing_api_cmd_exec_expire.c + * @brief run the taler-exchange-expire command + * @author Christian Grothoff + * @author Marcello Stanisci + */ +#include "platform.h" +#include "taler_json_lib.h" +#include +#include "taler_signatures.h" +#include "taler_testing_lib.h" + + +/** + * State for a "expire" CMD. + */ +struct ExpireState +{ + + /** + * Process for the expireer. + */ + struct GNUNET_OS_Process *expire_proc; + + /** + * Configuration file used by the expireer. + */ + const char *config_filename; +}; + + +/** + * Run the command; use the `taler-exchange-expire' program. + * + * @param cls closure. + * @param cmd command currently being executed. + * @param is interpreter state. + */ +static void +expire_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct ExpireState *ws = cls; + + (void) cmd; + ws->expire_proc + = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-exchange-expire", + "taler-exchange-expire", + "-L", "INFO", + "-c", ws->config_filename, + "-t", /* exit when done */ + NULL); + if (NULL == ws->expire_proc) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + TALER_TESTING_wait_for_sigchld (is); +} + + +/** + * Free the state of a "expire" CMD, and possibly + * kills its process if it did not terminate regularly. + * + * @param cls closure. + * @param cmd the command being freed. + */ +static void +expire_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + struct ExpireState *ws = cls; + + (void) cmd; + if (NULL != ws->expire_proc) + { + GNUNET_break (0 == + GNUNET_OS_process_kill (ws->expire_proc, + SIGKILL)); + GNUNET_OS_process_wait (ws->expire_proc); + GNUNET_OS_process_destroy (ws->expire_proc); + ws->expire_proc = NULL; + } + GNUNET_free (ws); +} + + +/** + * Offer "expire" CMD internal data to other commands. + * + * @param cls closure. + * @param[out] ret result. + * @param trait name of the trait. + * @param index index number of the object to offer. + * @return #GNUNET_OK on success. + */ +static enum GNUNET_GenericReturnValue +expire_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + struct ExpireState *ws = cls; + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_process (&ws->expire_proc), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); +} + + +struct TALER_TESTING_Command +TALER_TESTING_cmd_exec_expire (const char *label, + const char *config_filename) +{ + struct ExpireState *ws; + + ws = GNUNET_new (struct ExpireState); + ws->config_filename = config_filename; + + { + struct TALER_TESTING_Command cmd = { + .cls = ws, + .label = label, + .run = &expire_run, + .cleanup = &expire_cleanup, + .traits = &expire_traits + }; + + return cmd; + } +} + + +/* end of testing_api_cmd_exec_expire.c */ diff --git a/src/testing/testing_api_cmd_exec_router.c b/src/testing/testing_api_cmd_exec_router.c new file mode 100644 index 000000000..d7f3fe265 --- /dev/null +++ b/src/testing/testing_api_cmd_exec_router.c @@ -0,0 +1,161 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3, + or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with TALER; see the file COPYING. If not, see + +*/ +/** + * @file testing/testing_api_cmd_exec_router.c + * @brief run the taler-exchange-router command + * @author Christian Grothoff + * @author Marcello Stanisci + */ +#include "platform.h" +#include "taler_json_lib.h" +#include +#include "taler_signatures.h" +#include "taler_testing_lib.h" + + +/** + * State for a "router" CMD. + */ +struct RouterState +{ + + /** + * Process for the routerer. + */ + struct GNUNET_OS_Process *router_proc; + + /** + * Configuration file used by the routerer. + */ + const char *config_filename; +}; + + +/** + * Run the command; use the `taler-exchange-router' program. + * + * @param cls closure. + * @param cmd command currently being executed. + * @param is interpreter state. + */ +static void +router_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct RouterState *ws = cls; + + (void) cmd; + ws->router_proc + = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-exchange-router", + "taler-exchange-router", + "-c", ws->config_filename, + "-t", /* exit when done */ + NULL); + if (NULL == ws->router_proc) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + TALER_TESTING_wait_for_sigchld (is); +} + + +/** + * Free the state of a "router" CMD, and possibly + * kills its process if it did not terminate regularly. + * + * @param cls closure. + * @param cmd the command being freed. + */ +static void +router_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + struct RouterState *ws = cls; + + (void) cmd; + if (NULL != ws->router_proc) + { + GNUNET_break (0 == + GNUNET_OS_process_kill (ws->router_proc, + SIGKILL)); + GNUNET_OS_process_wait (ws->router_proc); + GNUNET_OS_process_destroy (ws->router_proc); + ws->router_proc = NULL; + } + GNUNET_free (ws); +} + + +/** + * Offer "router" CMD internal data to other commands. + * + * @param cls closure. + * @param[out] ret result. + * @param trait name of the trait. + * @param index index number of the object to offer. + * @return #GNUNET_OK on success. + */ +static enum GNUNET_GenericReturnValue +router_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + struct RouterState *ws = cls; + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_process (&ws->router_proc), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); +} + + +struct TALER_TESTING_Command +TALER_TESTING_cmd_exec_router (const char *label, + const char *config_filename) +{ + struct RouterState *ws; + + ws = GNUNET_new (struct RouterState); + ws->config_filename = config_filename; + + { + struct TALER_TESTING_Command cmd = { + .cls = ws, + .label = label, + .run = &router_run, + .cleanup = &router_cleanup, + .traits = &router_traits + }; + + return cmd; + } +} + + +/* end of testing_api_cmd_exec_router.c */ diff --git a/src/testing/testing_api_cmd_purse_get.c b/src/testing/testing_api_cmd_purse_get.c index 3fc576912..61873721b 100644 --- a/src/testing/testing_api_cmd_purse_get.c +++ b/src/testing/testing_api_cmd_purse_get.c @@ -261,6 +261,7 @@ TALER_TESTING_cmd_purse_poll ( ss->expected_balance = expected_balance; ss->expected_response_code = expected_http_status; ss->timeout = timeout; + ss->wait_for_merge = wait_for_merge; { struct TALER_TESTING_Command cmd = { .cls = ss, -- cgit v1.2.3