tests/test_cel: Fix CEL unit test failures caused by attended transfer changes
authorMatthew Jordan <mjordan@digium.com>
Wed, 3 Dec 2014 19:49:38 +0000 (19:49 +0000)
committerMatthew Jordan <mjordan@digium.com>
Wed, 3 Dec 2014 19:49:38 +0000 (19:49 +0000)
When the publication of attended transfer messages were pushed to another
thread, some subtle race conditions were introduced with the CEL unit tests.
This patch fixes one of them, and pushes the other to ASTERISK-22367, which
already exists to fix another bouncy CEL unit test.

In particular, this patch fixes the test_cel_attended_transfer_bridges_link
test, and defers the test_cel_attended_transfer_bridges_swap test to the
aforementioned JIRA issue.

ASTERISK-22367
........

Merged revisions 428891 from http://svn.asterisk.org/svn/asterisk/branches/12
........

Merged revisions 428892 from http://svn.asterisk.org/svn/asterisk/branches/13

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@428893 65c4cc65-6c06-0410-ace0-fbb531ad65f3

tests/test_cel.c

index 194bbf3..cd39a62 100644 (file)
@@ -1300,6 +1300,10 @@ AST_TEST_DEFINE(test_cel_blind_transfer)
        return AST_TEST_PASS;
 }
 
+/* XXX Validation needs to take into account the BRIDGE_EXIT for Alice and the
+ * ATTENDEDTRANSFER message are not guaranteed to be ordered
+ */
+#ifdef RACEY_TESTS
 AST_TEST_DEFINE(test_cel_attended_transfer_bridges_swap)
 {
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
@@ -1362,8 +1366,8 @@ AST_TEST_DEFINE(test_cel_attended_transfer_bridges_swap)
        BRIDGE_ENTER_EVENT_PEER(chan_bob, bridge2, "CELTestChannel/David,CELTestChannel/Charlie");
 
        BRIDGE_EXIT_EVENT(chan_david, bridge2);
-       ATTENDEDTRANSFER_BRIDGE(chan_alice, bridge1, chan_david, bridge2, chan_charlie, chan_bob);
        BRIDGE_EXIT_EVENT(chan_alice, bridge1);
+       ATTENDEDTRANSFER_BRIDGE(chan_alice, bridge1, chan_david, bridge2, chan_charlie, chan_bob);
 
        do_sleep();
        BRIDGE_EXIT(chan_bob, bridge2);
@@ -1379,6 +1383,7 @@ AST_TEST_DEFINE(test_cel_attended_transfer_bridges_swap)
 
        return AST_TEST_PASS;
 }
+#endif
 
 AST_TEST_DEFINE(test_cel_attended_transfer_bridges_merge)
 {
@@ -1524,24 +1529,11 @@ AST_TEST_DEFINE(test_cel_attended_transfer_bridges_link)
        BRIDGE_ENTER(chan_david, bridge2);
 
        /* Perform attended transfer */
-
-       /* The following events can not be matched directly since nothing is known
-        * about the linking local channel.
-        * ;1 and ;2 CHAN_START and ;2 ANSWER */
-       APPEND_DUMMY_EVENT();
-       APPEND_DUMMY_EVENT();
-       APPEND_DUMMY_EVENT();
-
        ATTENDEDTRANSFER_BRIDGE(chan_alice, bridge1, chan_david, bridge2, chan_charlie, chan_bob);
 
        ast_bridge_transfer_attended(chan_alice, chan_david);
        do_sleep();
 
-       /* ;1 and ;2 BRIDGE_ENTER and ;1 ANSWER */
-       APPEND_DUMMY_EVENT();
-       APPEND_DUMMY_EVENT();
-       APPEND_DUMMY_EVENT();
-
        /* BRIDGE_EXIT alice and david */
        APPEND_DUMMY_EVENT();
        APPEND_DUMMY_EVENT();
@@ -1559,14 +1551,6 @@ AST_TEST_DEFINE(test_cel_attended_transfer_bridges_link)
        HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
        do_sleep();
 
-       /* ;1 and ;2 BRIDGE_EXIT, HANGUP, and CHAN_END */
-       APPEND_DUMMY_EVENT();
-       APPEND_DUMMY_EVENT();
-       APPEND_DUMMY_EVENT();
-       APPEND_DUMMY_EVENT();
-       APPEND_DUMMY_EVENT();
-       APPEND_DUMMY_EVENT();
-
        return AST_TEST_PASS;
 }
 
@@ -1800,12 +1784,18 @@ static int append_expected_event(
 static void test_sub(struct ast_event *event)
 {
        struct ast_event *event_dup = ao2_dup_event(event);
+       const char *chan_name;
        SCOPED_MUTEX(mid_test_lock, &mid_test_sync_lock);
 
        if (!event_dup) {
                return;
        }
 
+       chan_name = ast_event_get_ie_str(event_dup, AST_EVENT_IE_CEL_CHANNAME);
+       if (chan_name && strncmp(chan_name, CHANNEL_TECH_NAME, 14)) {
+               return;
+       }
+
        /* save the event for later processing */
        ao2_link(cel_received_events, event_dup);
 
@@ -2130,10 +2120,10 @@ static int unload_module(void)
        AST_TEST_UNREGISTER(test_cel_dial_answer_twoparty_bridge_b);
 #ifdef RACEY_TESTS
        AST_TEST_UNREGISTER(test_cel_dial_answer_multiparty);
+       AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_swap);
 #endif
 
        AST_TEST_UNREGISTER(test_cel_blind_transfer);
-       AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_swap);
        AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_merge);
        AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_link);
 
@@ -2205,10 +2195,10 @@ static int load_module(void)
        AST_TEST_REGISTER(test_cel_dial_answer_twoparty_bridge_b);
 #ifdef RACEY_TESTS
        AST_TEST_REGISTER(test_cel_dial_answer_multiparty);
+       AST_TEST_REGISTER(test_cel_attended_transfer_bridges_swap);
 #endif
 
        AST_TEST_REGISTER(test_cel_blind_transfer);
-       AST_TEST_REGISTER(test_cel_attended_transfer_bridges_swap);
        AST_TEST_REGISTER(test_cel_attended_transfer_bridges_merge);
        AST_TEST_REGISTER(test_cel_attended_transfer_bridges_link);