diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-12 16:16:40 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-12 16:16:40 +0000 |
commit | b0d45a48d3b75c05300d6b643cc96b321c1000c6 (patch) | |
tree | 18d11193d79a212906e1ce75162b90181a1b5a40 /src/testbed | |
parent | 004f722370039f34f4ecc61bdd5ae61bf2f1a0a4 (diff) | |
download | gnunet-b0d45a48d3b75c05300d6b643cc96b321c1000c6.tar.gz gnunet-b0d45a48d3b75c05300d6b643cc96b321c1000c6.zip |
tests to show overlay_connect on already connected peers doesn't fail
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/test_testbed_api_2peers.c | 136 |
1 files changed, 101 insertions, 35 deletions
diff --git a/src/testbed/test_testbed_api_2peers.c b/src/testbed/test_testbed_api_2peers.c index 43becddba..467390798 100644 --- a/src/testbed/test_testbed_api_2peers.c +++ b/src/testbed/test_testbed_api_2peers.c | |||
@@ -116,39 +116,49 @@ static struct GNUNET_TESTBED_Operation *common_operation; | |||
116 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | 116 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; |
117 | 117 | ||
118 | /** | 118 | /** |
119 | * Delayed connect job identifier | ||
120 | */ | ||
121 | static GNUNET_SCHEDULER_TaskIdentifier delayed_connect_task; | ||
122 | |||
123 | /** | ||
119 | * Different stages in testing | 124 | * Different stages in testing |
120 | */ | 125 | */ |
121 | enum Stage | 126 | enum Stage |
122 | { | 127 | { |
123 | 128 | ||
124 | /** | 129 | /** |
125 | * Initial stage | 130 | * Initial stage |
126 | */ | 131 | */ |
127 | INIT, | 132 | INIT, |
128 | 133 | ||
129 | /** | 134 | /** |
130 | * peers are created | 135 | * peers are created |
131 | */ | 136 | */ |
132 | PEERS_CREATED, | 137 | PEERS_CREATED, |
133 | 138 | ||
134 | /** | 139 | /** |
135 | * peers are started | 140 | * peers are started |
136 | */ | 141 | */ |
137 | PEERS_STARTED, | 142 | PEERS_STARTED, |
138 | 143 | ||
139 | /** | 144 | /** |
140 | * peers are connected | 145 | * peers are connected |
141 | */ | 146 | */ |
142 | PEERS_CONNECTED, | 147 | PEERS_CONNECTED, |
143 | 148 | ||
144 | /** | 149 | /** |
145 | * peers are stopped | 150 | * Peers are connected once again (this should not fail as they are already connected) |
146 | */ | 151 | */ |
152 | PEERS_CONNECTED_2, | ||
153 | |||
154 | /** | ||
155 | * peers are stopped | ||
156 | */ | ||
147 | PEERS_STOPPED, | 157 | PEERS_STOPPED, |
148 | 158 | ||
149 | /** | 159 | /** |
150 | * Final success stage | 160 | * Final success stage |
151 | */ | 161 | */ |
152 | SUCCESS | 162 | SUCCESS |
153 | }; | 163 | }; |
154 | 164 | ||
@@ -169,6 +179,7 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
169 | { | 179 | { |
170 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | 180 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) |
171 | GNUNET_SCHEDULER_cancel (abort_task); | 181 | GNUNET_SCHEDULER_cancel (abort_task); |
182 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == delayed_connect_task); | ||
172 | if (NULL != reg_handle) | 183 | if (NULL != reg_handle) |
173 | GNUNET_TESTBED_cancel_registration (reg_handle); | 184 | GNUNET_TESTBED_cancel_registration (reg_handle); |
174 | GNUNET_TESTBED_controller_disconnect (controller); | 185 | GNUNET_TESTBED_controller_disconnect (controller); |
@@ -191,6 +202,7 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
191 | { | 202 | { |
192 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | 203 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); |
193 | abort_task = GNUNET_SCHEDULER_NO_TASK; | 204 | abort_task = GNUNET_SCHEDULER_NO_TASK; |
205 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == delayed_connect_task); | ||
194 | do_shutdown (cls, tc); | 206 | do_shutdown (cls, tc); |
195 | } | 207 | } |
196 | 208 | ||
@@ -204,18 +216,65 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
204 | * operation has executed successfully. | 216 | * operation has executed successfully. |
205 | */ | 217 | */ |
206 | static void | 218 | static void |
219 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); | ||
220 | |||
221 | |||
222 | /** | ||
223 | * task for delaying a connect | ||
224 | * | ||
225 | * @param cls NULL | ||
226 | * @param tc the task context | ||
227 | */ | ||
228 | static void | ||
229 | do_delayed_connect (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
230 | { | ||
231 | delayed_connect_task = GNUNET_SCHEDULER_NO_TASK; | ||
232 | GNUNET_assert (NULL == common_operation); | ||
233 | common_operation = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, | ||
234 | peer1.peer, peer2.peer); | ||
235 | } | ||
236 | |||
237 | |||
238 | /** | ||
239 | * Callback to be called when an operation is completed | ||
240 | * | ||
241 | * @param cls the callback closure from functions generating an operation | ||
242 | * @param op the operation that has been finished | ||
243 | * @param emsg error message in case the operation has failed; will be NULL if | ||
244 | * operation has executed successfully. | ||
245 | */ | ||
246 | static void | ||
207 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | 247 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) |
208 | { | 248 | { |
209 | GNUNET_assert (PEERS_STARTED == result); | 249 | GNUNET_assert (common_operation == op); |
210 | GNUNET_assert (NULL == peer1.operation); | 250 | switch(result) |
211 | GNUNET_assert (NULL == peer2.operation); | 251 | { |
212 | GNUNET_assert (NULL != common_operation); | 252 | case PEERS_STARTED: |
213 | GNUNET_TESTBED_operation_done (common_operation); | 253 | GNUNET_assert (NULL == peer1.operation); |
214 | common_operation = NULL; | 254 | GNUNET_assert (NULL == peer2.operation); |
215 | result = PEERS_CONNECTED; | 255 | GNUNET_assert (NULL != common_operation); |
216 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); | 256 | GNUNET_TESTBED_operation_done (common_operation); |
217 | peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer, NULL, NULL); | 257 | common_operation = NULL; |
218 | peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer, NULL, NULL); | 258 | result = PEERS_CONNECTED; |
259 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); | ||
260 | delayed_connect_task = | ||
261 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), | ||
262 | &do_delayed_connect, NULL); | ||
263 | break; | ||
264 | case PEERS_CONNECTED: | ||
265 | GNUNET_assert (NULL == peer1.operation); | ||
266 | GNUNET_assert (NULL == peer2.operation); | ||
267 | GNUNET_assert (NULL != common_operation); | ||
268 | GNUNET_TESTBED_operation_done (common_operation); | ||
269 | common_operation = NULL; | ||
270 | result = PEERS_CONNECTED_2; | ||
271 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n"); | ||
272 | peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer, NULL, NULL); | ||
273 | peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer, NULL, NULL); | ||
274 | break; | ||
275 | default: | ||
276 | GNUNET_assert (0); | ||
277 | } | ||
219 | } | 278 | } |
220 | 279 | ||
221 | 280 | ||
@@ -282,7 +341,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
282 | } | 341 | } |
283 | break; | 342 | break; |
284 | case GNUNET_TESTBED_ET_PEER_STOP: | 343 | case GNUNET_TESTBED_ET_PEER_STOP: |
285 | GNUNET_assert (PEERS_CONNECTED == result); | 344 | GNUNET_assert (PEERS_CONNECTED_2 == result); |
286 | if (event->details.peer_stop.peer == peer1.peer) | 345 | if (event->details.peer_stop.peer == peer1.peer) |
287 | { | 346 | { |
288 | peer1.is_running = GNUNET_NO; | 347 | peer1.is_running = GNUNET_NO; |
@@ -301,12 +360,19 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
301 | result = PEERS_STOPPED; | 360 | result = PEERS_STOPPED; |
302 | break; | 361 | break; |
303 | case GNUNET_TESTBED_ET_CONNECT: | 362 | case GNUNET_TESTBED_ET_CONNECT: |
304 | GNUNET_assert (PEERS_STARTED == result); | 363 | switch (result) |
305 | GNUNET_assert (NULL == peer1.operation); | 364 | { |
306 | GNUNET_assert (NULL == peer2.operation); | 365 | case PEERS_STARTED: |
307 | GNUNET_assert (NULL != common_operation); | 366 | case PEERS_CONNECTED: |
308 | GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) && | 367 | GNUNET_assert (NULL == peer1.operation); |
309 | (event->details.peer_connect.peer2 == peer2.peer)); | 368 | GNUNET_assert (NULL == peer2.operation); |
369 | GNUNET_assert (NULL != common_operation); | ||
370 | GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) && | ||
371 | (event->details.peer_connect.peer2 == peer2.peer)); | ||
372 | break; | ||
373 | default: | ||
374 | GNUNET_assert (0); | ||
375 | } | ||
310 | break; | 376 | break; |
311 | default: | 377 | default: |
312 | GNUNET_assert (0); | 378 | GNUNET_assert (0); |