test_cdr.c, test_cel.c: Correctly destroy created bridges.
authorRichard Mudgett <rmudgett@digium.com>
Tue, 28 Jan 2014 00:20:46 +0000 (00:20 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Tue, 28 Jan 2014 00:20:46 +0000 (00:20 +0000)
* Fixed the test_cel_attended_transfer_bridges_link unit test to also
account for the local channel link being destroyed now that the bridges
are actually destroyed.

* Made CDR unit test use its own version of do_sleep() from the CEL unit
tests.
........

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

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

tests/test_cdr.c
tests/test_cel.c

index 946b570..75fcdc2 100644 (file)
@@ -360,6 +360,20 @@ static void safe_channel_release(struct ast_channel *chan)
        ast_channel_release(chan);
 }
 
+static void safe_bridge_destroy(struct ast_bridge *bridge)
+{
+       if (!bridge) {
+               return;
+       }
+       ast_bridge_destroy(bridge, 0);
+}
+
+static void do_sleep(struct timespec *to_sleep)
+{
+       while ((nanosleep(to_sleep, to_sleep) == -1) && (errno == EINTR)) {
+       }
+}
+
 AST_TEST_DEFINE(test_cdr_channel_creation)
 {
        RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
@@ -506,7 +520,7 @@ AST_TEST_DEFINE(test_cdr_outbound_bridged_call)
 {
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
                        ao2_cleanup);
        struct timespec to_sleep = {1, 0};
@@ -564,7 +578,7 @@ AST_TEST_DEFINE(test_cdr_outbound_bridged_call)
 
        bridge = ast_bridge_basic_new();
        ast_test_validate(test, bridge != NULL);
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
@@ -582,11 +596,11 @@ AST_TEST_DEFINE(test_cdr_outbound_bridged_call)
 
        ast_channel_state_set(chan_bob, AST_STATE_UP);
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_bridge_depart(chan_bob);
        ast_bridge_depart(chan_alice);
@@ -653,7 +667,7 @@ AST_TEST_DEFINE(test_cdr_single_party)
 AST_TEST_DEFINE(test_cdr_single_bridge)
 {
        RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
                        ao2_cleanup);
        struct timespec to_sleep = {1, 0};
@@ -697,10 +711,10 @@ AST_TEST_DEFINE(test_cdr_single_bridge)
        bridge = ast_bridge_basic_new();
        ast_test_validate(test, bridge != NULL);
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, !ast_bridge_impart(bridge, chan, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_bridge_depart(chan);
 
@@ -714,8 +728,7 @@ AST_TEST_DEFINE(test_cdr_single_bridge)
 AST_TEST_DEFINE(test_cdr_single_bridge_continue)
 {
        RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge_one, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_bridge *, bridge_two, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
                        ao2_cleanup);
        struct timespec to_sleep = {1, 0};
@@ -771,13 +784,13 @@ AST_TEST_DEFINE(test_cdr_single_bridge_continue)
        EMULATE_APP_DATA(chan, 2, "Bridge", "");
        ast_channel_unlock(chan);
 
-       bridge_one = ast_bridge_basic_new();
-       ast_test_validate(test, bridge_one != NULL);
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       bridge = ast_bridge_basic_new();
+       ast_test_validate(test, bridge != NULL);
+       do_sleep(&to_sleep);
 
-       ast_test_validate(test, !ast_bridge_impart(bridge_one, chan, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+       ast_test_validate(test, !ast_bridge_impart(bridge, chan, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_bridge_depart(chan);
 
@@ -795,7 +808,7 @@ AST_TEST_DEFINE(test_cdr_single_twoparty_bridge_a)
 {
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
                        ao2_cleanup);
        struct timespec to_sleep = {1, 0};
@@ -861,7 +874,7 @@ AST_TEST_DEFINE(test_cdr_single_twoparty_bridge_a)
        ast_test_validate(test, bridge != NULL);
 
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_channel_lock(chan_bob);
        EMULATE_APP_DATA(chan_bob, 1, "Answer", "");
@@ -870,7 +883,7 @@ AST_TEST_DEFINE(test_cdr_single_twoparty_bridge_a)
        ast_channel_unlock(chan_bob);
 
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_bridge_depart(chan_alice);
        ast_bridge_depart(chan_bob);
@@ -887,7 +900,7 @@ AST_TEST_DEFINE(test_cdr_single_twoparty_bridge_b)
 {
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
                        ao2_cleanup);
        struct timespec to_sleep = {1, 0};
@@ -957,13 +970,13 @@ AST_TEST_DEFINE(test_cdr_single_twoparty_bridge_b)
        ast_setstate(chan_bob, AST_STATE_UP);
        EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
        ast_channel_unlock(chan_bob);
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_bridge_depart(chan_alice);
        ast_bridge_depart(chan_bob);
@@ -981,7 +994,7 @@ AST_TEST_DEFINE(test_cdr_single_multiparty_bridge)
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
                        ao2_cleanup);
        struct timespec to_sleep = {1, 0};
@@ -1078,7 +1091,7 @@ AST_TEST_DEFINE(test_cdr_single_multiparty_bridge)
 
        bridge = ast_bridge_basic_new();
        ast_test_validate(test, bridge != NULL);
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
@@ -1087,11 +1100,11 @@ AST_TEST_DEFINE(test_cdr_single_multiparty_bridge)
        ast_setstate(chan_bob, AST_STATE_UP);
        EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
        ast_channel_unlock(chan_bob);
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_channel_lock(chan_charlie);
        EMULATE_APP_DATA(chan_charlie, 1, "Answer", "");
@@ -1100,7 +1113,7 @@ AST_TEST_DEFINE(test_cdr_single_multiparty_bridge)
        ast_channel_unlock(chan_charlie);
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_charlie, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_bridge_depart(chan_alice);
        ast_bridge_depart(chan_bob);
@@ -1650,7 +1663,7 @@ AST_TEST_DEFINE(test_cdr_dial_answer_twoparty_bridge_a)
 {
        RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
                        ao2_cleanup);
        struct timespec to_sleep = {1, 0};
@@ -1705,12 +1718,12 @@ AST_TEST_DEFINE(test_cdr_dial_answer_twoparty_bridge_a)
 
        bridge = ast_bridge_basic_new();
        ast_test_validate(test, bridge != NULL);
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_caller, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_callee, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_bridge_depart(chan_caller);
        ast_bridge_depart(chan_callee);
@@ -1726,7 +1739,7 @@ AST_TEST_DEFINE(test_cdr_dial_answer_twoparty_bridge_b)
 {
        RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
                        ao2_cleanup);
        struct timespec to_sleep = {1, 0};
@@ -1781,11 +1794,11 @@ AST_TEST_DEFINE(test_cdr_dial_answer_twoparty_bridge_b)
 
        bridge = ast_bridge_basic_new();
        ast_test_validate(test, bridge != NULL);
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_callee, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_caller, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_bridge_depart(chan_caller);
        ast_bridge_depart(chan_callee);
 
@@ -1802,7 +1815,7 @@ AST_TEST_DEFINE(test_cdr_dial_answer_multiparty)
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
                        ao2_cleanup);
        struct timespec to_sleep = {1, 0};
@@ -1960,15 +1973,15 @@ AST_TEST_DEFINE(test_cdr_dial_answer_multiparty)
        bridge = ast_bridge_basic_new();
        ast_test_validate(test, bridge != NULL);
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_charlie, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_david, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, !ast_bridge_depart(chan_alice));
        ast_test_validate(test, !ast_bridge_depart(chan_bob));
        ast_test_validate(test, !ast_bridge_depart(chan_charlie));
@@ -1988,7 +2001,7 @@ AST_TEST_DEFINE(test_cdr_park)
 {
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
                        ao2_cleanup);
        struct timespec to_sleep = {1, 0};
@@ -2056,11 +2069,11 @@ AST_TEST_DEFINE(test_cdr_park)
                "test_cdr", "test_cdr_park");
        ast_test_validate(test, bridge != NULL);
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_bridge_depart(chan_alice);
        ast_bridge_depart(chan_bob);
 
@@ -2166,7 +2179,7 @@ AST_TEST_DEFINE(test_cdr_fields)
        ast_channel_unlock(chan);
 
        /* Wait one second so we get a duration. */
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        ast_cdr_setuserfield(ast_channel_name(chan), "foobar");
        ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_1") == 0);
@@ -2316,7 +2329,7 @@ AST_TEST_DEFINE(test_cdr_no_reset_cdr)
 
        CREATE_ALICE_CHANNEL(chan, &caller, &expected);
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        /* Disable the CDR */
        ast_test_validate(test, ast_cdr_set_property(ast_channel_name(chan), AST_CDR_FLAG_DISABLE) == 0);
@@ -2418,7 +2431,7 @@ AST_TEST_DEFINE(test_cdr_fork_cdr)
        ast_copy_string(fork_expected_two.uniqueid, ast_channel_uniqueid(chan), sizeof(fork_expected_two.uniqueid));
        ast_copy_string(fork_expected_two.linkedid, ast_channel_linkedid(chan), sizeof(fork_expected_two.linkedid));
 
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
 
        /* Test blowing away variables */
        ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_1") == 0);
@@ -2438,7 +2451,7 @@ AST_TEST_DEFINE(test_cdr_fork_cdr)
        ast_channel_lock(chan);
        ast_setstate(chan, AST_STATE_UP);
        ast_channel_unlock(chan);
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       do_sleep(&to_sleep);
        ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_2") == 0);
        ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "test_variable", varbuffer, sizeof(varbuffer)) == 0);
        ast_test_validate(test, strcmp(varbuffer, "record_2") == 0);
