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
This commit is contained in:
George Joseph 2023-06-09 10:41:13 -06:00
parent fcaa1ba181
commit a5c4f3e567
1 changed files with 18 additions and 9 deletions

View 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);
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);