[asterisk-commits] mmichelson: branch mmichelson/threadpool r376140 - /team/mmichelson/threadpoo...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Nov 11 18:36:20 CST 2012


Author: mmichelson
Date: Sun Nov 11 18:36:16 2012
New Revision: 376140

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376140
Log:
Refine the taskprocessor listener test a bit more.

This makes it easier to follow and tests more thoroughly.


Modified:
    team/mmichelson/threadpool/tests/test_taskprocessor.c

Modified: team/mmichelson/threadpool/tests/test_taskprocessor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/tests/test_taskprocessor.c?view=diff&rev=376140&r1=376139&r2=376140
==============================================================================
--- team/mmichelson/threadpool/tests/test_taskprocessor.c (original)
+++ team/mmichelson/threadpool/tests/test_taskprocessor.c Sun Nov 11 18:36:16 2012
@@ -102,6 +102,7 @@
 struct test_listener_pvt {
 	int num_pushed;
 	int num_emptied;
+	int num_was_empty;
 };
 
 static void *test_alloc(struct ast_taskprocessor_listener *listener)
@@ -116,6 +117,9 @@
 {
 	struct test_listener_pvt *pvt = listener->private_data;
 	++pvt->num_pushed;
+	if (was_empty) {
+		++pvt->num_was_empty;
+	}
 }
 
 static void test_emptied(struct ast_taskprocessor_listener *listener)
@@ -139,6 +143,29 @@
 
 static int listener_test_task(void *ignore)
 {
+	return 0;
+}
+
+static int check_stats(struct ast_test *test, const struct test_listener_pvt *pvt, int num_pushed, int num_emptied, int num_was_empty)
+{
+	if (pvt->num_pushed != num_pushed) {
+		ast_test_status_update(test, "Unexpected number of tasks pushed. Expected %d but got %d\n",
+				num_pushed, pvt->num_pushed);
+		return -1;
+	}
+
+	if (pvt->num_emptied != num_emptied) {
+		ast_test_status_update(test, "Unexpected number of empties. Expected %d but got %d\n",
+				num_emptied, pvt->num_emptied);
+		return -1;
+	}
+
+	if (pvt->num_was_empty != num_was_empty) {
+		ast_test_status_update(test, "Unexpected number of empties. Expected %d but got %d\n",
+				num_was_empty, pvt->num_emptied);
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -174,23 +201,32 @@
 		goto test_exit;
 	}
 
+	pvt = listener->private_data;
+
 	ast_taskprocessor_push(tps, listener_test_task, NULL);
+
+	if (check_stats(test, pvt, 1, 0, 1) < 0) {
+		res = AST_TEST_FAIL;
+		goto test_exit;
+	}
+
 	ast_taskprocessor_push(tps, listener_test_task, NULL);
 
+	if (check_stats(test, pvt, 2, 0, 1) < 0) {
+		res = AST_TEST_FAIL;
+		goto test_exit;
+	}
+
 	ast_taskprocessor_execute(tps);
+
+	if (check_stats(test, pvt, 2, 0, 1) < 0) {
+		res = AST_TEST_FAIL;
+		goto test_exit;
+	}
+
 	ast_taskprocessor_execute(tps);
 
-	pvt = listener->private_data;
-	if (pvt->num_pushed != 2) {
-		ast_test_status_update(test, "Unexpected number of tasks pushed. Expected %d but got %d\n",
-				2, pvt->num_pushed);
-		res = AST_TEST_FAIL;
-		goto test_exit;
-	}
-
-	if (pvt->num_emptied != 1) {
-		ast_test_status_update(test, "Unexpected number of empties. Expected %d but got %d\n",
-				1, pvt->num_emptied);
+	if (check_stats(test, pvt, 2, 1, 1) < 0) {
 		res = AST_TEST_FAIL;
 		goto test_exit;
 	}




More information about the asterisk-commits mailing list