[asterisk-commits] dlee: branch dlee/ASTERISK-22243 r396333 - in /team/dlee/ASTERISK-22243: main...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 6 09:47:11 CDT 2013


Author: dlee
Date: Tue Aug  6 09:47:09 2013
New Revision: 396333

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396333
Log:
Comments, assertions, tests

Modified:
    team/dlee/ASTERISK-22243/main/stasis.c
    team/dlee/ASTERISK-22243/main/stasis_cache.c
    team/dlee/ASTERISK-22243/tests/test_stasis.c

Modified: team/dlee/ASTERISK-22243/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22243/main/stasis.c?view=diff&rev=396333&r1=396332&r2=396333
==============================================================================
--- team/dlee/ASTERISK-22243/main/stasis.c (original)
+++ team/dlee/ASTERISK-22243/main/stasis.c Tue Aug  6 09:47:09 2013
@@ -53,7 +53,7 @@
 /*! \internal */
 struct stasis_topic {
 	char *name;
-	/*! Variable length array of the subscribers (raw pointer to avoid cyclic references) */
+	/*! Variable length array of the subscribers. */
 	struct stasis_subscription **subscribers;
 	/*! Allocated length of the subscribers array */
 	size_t num_subscribers_max;
@@ -67,6 +67,11 @@
 static void topic_dtor(void *obj)
 {
 	struct stasis_topic *topic = obj;
+
+	/* Subscribers hold a refernce to topics, so they should all be
+	 * unsubscribed before we get here.
+	 */
+	ast_assert(topic->num_subscribers_current == 0);
 	ast_free(topic->name);
 	topic->name = NULL;
 	ast_free(topic->subscribers);
@@ -131,8 +136,14 @@
 static void subscription_dtor(void *obj)
 {
 	struct stasis_subscription *sub = obj;
+
+	/* Subscriptions need to be manually unsubscribed before destruction
+	 * b/c there's a cyclic reference between topics and subscriptions */
 	ast_assert(!stasis_subscription_is_subscribed(sub));
+	/* If there are any messages in flight to this subscription; that would
+	 * be bad. */
 	ast_assert(stasis_subscription_is_done(sub));
+
 	ao2_cleanup(sub->topic);
 	sub->topic = NULL;
 	ast_taskprocessor_unreference(sub->mailbox);

Modified: team/dlee/ASTERISK-22243/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22243/main/stasis_cache.c?view=diff&rev=396333&r1=396332&r2=396333
==============================================================================
--- team/dlee/ASTERISK-22243/main/stasis_cache.c (original)
+++ team/dlee/ASTERISK-22243/main/stasis_cache.c Tue Aug  6 09:47:09 2013
@@ -59,8 +59,14 @@
 
 static void stasis_caching_topic_dtor(void *obj) {
 	struct stasis_caching_topic *caching_topic = obj;
+
+	/* Caching topics contain subscriptions, and must be manually
+	 * unsubscribed. */
 	ast_assert(!stasis_subscription_is_subscribed(caching_topic->sub));
+	/* If there are any messages in flight to this subscription; that would
+	 * be bad. */
 	ast_assert(stasis_subscription_is_done(caching_topic->sub));
+
 	ao2_cleanup(caching_topic->sub);
 	caching_topic->sub = NULL;
 	ao2_cleanup(caching_topic->cache);

Modified: team/dlee/ASTERISK-22243/tests/test_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22243/tests/test_stasis.c?view=diff&rev=396333&r1=396332&r2=396333
==============================================================================
--- team/dlee/ASTERISK-22243/tests/test_stasis.c (original)
+++ team/dlee/ASTERISK-22243/tests/test_stasis.c Tue Aug  6 09:47:09 2013
@@ -1279,6 +1279,97 @@
 	return AST_TEST_PASS;
 }
 
+static void noop(void *data, struct stasis_subscription *sub,
+	struct stasis_topic *topic, struct stasis_message *message)
+{
+	/* no-op */
+}
+
+AST_TEST_DEFINE(dtor_order)
+{
+	RAII_VAR(struct stasis_topic *, topic, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = test_category;
+		info->summary = "Test that destruction order doesn't bomb stuff";
+		info->description = "Test that destruction order doesn't bomb stuff";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	topic = stasis_topic_create("test-topic");
+	ast_test_validate(test, NULL != topic);
+
+	sub = stasis_subscribe(topic, noop, NULL);
+	ast_test_validate(test, NULL != sub);
+
+	/* With any luck, this won't completely blow everything up */
+	ao2_cleanup(topic);
+	stasis_unsubscribe(sub);
+
+	/* These refs were cleaned up manually */
+	topic = NULL;
+	sub = NULL;
+
+	return AST_TEST_PASS;
+}
+
+static const char *noop_get_id(struct stasis_message *message)
+{
+	return NULL;
+}
+
+AST_TEST_DEFINE(caching_dtor_order)
+{
+	RAII_VAR(struct stasis_topic *, topic, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_cache *, cache, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL,
+		stasis_caching_unsubscribe);
+	RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = test_category;
+		info->summary = "Test that destruction order doesn't bomb stuff";
+		info->description = "Test that destruction order doesn't bomb stuff";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	cache = stasis_cache_create(noop_get_id);
+	ast_test_validate(test, NULL != cache);
+
+	topic = stasis_topic_create("test-topic");
+	ast_test_validate(test, NULL != topic);
+
+	caching_topic = stasis_caching_topic_create(topic, cache);
+	ast_test_validate(test, NULL != caching_topic);
+
+	sub = stasis_subscribe(stasis_caching_get_topic(caching_topic), noop,
+		NULL);
+	ast_test_validate(test, NULL != sub);
+
+	/* With any luck, this won't completely blow everything up */
+	ao2_cleanup(cache);
+	ao2_cleanup(topic);
+	stasis_caching_unsubscribe(caching_topic);
+	stasis_unsubscribe(sub);
+
+	/* These refs were cleaned up manually */
+	cache = NULL;
+	topic = NULL;
+	caching_topic = NULL;
+	sub = NULL;
+
+	return AST_TEST_PASS;
+}
+
 static int unload_module(void)
 {
 	AST_TEST_UNREGISTER(message_type);
@@ -1298,6 +1389,8 @@
 	AST_TEST_UNREGISTER(to_json);
 	AST_TEST_UNREGISTER(no_to_ami);
 	AST_TEST_UNREGISTER(to_ami);
+	AST_TEST_UNREGISTER(dtor_order);
+	AST_TEST_UNREGISTER(caching_dtor_order);
 	return 0;
 }
 
@@ -1320,6 +1413,8 @@
 	AST_TEST_REGISTER(to_json);
 	AST_TEST_REGISTER(no_to_ami);
 	AST_TEST_REGISTER(to_ami);
+	AST_TEST_REGISTER(dtor_order);
+	AST_TEST_REGISTER(caching_dtor_order);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the asterisk-commits mailing list