summaryrefslogtreecommitdiff
path: root/tests/test_taskprocessor.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2012-11-12 00:36:16 +0000
committerMark Michelson <mmichelson@digium.com>2012-11-12 00:36:16 +0000
commit426e8d145437b44e5e8ba0adbde19eae94d906e1 (patch)
tree44a55737d49533d71ac40cec0203f9d8459b5a06 /tests/test_taskprocessor.c
parent0874e3c825ece4331103441398b4d2db09b72a32 (diff)
Refine the taskprocessor listener test a bit more.
This makes it easier to follow and tests more thoroughly. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376140 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_taskprocessor.c')
-rw-r--r--tests/test_taskprocessor.c52
1 files changed, 44 insertions, 8 deletions
diff --git a/tests/test_taskprocessor.c b/tests/test_taskprocessor.c
index d33b45b7a..eebf3d0b3 100644
--- a/tests/test_taskprocessor.c
+++ b/tests/test_taskprocessor.c
@@ -102,6 +102,7 @@ test_end:
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 @@ static void test_task_pushed(struct ast_taskprocessor_listener *listener, int wa
{
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)
@@ -142,6 +146,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;
+}
+
AST_TEST_DEFINE(taskprocessor_listener)
{
struct ast_taskprocessor *tps;
@@ -174,23 +201,32 @@ AST_TEST_DEFINE(taskprocessor_listener)
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);
- 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);
+ if (check_stats(test, pvt, 2, 0, 1) < 0) {
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);
+ ast_taskprocessor_execute(tps);
+
+ if (check_stats(test, pvt, 2, 1, 1) < 0) {
res = AST_TEST_FAIL;
goto test_exit;
}