From b7775ae4e1410c51c606104175d75702d3857a2b Mon Sep 17 00:00:00 2001 From: George Joseph Date: Fri, 9 Jun 2023 10:41:13 -0600 Subject: [PATCH] test_stasis_endpoints.c: Make channel_messages more stable 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 (cherry picked from commit 83781c23b9cdbba597c72662ab768ee96d063f23) --- tests/test_stasis_endpoints.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/test_stasis_endpoints.c b/tests/test_stasis_endpoints.c index 8408f364c3..3f4bee6d22 100644 --- a/tests/test_stasis_endpoints.c +++ b/tests/test_stasis_endpoints.c @@ -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); + ast_test_validate(test, expected_count == 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); + 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);