summaryrefslogtreecommitdiff
path: root/src/conversation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-27 13:48:21 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-27 13:48:21 +0000
commitbeae62bfc73edc1784efbcbb8efd74c07a057865 (patch)
tree953a0890b0d2bbdea5427e57fa91c72ffee2b018 /src/conversation
parent9db237899dd8db104328221e6911fcbbf9d0f3cf (diff)
handle failures more gracefully in test
Diffstat (limited to 'src/conversation')
-rw-r--r--src/conversation/conversation_api_call.c26
-rw-r--r--src/conversation/test_conversation_api.c20
-rw-r--r--src/conversation/test_conversation_api_twocalls.c37
3 files changed, 62 insertions, 21 deletions
diff --git a/src/conversation/conversation_api_call.c b/src/conversation/conversation_api_call.c
index 728b495b3..ad83288b9 100644
--- a/src/conversation/conversation_api_call.c
+++ b/src/conversation/conversation_api_call.c
@@ -154,7 +154,7 @@ struct GNUNET_CONVERSATION_Call
* @param call call to reconnect
*/
static void
-reconnect_call (struct GNUNET_CONVERSATION_Call *call);
+fail_call (struct GNUNET_CONVERSATION_Call *call);
/**
@@ -198,11 +198,11 @@ handle_call_suspend (void *cls,
{
case CS_LOOKUP:
GNUNET_break (0);
- reconnect_call (call);
+ fail_call (call);
break;
case CS_RINGING:
GNUNET_break_op (0);
- reconnect_call (call);
+ fail_call (call);
break;
case CS_SUSPENDED_CALLER:
call->state = CS_SUSPENDED_BOTH;
@@ -243,11 +243,11 @@ handle_call_resume (void *cls,
{
case CS_LOOKUP:
GNUNET_break (0);
- reconnect_call (call);
+ fail_call (call);
break;
case CS_RINGING:
GNUNET_break_op (0);
- reconnect_call (call);
+ fail_call (call);
break;
case CS_SUSPENDED_CALLER:
GNUNET_break_op (0);
@@ -292,7 +292,7 @@ handle_call_picked_up (void *cls,
{
case CS_LOOKUP:
GNUNET_break (0);
- reconnect_call (call);
+ fail_call (call);
break;
case CS_RINGING:
call->state = CS_ACTIVE;
@@ -308,7 +308,7 @@ handle_call_picked_up (void *cls,
case CS_SUSPENDED_BOTH:
case CS_ACTIVE:
GNUNET_break (0);
- reconnect_call (call);
+ fail_call (call);
break;
case CS_SHUTDOWN:
GNUNET_CONVERSATION_call_stop (call);
@@ -335,7 +335,7 @@ handle_call_hangup (void *cls,
{
case CS_LOOKUP:
GNUNET_break (0);
- reconnect_call (call);
+ fail_call (call);
break;
case CS_RINGING:
case CS_SUSPENDED_CALLER:
@@ -386,11 +386,11 @@ handle_call_audio (void *cls,
{
case CS_LOOKUP:
GNUNET_break (0);
- reconnect_call (call);
+ fail_call (call);
break;
case CS_RINGING:
GNUNET_break (0);
- reconnect_call (call);
+ fail_call (call);
break;
case CS_SUSPENDED_CALLER:
/* can happen: we suspended, other peer did not yet
@@ -482,17 +482,17 @@ call_error_handler (void *cls,
}
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Connection to conversation service lost, trying to reconnect\n"));
- reconnect_call (call);
+ fail_call (call);
}
/**
- * The call got disconnected, reconnect to the service.
+ * The call got disconnected, destroy the handle.
*
* @param call call to reconnect
*/
static void
-reconnect_call (struct GNUNET_CONVERSATION_Call *call)
+fail_call (struct GNUNET_CONVERSATION_Call *call)
{
if (CS_ACTIVE == call->state)
{
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c
index f8159115b..fd9327805 100644
--- a/src/conversation/test_conversation_api.c
+++ b/src/conversation/test_conversation_api.c
@@ -67,9 +67,9 @@ static GNUNET_MICROPHONE_RecordedDataCallback call_rdc;
static void *call_rdc_cls;
-static struct GNUNET_SCHEDULER_Task * phone_task;
+static struct GNUNET_SCHEDULER_Task *phone_task;
-static struct GNUNET_SCHEDULER_Task * call_task;
+static struct GNUNET_SCHEDULER_Task *call_task;
static void
@@ -347,11 +347,14 @@ phone_event_handler (void *cls,
case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP:
GNUNET_break (caller == active_caller);
active_caller = NULL;
- ok = 0;
+ if (1 == ok)
+ ok = 0;
GNUNET_SCHEDULER_shutdown ();
break;
default:
- fprintf (stderr, "Unexpected phone code: %d\n", code);
+ fprintf (stderr,
+ "Unexpected phone code: %d\n",
+ code);
break;
}
}
@@ -376,12 +379,21 @@ call_event_handler (void *cls,
case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
call = NULL;
+ ok = 2;
+ GNUNET_break (0);
fprintf (stderr, "Unexpected call code: %d\n", code);
break;
case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
case GNUNET_CONVERSATION_EC_CALL_RESUMED:
+ GNUNET_break (0);
+ fprintf (stderr, "Unexpected call code: %d\n", code);
+ ok = 2;
+ break;
case GNUNET_CONVERSATION_EC_CALL_ERROR:
+ GNUNET_break (0);
fprintf (stderr, "Unexpected call code: %d\n", code);
+ call = NULL;
+ ok = 2;
break;
}
}
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c
index 17a12eb4f..2e2a73e3f 100644
--- a/src/conversation/test_conversation_api_twocalls.c
+++ b/src/conversation/test_conversation_api_twocalls.c
@@ -73,7 +73,9 @@ static GNUNET_MICROPHONE_RecordedDataCallback phone_rdc;
static void *phone_rdc_cls;
-static struct GNUNET_SCHEDULER_Task * phone_task;
+static struct GNUNET_SCHEDULER_Task *phone_task;
+
+static struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* Variable for recognizing caller1
@@ -338,14 +340,33 @@ static struct GNUNET_MICROPHONE_Handle phone_mic = {
/**
- * Signature of the main function of a task.
+ * Function run on timeout.
*
* @param cls closure
*/
static void
end_test (void *cls)
{
+ timeout_task = NULL;
+ fprintf (stderr,
+ "Timeout!\n");
GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Function run on shutdown.
+ *
+ * @param cls closure
+ */
+static void
+do_shutdown (void *cls)
+{
+ if (NULL != timeout_task)
+ {
+ GNUNET_SCHEDULER_cancel (timeout_task);
+ timeout_task = NULL;
+ }
if (NULL != op)
{
GNUNET_IDENTITY_cancel (op);
@@ -485,6 +506,11 @@ call_event_handler (void *cls,
break;
case GNUNET_CONVERSATION_EC_CALL_ERROR:
GNUNET_break (0);
+ if (0 == strcmp (cid, "call1"))
+ call1 = NULL;
+ else
+ call2 = NULL;
+ GNUNET_SCHEDULER_shutdown ();
break;
}
}
@@ -592,8 +618,11 @@ run (void *cls,
struct GNUNET_TESTING_Peer *peer)
{
cfg = c;
- GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test,
- NULL);
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_test,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
id = GNUNET_IDENTITY_connect (cfg,
&identity_cb,
NULL);