diff options
author | Matthew Jordan <mjordan@digium.com> | 2014-12-04 15:48:26 +0000 |
---|---|---|
committer | Matthew Jordan <mjordan@digium.com> | 2014-12-04 15:48:26 +0000 |
commit | 343a83d7d87f9090ed6a3003ff752208545c884e (patch) | |
tree | a3a729207991ad737307f7f37fe4ca0b476b62c0 /main/test.c | |
parent | 7cb2c446b43381d78befb5bd16c364bce38e1fca (diff) |
main/test: Fix race condition between AMI topic and Test Suite topic
This patch fixes a race condition between the raising of test AMI events (which
drive many tests in the Asterisk Test Suite) and other AMI events. Prior to
this patch, the Stasis messages published to the test topic were not forwarded
to the AMI topic. Instead, the code in manager had a dedicated handler for test
messages that was independent of the topics forwarded to the AMI topic. This
results in no synchronization between the test messages and the rest of the
Stasis messages published out over AMI. In some test with very tight timing
constraints, this can result in out of order messages and spurious test
failures. Properly forwarding the Test Suite topic to the AMI topic ensures
that the messages are synchronized properly.
This patch does that, and moves the message handling to the Stasis definition
of the Test Suite message in test.c as well.
Review: https://reviewboard.asterisk.org/r/4221/
........
Merged revisions 428945 from http://svn.asterisk.org/svn/asterisk/branches/12
........
Merged revisions 428946 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@428947 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/test.c')
-rw-r--r-- | main/test.c | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/main/test.c b/main/test.c index c144d3eb4..1ad7b238c 100644 --- a/main/test.c +++ b/main/test.c @@ -56,11 +56,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$"); */ struct stasis_topic *test_suite_topic; -/*! \since 12 - * \brief The message type for test suite messages - */ -STASIS_MESSAGE_TYPE_DEFN(ast_test_suite_message_type); - /*! This array corresponds to the values defined in the ast_test_state enum */ static const char * const test_result2str[] = { [AST_TEST_NOT_RUN] = "NOT RUN", @@ -1012,6 +1007,51 @@ struct ast_json *ast_test_suite_get_blob(struct ast_test_suite_message_payload * return payload->blob; } +static struct ast_manager_event_blob *test_suite_event_to_ami(struct stasis_message *msg) +{ + RAII_VAR(struct ast_str *, packet_string, ast_str_create(128), ast_free); + struct ast_test_suite_message_payload *payload; + struct ast_json *blob; + const char *type; + + payload = stasis_message_data(msg); + if (!payload) { + return NULL; + } + blob = ast_test_suite_get_blob(payload); + if (!blob) { + return NULL; + } + + type = ast_json_string_get(ast_json_object_get(blob, "type")); + if (ast_strlen_zero(type) || strcmp("testevent", type)) { + return NULL; + } + + ast_str_append(&packet_string, 0, "Type: StateChange\r\n"); + ast_str_append(&packet_string, 0, "State: %s\r\n", + ast_json_string_get(ast_json_object_get(blob, "state"))); + ast_str_append(&packet_string, 0, "AppFile: %s\r\n", + ast_json_string_get(ast_json_object_get(blob, "appfile"))); + ast_str_append(&packet_string, 0, "AppFunction: %s\r\n", + ast_json_string_get(ast_json_object_get(blob, "appfunction"))); + ast_str_append(&packet_string, 0, "AppLine: %ld\r\n", + ast_json_integer_get(ast_json_object_get(blob, "line"))); + ast_str_append(&packet_string, 0, "%s\r\n", + ast_json_string_get(ast_json_object_get(blob, "data"))); + + return ast_manager_event_blob_create(EVENT_FLAG_REPORTING, + "TestEvent", + "%s", + ast_str_buffer(packet_string)); +} + +/*! \since 12 + * \brief The message type for test suite messages + */ +STASIS_MESSAGE_TYPE_DEFN(ast_test_suite_message_type, + .to_ami = test_suite_event_to_ami); + void __ast_test_suite_event_notify(const char *file, const char *func, int line, const char *state, const char *fmt, ...) { RAII_VAR(struct ast_test_suite_message_payload *, payload, |