[asterisk-commits] dlee: branch dlee/performance r399641 - in /team/dlee/performance: include/as...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 23 12:26:53 CDT 2013


Author: dlee
Date: Mon Sep 23 12:26:51 2013
New Revision: 399641

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399641
Log:
Adjusted tests and comments for message router behavior change

Modified:
    team/dlee/performance/include/asterisk/stasis_message_router.h
    team/dlee/performance/main/stasis_message_router.c
    team/dlee/performance/tests/test_stasis.c

Modified: team/dlee/performance/include/asterisk/stasis_message_router.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/performance/include/asterisk/stasis_message_router.h?view=diff&rev=399641&r1=399640&r2=399641
==============================================================================
--- team/dlee/performance/include/asterisk/stasis_message_router.h (original)
+++ team/dlee/performance/include/asterisk/stasis_message_router.h Mon Sep 23 12:26:51 2013
@@ -100,6 +100,9 @@
  * updates for types not handled by routes added with
  * stasis_message_router_add_cache_update().
  *
+ * Adding multiple routes for the same message type results in undefined
+ * behavior.
+ *
  * \param router Router to add the route to.
  * \param message_type Type of message to route.
  * \param callback Callback to forard messages of \a message_type to.
@@ -120,6 +123,9 @@
  * A particular \a message_type may have at most one cache route per \a router.
  * These are distinct from regular routes, so one could have both a regular
  * route and a cache route for the same \a message_type.
+ *
+ * Adding multiple routes for the same message type results in undefined
+ * behavior.
  *
  * \param router Router to add the route to.
  * \param message_type Subtype of cache update to route.

Modified: team/dlee/performance/main/stasis_message_router.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/performance/main/stasis_message_router.c?view=diff&rev=399641&r1=399640&r2=399641
==============================================================================
--- team/dlee/performance/main/stasis_message_router.c (original)
+++ team/dlee/performance/main/stasis_message_router.c Mon Sep 23 12:26:51 2013
@@ -53,12 +53,28 @@
 	struct stasis_message_route routes[];
 };
 
+static int table_has_route(struct route_table *table,
+	struct stasis_message_type *message_type)
+{
+	size_t idx;
+
+	for (idx = 0; idx < table->current_size; ++idx) {
+		if (table->routes[idx].message_type == message_type) {
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
 static int table_add_route(struct route_table **table_ptr,
 	struct stasis_message_type *message_type,
 	stasis_subscription_cb callback, void *data)
 {
 	struct route_table *table = *table_ptr;
 	struct stasis_message_route *route;
+
+	ast_assert(!table_has_route(table, message_type));
 
 	if (table->current_size + 1 > table->max_size) {
 		size_t new_max_size = table->max_size ? table->max_size * 2 : 1;

Modified: team/dlee/performance/tests/test_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/performance/tests/test_stasis.c?view=diff&rev=399641&r1=399640&r2=399641
==============================================================================
--- team/dlee/performance/tests/test_stasis.c (original)
+++ team/dlee/performance/tests/test_stasis.c Mon Sep 23 12:26:51 2013
@@ -863,52 +863,6 @@
 	ao2_cleanup(cache_dump);
 	cache_dump = stasis_cache_dump(cache, stasis_subscription_change_type());
 	ast_test_validate(test, 0 == ao2_container_count(cache_dump));
-
-	return AST_TEST_PASS;
-}
-
-AST_TEST_DEFINE(route_conflicts)
-{
-	RAII_VAR(struct stasis_topic *, topic, NULL, ao2_cleanup);
-	RAII_VAR(struct stasis_message_router *, uut, NULL, stasis_message_router_unsubscribe_and_join);
-	RAII_VAR(struct stasis_message_type *, test_message_type, NULL, ao2_cleanup);
-	RAII_VAR(struct consumer *, consumer1, NULL, ao2_cleanup);
-	RAII_VAR(struct consumer *, consumer2, NULL, ao2_cleanup);
-	int ret;
-
-	switch (cmd) {
-	case TEST_INIT:
-		info->name = __func__;
-		info->category = test_category;
-		info->summary =
-			"Multiple routes to the same message_type should fail";
-		info->description =
-			"Multiple routes to the same message_type should fail";
-		return AST_TEST_NOT_RUN;
-	case TEST_EXECUTE:
-		break;
-	}
-
-	topic = stasis_topic_create("TestTopic");
-	ast_test_validate(test, NULL != topic);
-
-	consumer1 = consumer_create(1);
-	ast_test_validate(test, NULL != consumer1);
-	consumer2 = consumer_create(1);
-	ast_test_validate(test, NULL != consumer2);
-
-	test_message_type = stasis_message_type_create("TestMessage", NULL);
-	ast_test_validate(test, NULL != test_message_type);
-
-	uut = stasis_message_router_create(topic);
-	ast_test_validate(test, NULL != uut);
-
-	ret = stasis_message_router_add(
-		uut, test_message_type, consumer_exec, consumer1);
-	ast_test_validate(test, 0 == ret);
-	ret = stasis_message_router_add(
-		uut, test_message_type, consumer_exec, consumer2);
-	ast_test_validate(test, 0 != ret);
 
 	return AST_TEST_PASS;
 }
@@ -1373,7 +1327,6 @@
 	AST_TEST_UNREGISTER(cache_filter);
 	AST_TEST_UNREGISTER(cache);
 	AST_TEST_UNREGISTER(cache_dump);
-	AST_TEST_UNREGISTER(route_conflicts);
 	AST_TEST_UNREGISTER(router);
 	AST_TEST_UNREGISTER(router_cache_updates);
 	AST_TEST_UNREGISTER(interleaving);
@@ -1397,7 +1350,6 @@
 	AST_TEST_REGISTER(cache_filter);
 	AST_TEST_REGISTER(cache);
 	AST_TEST_REGISTER(cache_dump);
-	AST_TEST_REGISTER(route_conflicts);
 	AST_TEST_REGISTER(router);
 	AST_TEST_REGISTER(router_cache_updates);
 	AST_TEST_REGISTER(interleaving);




More information about the asterisk-commits mailing list