testing_api_cmd_wait.c (3238B)
1 /* 2 This file is part of TALER 3 (C) 2018 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 3, or 8 (at your option) any later version. 9 10 TALER is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public 16 License along with TALER; see the file COPYING. If not, see 17 <http://www.gnu.org/licenses/> 18 */ 19 /** 20 * @file testing/testing_api_cmd_wait.c 21 * @brief command(s) to wait on some process 22 * @author Christian Grothoff 23 */ 24 #include "taler/taler_json_lib.h" 25 #include <gnunet/gnunet_curl_lib.h> 26 #include "taler/taler_testing_lib.h" 27 28 29 /** 30 * Cleanup the state from a "wait service" CMD. 31 * 32 * @param cls closure. 33 * @param cmd the command which is being cleaned up. 34 */ 35 static void 36 wait_service_cleanup (void *cls, 37 const struct TALER_TESTING_Command *cmd) 38 { 39 (void) cls; 40 (void) cmd; 41 /* nothing to clean. */ 42 return; 43 } 44 45 46 /** 47 * No traits to offer, just provide a stub to be called when 48 * some CMDs iterates through the list of all the commands. 49 * 50 * @param cls closure. 51 * @param[out] ret result. 52 * @param trait name of the trait. 53 * @param index index number of the trait to return. 54 * @return #GNUNET_OK on success. 55 */ 56 static int 57 wait_service_traits (void *cls, 58 const void **ret, 59 const char *trait, 60 unsigned int index) 61 { 62 (void) cls; 63 (void) ret; 64 (void) trait; 65 (void) index; 66 return GNUNET_NO; 67 } 68 69 70 /** 71 * Run a "wait service" CMD. 72 * 73 * @param cls closure. 74 * @param cmd the command being run. 75 * @param is the interpreter state. 76 */ 77 static void 78 wait_service_run (void *cls, 79 const struct TALER_TESTING_Command *cmd, 80 struct TALER_TESTING_Interpreter *is) 81 { 82 unsigned int iter = 0; 83 const char *url = cmd->cls; 84 char *wget_cmd; 85 86 (void) cls; 87 GNUNET_asprintf (&wget_cmd, 88 "wget -q -t 1 -T 1 %s -o /dev/null -O /dev/null", 89 url); 90 do 91 { 92 fprintf (stderr, "."); 93 94 if (10 == iter++) 95 { 96 TALER_LOG_ERROR ("Could not reach the proxied service\n"); 97 TALER_TESTING_interpreter_fail (is); 98 GNUNET_free (wget_cmd); 99 return; 100 } 101 } 102 while (0 != system (wget_cmd)); 103 104 GNUNET_free (wget_cmd); 105 TALER_TESTING_interpreter_next (is); 106 } 107 108 109 /** 110 * This CMD simply tries to connect via HTTP to the 111 * service addressed by @a url. It attempts 10 times 112 * before giving up and make the test fail. 113 * 114 * @param label label for the command. 115 * @param url complete URL to connect to. 116 */ 117 struct TALER_TESTING_Command 118 TALER_TESTING_cmd_wait_service (const char *label, 119 const char *url) 120 { 121 struct TALER_TESTING_Command cmd = { 122 .label = label, 123 .run = wait_service_run, 124 .cleanup = wait_service_cleanup, 125 .traits = wait_service_traits, 126 .cls = (void *) url 127 }; 128 129 return cmd; 130 } 131 132 133 /* end of testing_api_cmd_sleep.c */