]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
test_stasis_endpoints.c: Make channel_messages more stable
authorGeorge Joseph <gjoseph@sangoma.com>
Fri, 9 Jun 2023 16:41:13 +0000 (10:41 -0600)
committerasterisk-org-access-app[bot] <120671045+asterisk-org-access-app[bot]@users.noreply.github.com>
Fri, 9 Jun 2023 23:28:15 +0000 (23:28 +0000)
The channel_messages test was assuming that stasis would return
messages in a specific order.  This is an incorrect assumption as
message ordering was never guaranteed.  This was causing the test
to fail occasionally.  We now test all the messages for the
required message types instead of testing one by one.

Resolves: #158

tests/test_stasis_endpoints.c

index 8408f364c3c748418bd5607d0ded8c0228913c92..3f4bee6d22647b9443fba490fdb7108ca11d71f9 100644 (file)
@@ -212,7 +212,11 @@ AST_TEST_DEFINE(channel_messages)
        struct stasis_message *msg;
        struct stasis_message_type *type;
        struct ast_endpoint_snapshot *actual_snapshot;
+       int expected_count;
        int actual_count;
+       int i;
+       int got_channel = 0;
+       int got_endpoint = 0;
 
        switch (cmd) {
        case TEST_INIT:
@@ -255,17 +259,22 @@ AST_TEST_DEFINE(channel_messages)
        ast_hangup(chan);
        chan = NULL;
 
-       actual_count = stasis_message_sink_wait_for_count(sink, 3,
+       expected_count = 3;
+       actual_count = stasis_message_sink_wait_for_count(sink, expected_count,
                STASIS_SINK_DEFAULT_WAIT);
-       ast_test_validate(test, 3 == actual_count);
-
-       msg = sink->messages[1];
-       type = stasis_message_type(msg);
-       ast_test_validate(test, ast_channel_snapshot_type() == type);
-
-       msg = sink->messages[2];
-       type = stasis_message_type(msg);
-       ast_test_validate(test, ast_endpoint_snapshot_type() == type);
+       ast_test_validate(test, expected_count == actual_count);
+
+       for (i = 0; i < expected_count; i++) {
+               msg = sink->messages[i];
+               type = stasis_message_type(msg);
+               if (type == ast_channel_snapshot_type()) {
+                       got_channel = 1;
+               }
+               if (type == ast_endpoint_snapshot_type()) {
+                       got_endpoint = 1;
+               }
+       }
+       ast_test_validate(test, got_channel && got_endpoint);
 
        actual_snapshot = stasis_message_data(msg);
        ast_test_validate(test, 0 == actual_snapshot->num_channels);