index f509cc5..17c4e09 100644 (file)
@@ -87,7 +87,8 @@ static struct timespec to_sleep = {1, 0};
 
 static void do_sleep(void)
 {
-       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+       while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
+       }
 }
 
 #define APPEND_EVENT(chan, ev_type, userevent, extra) do { \
@@ -357,6 +358,14 @@ static void safe_channel_release(struct ast_channel *chan)
        ast_channel_release(chan);
 }
 
+static void safe_bridge_destroy(struct ast_bridge *bridge)
+{
+       if (!bridge) {
+               return;
+       }
+       ast_bridge_destroy(bridge, 0);
+}
+
 AST_TEST_DEFINE(test_cel_channel_creation)
 {
        RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
@@ -472,7 +481,7 @@ AST_TEST_DEFINE(test_cel_single_party)
 AST_TEST_DEFINE(test_cel_single_bridge)
 {
        RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 
        struct ast_party_caller caller = ALICE_CALLERID;
 
@@ -511,7 +520,7 @@ AST_TEST_DEFINE(test_cel_single_bridge)
 AST_TEST_DEFINE(test_cel_single_bridge_continue)
 {
        RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        struct ast_party_caller caller = ALICE_CALLERID;
 
        switch (cmd) {
@@ -553,7 +562,7 @@ AST_TEST_DEFINE(test_cel_single_twoparty_bridge_a)
 {
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        struct ast_party_caller caller_alice = ALICE_CALLERID;
        struct ast_party_caller caller_bob = BOB_CALLERID;
 
@@ -601,7 +610,7 @@ AST_TEST_DEFINE(test_cel_single_twoparty_bridge_b)
 {
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        struct ast_party_caller caller_alice = ALICE_CALLERID;
        struct ast_party_caller caller_bob = BOB_CALLERID;
 
@@ -654,7 +663,7 @@ AST_TEST_DEFINE(test_cel_single_multiparty_bridge)
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        struct ast_party_caller caller_alice = ALICE_CALLERID;
        struct ast_party_caller caller_bob = BOB_CALLERID;
        struct ast_party_caller caller_charlie = CHARLIE_CALLERID;
@@ -1003,7 +1012,7 @@ AST_TEST_DEFINE(test_cel_dial_answer_twoparty_bridge_a)
 {
        RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        struct ast_party_caller caller = ALICE_CALLERID;
 
        switch (cmd) {
@@ -1050,7 +1059,7 @@ AST_TEST_DEFINE(test_cel_dial_answer_twoparty_bridge_b)
 {
        RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        struct ast_party_caller caller = ALICE_CALLERID;
 
        switch (cmd) {
@@ -1099,7 +1108,7 @@ AST_TEST_DEFINE(test_cel_dial_answer_multiparty)
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        struct ast_party_caller alice_caller = ALICE_CALLERID;
        struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
 
@@ -1173,7 +1182,7 @@ AST_TEST_DEFINE(test_cel_blind_transfer)
 {
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
        struct ast_party_caller alice_caller = ALICE_CALLERID;
        struct ast_party_caller bob_caller = BOB_CALLERID;
        struct ast_bridge_channel_pair pair;
@@ -1224,8 +1233,8 @@ AST_TEST_DEFINE(test_cel_attended_transfer_bridges_swap)
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge1, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_bridge *, bridge2, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge1, NULL, safe_bridge_destroy);
+       RAII_VAR(struct ast_bridge *, bridge2, NULL, safe_bridge_destroy);
        struct ast_party_caller alice_caller = ALICE_CALLERID;
        struct ast_party_caller bob_caller = BOB_CALLERID;
        struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
@@ -1301,8 +1310,8 @@ AST_TEST_DEFINE(test_cel_attended_transfer_bridges_merge)
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge1, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_bridge *, bridge2, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge1, NULL, safe_bridge_destroy);
+       RAII_VAR(struct ast_bridge *, bridge2, NULL, safe_bridge_destroy);
        struct ast_party_caller alice_caller = ALICE_CALLERID;
        struct ast_party_caller bob_caller = BOB_CALLERID;
        struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
@@ -1382,8 +1391,8 @@ AST_TEST_DEFINE(test_cel_attended_transfer_bridges_link)
        RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
        RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
-       RAII_VAR(struct ast_bridge *, bridge1, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_bridge *, bridge2, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_bridge *, bridge1, NULL, safe_bridge_destroy);
+       RAII_VAR(struct ast_bridge *, bridge2, NULL, safe_bridge_destroy);
        struct ast_party_caller alice_caller = ALICE_CALLERID;
        struct ast_party_caller bob_caller = BOB_CALLERID;
        struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
@@ -1439,7 +1448,7 @@ AST_TEST_DEFINE(test_cel_attended_transfer_bridges_link)
 
        /* The following events can not be matched directly since nothing is known
         * about the linking local channel.
-        * local channel ;1 and ;2 creation and ;2 answer */
+        * ;1 and ;2 CHAN_START and ;2 ANSWER */
        APPEND_DUMMY_EVENT();
        APPEND_DUMMY_EVENT();
        APPEND_DUMMY_EVENT();
@@ -1469,6 +1478,15 @@ AST_TEST_DEFINE(test_cel_attended_transfer_bridges_link)
        HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "");
        do_sleep();
        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;
 }