[asterisk-commits] dlee: branch dlee/stasis-http r382818 - /team/dlee/stasis-http/tests/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 11 16:51:51 CDT 2013


Author: dlee
Date: Mon Mar 11 16:51:48 2013
New Revision: 382818

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382818
Log:
Added cache_dump test, to help me figure out what the cache_dump is actually doing

Modified:
    team/dlee/stasis-http/tests/test_stasis.c

Modified: team/dlee/stasis-http/tests/test_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/tests/test_stasis.c?view=diff&rev=382818&r1=382817&r2=382818
==============================================================================
--- team/dlee/stasis-http/tests/test_stasis.c (original)
+++ team/dlee/stasis-http/tests/test_stasis.c Mon Mar 11 16:51:48 2013
@@ -564,7 +564,6 @@
 	RAII_VAR(struct stasis_message *, test_message1_clear, NULL, ao2_cleanup);
 	int actual_len;
 	struct stasis_cache_update *actual_update;
-	struct ao2_container *cache_dump;
 
 	switch (cmd) {
 	case TEST_INIT:
@@ -600,12 +599,6 @@
 	actual_len = consumer_wait_for(consumer, 2);
 	ast_test_validate(test, 2 == actual_len);
 
-	/* Dump the cache to ensure that it has the correct number of items in it */
-	cache_dump = stasis_cache_dump(caching_topic, NULL);
-	ast_test_validate(test, 2 == ao2_container_count(cache_dump));
-	ao2_ref(cache_dump, -1);
-	cache_dump = NULL;
-
 	/* Check for new snapshot messages */
 	ast_test_validate(test, stasis_cache_update() == stasis_message_type(consumer->messages_rxed[0]));
 	actual_update = stasis_message_data(consumer->messages_rxed[0]);
@@ -641,12 +634,6 @@
 	/* stasis_cache_get returned a ref, so unref test_message2_2 */
 	ao2_ref(test_message2_2, -1);
 
-	/* Dump the cache to ensure that it has the correct number of items in it */
-	cache_dump = stasis_cache_dump(caching_topic, NULL);
-	ast_test_validate(test, 2 == ao2_container_count(cache_dump));
-	ao2_ref(cache_dump, -1);
-	cache_dump = NULL;
-
 	/* Clear snapshot 1 */
 	test_message1_clear = stasis_cache_clear_create(cache_type, "1");
 	ast_test_validate(test, NULL != test_message1_clear);
@@ -661,20 +648,113 @@
 	ast_test_validate(test, NULL == actual_update->new_snapshot);
 	ast_test_validate(test, NULL == stasis_cache_get(caching_topic, cache_type, "1"));
 
-	/* Dump the cache to ensure that it has the correct number of items in it */
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(cache_dump)
+{
+	RAII_VAR(struct stasis_message_type *, cache_type, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_topic *, topic, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, stasis_caching_unsubscribe);
+	RAII_VAR(struct consumer *, consumer, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
+	RAII_VAR(struct stasis_message *, test_message1_1, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, test_message2_1, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, test_message2_2, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, test_message1_clear, NULL, ao2_cleanup);
+	RAII_VAR(struct ao2_container *, cache_dump, NULL, ao2_cleanup);
+	int actual_len;
+	struct ao2_iterator i;
+	void *obj;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = test_category;
+		info->summary = "Test passing messages through cache topic unscathed.";
+		info->description = "Test passing messages through cache topic unscathed.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	cache_type = stasis_message_type_create("Cacheable");
+	ast_test_validate(test, NULL != cache_type);
+	topic = stasis_topic_create("SomeTopic");
+	ast_test_validate(test, NULL != topic);
+	caching_topic = stasis_caching_topic_create(topic, cache_test_data_id);
+	ast_test_validate(test, NULL != caching_topic);
+	consumer = consumer_create(1);
+	ast_test_validate(test, NULL != consumer);
+	sub = stasis_subscribe(stasis_caching_get_topic(caching_topic), consumer_exec, consumer);
+	ast_test_validate(test, NULL != sub);
+	ao2_ref(consumer, +1);
+
+	test_message1_1 = cache_test_message_create(cache_type, "1", "1");
+	ast_test_validate(test, NULL != test_message1_1);
+	test_message2_1 = cache_test_message_create(cache_type, "2", "1");
+	ast_test_validate(test, NULL != test_message2_1);
+
+	/* Post a couple of snapshots */
+	stasis_publish(topic, test_message1_1);
+	stasis_publish(topic, test_message2_1);
+	actual_len = consumer_wait_for(consumer, 2);
+	ast_test_validate(test, 2 == actual_len);
+
+	/* Check the cache */
 	cache_dump = stasis_cache_dump(caching_topic, NULL);
+	ast_test_validate(test, NULL != cache_dump);
+	ast_test_validate(test, 2 == ao2_container_count(cache_dump));
+	i = ao2_iterator_init(cache_dump, 0);
+	while ((obj = ao2_iterator_next(&i))) {
+		RAII_VAR(struct stasis_message *, actual_cache_entry, obj, ao2_cleanup);
+		ast_test_validate(test, actual_cache_entry == test_message1_1 || actual_cache_entry == test_message2_1);
+	}
+
+	/* Update snapshot 2 */
+	test_message2_2 = cache_test_message_create(cache_type, "2", "2");
+	ast_test_validate(test, NULL != test_message2_2);
+	stasis_publish(topic, test_message2_2);
+
+	actual_len = consumer_wait_for(consumer, 3);
+	ast_test_validate(test, 3 == actual_len);
+
+	/* Check the cache */
+	cache_dump = stasis_cache_dump(caching_topic, NULL);
+	ast_test_validate(test, NULL != cache_dump);
+	ast_test_validate(test, 2 == ao2_container_count(cache_dump));
+	i = ao2_iterator_init(cache_dump, 0);
+	while ((obj = ao2_iterator_next(&i))) {
+		RAII_VAR(struct stasis_message *, actual_cache_entry, obj, ao2_cleanup);
+		ast_test_validate(test, actual_cache_entry == test_message1_1 || actual_cache_entry == test_message2_2);
+	}
+
+	/* Clear snapshot 1 */
+	test_message1_clear = stasis_cache_clear_create(cache_type, "1");
+	ast_test_validate(test, NULL != test_message1_clear);
+	stasis_publish(topic, test_message1_clear);
+
+	actual_len = consumer_wait_for(consumer, 4);
+	ast_test_validate(test, 4 == actual_len);
+
+	/* Check the cache */
+	cache_dump = stasis_cache_dump(caching_topic, NULL);
+	ast_test_validate(test, NULL != cache_dump);
 	ast_test_validate(test, 1 == ao2_container_count(cache_dump));
-	ao2_ref(cache_dump, -1);
-	cache_dump = NULL;
+	i = ao2_iterator_init(cache_dump, 0);
+	while ((obj = ao2_iterator_next(&i))) {
+		RAII_VAR(struct stasis_message *, actual_cache_entry, obj, ao2_cleanup);
+		ast_test_validate(test, actual_cache_entry == test_message2_2);
+	}
 
 	/* Dump the cache to ensure that it has no subscription change items in it since those aren't cached */
+	ao2_cleanup(cache_dump);
 	cache_dump = stasis_cache_dump(caching_topic, stasis_subscription_change());
 	ast_test_validate(test, 0 == ao2_container_count(cache_dump));
-	ao2_ref(cache_dump, -1);
-	cache_dump = NULL;
-
-	return AST_TEST_PASS;
-}
+
+	return AST_TEST_PASS;
+}
+
 
 static int unload_module(void)
 {
@@ -686,6 +766,7 @@
 	AST_TEST_UNREGISTER(forward);
 	AST_TEST_UNREGISTER(cache_passthrough);
 	AST_TEST_UNREGISTER(cache);
+	AST_TEST_UNREGISTER(cache_dump);
 	return 0;
 }
 
@@ -699,6 +780,7 @@
 	AST_TEST_REGISTER(forward);
 	AST_TEST_REGISTER(cache_passthrough);
 	AST_TEST_REGISTER(cache);
+	AST_TEST_REGISTER(cache_dump);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the asterisk-commits mailing list