From d3377e46af5eee1fde31e50aaeeac9103d2f451a Mon Sep 17 00:00:00 2001 From: xiazhvera Date: Mon, 5 Jun 2023 10:29:40 -0700 Subject: [PATCH] Unit Test for #297 (#298) * update tests for unsubscribe crash * update comments --- tests/v3/topic_tree_test.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/v3/topic_tree_test.c b/tests/v3/topic_tree_test.c index 9858f934..8fabfa9f 100644 --- a/tests/v3/topic_tree_test.c +++ b/tests/v3/topic_tree_test.c @@ -141,6 +141,12 @@ static int s_mqtt_topic_tree_unsubscribe_fn(struct aws_allocator *allocator, voi ASSERT_SUCCESS(aws_mqtt_topic_tree_insert( &tree, topic_a_a_a, AWS_MQTT_QOS_AT_MOST_ONCE, &on_publish, s_string_clean_up, topic_a_a_a)); + /* At this moment, the topic_a_a was not inserted. Though the remove returns a success, the topic_a_a_a should still + * remained in the tree. + * The test is inspired by the ticket: https://github.com/awslabs/aws-crt-nodejs/issues/405. There was a crash when + * we unsubscribe from an unsubscribed parent topic. + * We fixed the issue in https://github.com/awslabs/aws-c-mqtt/pull/297 */ + ASSERT_SUCCESS(aws_mqtt_topic_tree_remove(&tree, &s_topic_a_a)); ASSERT_SUCCESS(aws_mqtt_topic_tree_remove(&tree, &s_topic_a_a_a)); /* Re-create, it was nuked by remove. */ topic_a_a_a = aws_string_new_from_array(allocator, s_topic_a_a_a.ptr, s_topic_a_a_a.len);