aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-27 10:09:36 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-27 10:09:36 +0000
commitda69908da5c89e01c663b54da76099033aca4bb0 (patch)
tree22d8121dadfef2baa4d4b8125e1d01496a428a24 /src/gns
parent1af6c9bcef1500cdf1c59be391c70c4dc6617401 (diff)
downloadgnunet-da69908da5c89e01c663b54da76099033aca4bb0.tar.gz
gnunet-da69908da5c89e01c663b54da76099033aca4bb0.zip
-fixing testcase shutdown
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gns_api.c2
-rw-r--r--src/gns/test_gns_max_queries.c106
2 files changed, 66 insertions, 42 deletions
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 8d0fe6e99..94142ea88 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -899,7 +899,7 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
899 * @param proc_cls closure for processor 899 * @param proc_cls closure for processor
900 * @return handle to the lookup request 900 * @return handle to the lookup request
901 */ 901 */
902struct GNUNET_GNS_LookupRequest* 902struct GNUNET_GNS_LookupRequest *
903GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, 903GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
904 const char *name, 904 const char *name,
905 enum GNUNET_GNS_RecordType type, 905 enum GNUNET_GNS_RecordType type,
diff --git a/src/gns/test_gns_max_queries.c b/src/gns/test_gns_max_queries.c
index fecc40925..d06f4ebed 100644
--- a/src/gns/test_gns_max_queries.c
+++ b/src/gns/test_gns_max_queries.c
@@ -32,8 +32,6 @@
32#include "gnunet_dnsparser_lib.h" 32#include "gnunet_dnsparser_lib.h"
33#include "gnunet_gns_service.h" 33#include "gnunet_gns_service.h"
34 34
35/* DEFINES */
36#define VERBOSE GNUNET_YES
37 35
38/* Timeout for entire testcase */ 36/* Timeout for entire testcase */
39#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) 37#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20)
@@ -54,7 +52,7 @@
54/* Globals */ 52/* Globals */
55 53
56/* Task handle to use to schedule test failure */ 54/* Task handle to use to schedule test failure */
57GNUNET_SCHEDULER_TaskIdentifier die_task; 55static GNUNET_SCHEDULER_TaskIdentifier die_task;
58 56
59/* Global return value (0 for success, anything else for failure) */ 57/* Global return value (0 for success, anything else for failure) */
60static int ok; 58static int ok;
@@ -63,10 +61,14 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle;
63 61
64static struct GNUNET_GNS_Handle *gns_handle; 62static struct GNUNET_GNS_Handle *gns_handle;
65 63
66const struct GNUNET_CONFIGURATION_Handle *cfg; 64static const struct GNUNET_CONFIGURATION_Handle *cfg;
67 65
68static unsigned long long max_parallel_lookups; 66static unsigned long long max_parallel_lookups;
69 67
68static struct GNUNET_GNS_LookupRequest **requests;
69
70static unsigned int num_requests;
71
70 72
71/** 73/**
72 * Check if the get_handle is being used, if so stop the request. Either 74 * Check if the get_handle is being used, if so stop the request. Either
@@ -76,13 +78,17 @@ static unsigned long long max_parallel_lookups;
76static void 78static void
77end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 79end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
78{ 80{
81 unsigned int i;
82
83 for (i=0;i<num_requests;i++)
84 if (NULL != requests[i])
85 GNUNET_GNS_cancel_lookup_request (requests[i]);
79 die_task = GNUNET_SCHEDULER_NO_TASK; 86 die_task = GNUNET_SCHEDULER_NO_TASK;
80 if (NULL != gns_handle) 87 if (NULL != gns_handle)
81 { 88 {
82 GNUNET_GNS_disconnect(gns_handle); 89 GNUNET_GNS_disconnect(gns_handle);
83 gns_handle = NULL; 90 gns_handle = NULL;
84 } 91 }
85
86 if (NULL != namestore_handle) 92 if (NULL != namestore_handle)
87 { 93 {
88 GNUNET_NAMESTORE_disconnect (namestore_handle); 94 GNUNET_NAMESTORE_disconnect (namestore_handle);
@@ -90,29 +96,49 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
90 } 96 }
91 GNUNET_break (0); 97 GNUNET_break (0);
92 GNUNET_SCHEDULER_shutdown (); 98 GNUNET_SCHEDULER_shutdown ();
99 GNUNET_free (requests);
93 ok = 1; 100 ok = 1;
94} 101}
95 102
96static void
97end_badly_now ()
98{
99 GNUNET_SCHEDULER_cancel (die_task);
100 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
101}
102
103 103
104static void shutdown_task (void *cls, 104static void
105 const struct GNUNET_SCHEDULER_TaskContext *tc) 105shutdown_task (void *cls,
106 const struct GNUNET_SCHEDULER_TaskContext *tc)
106{ 107{
107 GNUNET_GNS_disconnect(gns_handle); 108 unsigned int i;
109
110 if (GNUNET_SCHEDULER_NO_TASK != die_task)
111 {
112 GNUNET_SCHEDULER_cancel (die_task);
113 die_task = GNUNET_SCHEDULER_NO_TASK;
114 }
115 for (i=0;i<num_requests;i++)
116 if (NULL != requests[i])
117 GNUNET_GNS_cancel_lookup_request (requests[i]);
118 if (NULL != gns_handle)
119 {
120 GNUNET_GNS_disconnect (gns_handle);
121 gns_handle = NULL;
122 }
123 if (NULL != namestore_handle)
124 {
125 GNUNET_NAMESTORE_disconnect (namestore_handle);
126 namestore_handle = NULL;
127 }
108 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); 128 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
109 GNUNET_SCHEDULER_shutdown (); 129 GNUNET_SCHEDULER_shutdown ();
130 GNUNET_free (requests);
110} 131}
132
133
111static void 134static void
112on_lookup_result_dummy(void *cls, uint32_t rd_count, 135on_lookup_result_dummy (void *cls, uint32_t rd_count,
113 const struct GNUNET_NAMESTORE_RecordData *rd) 136 const struct GNUNET_NAMESTORE_RecordData *rd)
114{ 137{
138 struct GNUNET_GNS_LookupRequest **request = cls;
115 static int replies = 0; 139 static int replies = 0;
140
141 *request = NULL;
116 if (GNUNET_SCHEDULER_NO_TASK != die_task) 142 if (GNUNET_SCHEDULER_NO_TASK != die_task)
117 { 143 {
118 GNUNET_SCHEDULER_cancel (die_task); 144 GNUNET_SCHEDULER_cancel (die_task);
@@ -126,20 +152,19 @@ on_lookup_result_dummy(void *cls, uint32_t rd_count,
126 ok = -1; 152 ok = -1;
127 } 153 }
128 replies++; 154 replies++;
129 if (replies == (max_parallel_lookups+TEST_ADDITIONAL_LOOKUPS))
130 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
131 fprintf (stderr, "."); 155 fprintf (stderr, ".");
132} 156}
133 157
134 158
135static void 159static void
136on_lookup_result(void *cls, uint32_t rd_count, 160on_lookup_result (void *cls, uint32_t rd_count,
137 const struct GNUNET_NAMESTORE_RecordData *rd) 161 const struct GNUNET_NAMESTORE_RecordData *rd)
138{ 162{
139 struct in_addr a; 163 struct in_addr a;
140 int i; 164 int i;
141 char* addr; 165 char* addr;
142 166
167 requests[max_parallel_lookups + TEST_ADDITIONAL_LOOKUPS] = NULL;
143 if (GNUNET_SCHEDULER_NO_TASK != die_task) 168 if (GNUNET_SCHEDULER_NO_TASK != die_task)
144 { 169 {
145 GNUNET_SCHEDULER_cancel (die_task); 170 GNUNET_SCHEDULER_cancel (die_task);
@@ -193,7 +218,7 @@ commence_testing (void *cls, int32_t success, const char *emsg)
193{ 218{
194 int i; 219 int i;
195 char lookup_name[MAX_DNS_NAME_LENGTH]; 220 char lookup_name[MAX_DNS_NAME_LENGTH];
196 221 struct GNUNET_GNS_LookupRequest *lr;
197 222
198 gns_handle = GNUNET_GNS_connect(cfg); 223 gns_handle = GNUNET_GNS_connect(cfg);
199 224
@@ -211,16 +236,18 @@ commence_testing (void *cls, int32_t success, const char *emsg)
211 GNUNET_snprintf(lookup_name, 236 GNUNET_snprintf(lookup_name,
212 MAX_DNS_NAME_LENGTH, 237 MAX_DNS_NAME_LENGTH,
213 "www.doesnotexist-%d.bob.gads", i); 238 "www.doesnotexist-%d.bob.gads", i);
214 GNUNET_GNS_lookup(gns_handle, lookup_name, GNUNET_GNS_RECORD_A, 239 lr = GNUNET_GNS_lookup (gns_handle, lookup_name, GNUNET_GNS_RECORD_A,
215 GNUNET_NO, 240 GNUNET_NO,
216 NULL, 241 NULL,
217 &on_lookup_result_dummy, NULL); 242 &on_lookup_result_dummy, &requests[num_requests]);
243 requests[num_requests++] = lr;
218 } 244 }
219 245 lr = GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
220 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A, 246 GNUNET_NO,
221 GNUNET_NO, 247 NULL,
222 NULL, 248 &on_lookup_result, TEST_DOMAIN);
223 &on_lookup_result, TEST_DOMAIN); 249 requests[num_requests++] = lr;
250 GNUNET_assert (num_requests == max_parallel_lookups + TEST_ADDITIONAL_LOOKUPS + 1);
224} 251}
225 252
226 253
@@ -246,7 +273,7 @@ do_check (void *cls,
246 if (NULL == namestore_handle) 273 if (NULL == namestore_handle)
247 { 274 {
248 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); 275 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
249 end_badly_now(); 276 GNUNET_SCHEDULER_shutdown ();
250 return; 277 return;
251 } 278 }
252 279
@@ -255,20 +282,21 @@ do_check (void *cls,
255 &alice_keyfile)) 282 &alice_keyfile))
256 { 283 {
257 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); 284 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
258 end_badly_now(); 285 GNUNET_SCHEDULER_shutdown ();
259 return; 286 return;
260 } 287 }
261 288
262 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "gns", 289 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "gns",
263 "MAX_PARALLEL_BACKGROUND_QUERIES", 290 "MAX_PARALLEL_BACKGROUND_QUERIES",
264 &max_parallel_lookups)) 291 &max_parallel_lookups))
265 { 292 {
266 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get max queries from cfg\n"); 293 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get max queries from cfg\n");
267 end_badly_now(); 294 GNUNET_SCHEDULER_shutdown ();
268 GNUNET_free (alice_keyfile); 295 GNUNET_free (alice_keyfile);
269 return; 296 return;
270 } 297 }
271 298 requests = GNUNET_malloc ((max_parallel_lookups + TEST_ADDITIONAL_LOOKUPS + 1) *
299 sizeof (struct GNUNET_GNS_LookupRequest *));
272 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile); 300 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile);
273 bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB); 301 bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB);
274 302
@@ -319,11 +347,7 @@ main (int argc, char *argv[])
319 ok = 1; 347 ok = 1;
320 348
321 GNUNET_log_setup ("test-gns-max-queries", 349 GNUNET_log_setup ("test-gns-max-queries",
322#if VERBOSE
323 "DEBUG",
324#else
325 "WARNING", 350 "WARNING",
326#endif
327 NULL); 351 NULL);
328 GNUNET_TESTING_peer_run ("test-gns-max-queries", "test_gns_simple_lookup.conf", &do_check, NULL); 352 GNUNET_TESTING_peer_run ("test-gns-max-queries", "test_gns_simple_lookup.conf", &do_check, NULL);
329 return ok; 353 return ok;