summaryrefslogtreecommitdiff
path: root/tests/test_taskprocessor.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2012-12-07 00:30:35 +0000
committerMark Michelson <mmichelson@digium.com>2012-12-07 00:30:35 +0000
commit4590bfd93d7124fbd042f17260738e315e0abb6e (patch)
tree1579fa64689d9d5da754444e4ba41a9bc6c3f4a4 /tests/test_taskprocessor.c
parent62981d203221541829b7d6165e2127ca9a29efd4 (diff)
Add new threadpool test and fix some taskprocessor bugs.
The new thread creation test fails because Asterisk locks up while trying to lock a taskprocessor. While trying to debug that, I found a race condition during taskprocessor creation where a default taskprocessor listener could try to operate on a partially started taskprocessor. This was fixed by adding a new callback to taskprocessor listeners. Then while testing that change, I found some bugs in the taskprocessor tests where I was not properly unlocking when done with a lock. Scoped locks have spoiled me a bit. I still have not figured out why the threadpool thread creation test is locking up. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377368 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_taskprocessor.c')
-rw-r--r--tests/test_taskprocessor.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/test_taskprocessor.c b/tests/test_taskprocessor.c
index cbab754a9..377a2b3e3 100644
--- a/tests/test_taskprocessor.c
+++ b/tests/test_taskprocessor.c
@@ -116,6 +116,7 @@ AST_TEST_DEFINE(default_taskprocessor)
break;
}
}
+ ast_mutex_unlock(&task_data.lock);
if (!task_data.task_complete) {
ast_test_status_update(test, "Queued task did not execute!\n");
@@ -218,6 +219,7 @@ AST_TEST_DEFINE(default_taskprocessor_load)
break;
}
}
+ ast_mutex_unlock(&load_task_results.lock);
if (load_task_results.tasks_completed != NUM_TASKS) {
ast_test_status_update(test, "Unexpected number of tasks executed. Expected %d but got %d\n",
@@ -267,6 +269,14 @@ static void *test_alloc(struct ast_taskprocessor_listener *listener)
}
/*!
+ * \brief test taskprocessor listener's start callback
+ */
+static int test_start(struct ast_taskprocessor_listener *listener)
+{
+ return 0;
+}
+
+/*!
* \brief test taskprocessor listener's task_pushed callback
*
* Adjusts private data's stats as indicated by the parameters.
@@ -309,6 +319,7 @@ static void test_destroy(void *private_data)
static const struct ast_taskprocessor_listener_callbacks test_callbacks = {
.alloc = test_alloc,
+ .start = test_start,
.task_pushed = test_task_pushed,
.emptied = test_emptied,
.shutdown = test_shutdown,