summaryrefslogtreecommitdiff
path: root/tests/test_taskprocessor.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2012-11-17 21:48:59 +0000
committerMark Michelson <mmichelson@digium.com>2012-11-17 21:48:59 +0000
commitf209bc6f9dab88285751acc06002a75bb4d63fc8 (patch)
tree240bda7c5f8a1e665a5fb750aa8134ce4985410b /tests/test_taskprocessor.c
parentec68a156191e9d8d6c752b9232b46a29f90a5cbb (diff)
Change the default taskprocessor test so it will never hang forever.
Changes the ast_cond_wait() to an ast_cond_timedwait() so that if there is an issue, we'll never wait forever for the task to finish execution. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376411 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_taskprocessor.c')
-rw-r--r--tests/test_taskprocessor.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/test_taskprocessor.c b/tests/test_taskprocessor.c
index 2ad172f41..6a2755747 100644
--- a/tests/test_taskprocessor.c
+++ b/tests/test_taskprocessor.c
@@ -46,7 +46,7 @@ static int task(void *data)
{
struct task_data *task_data = data;
SCOPED_MUTEX(lock, &task_data->lock);
- task_data->task_complete = 1;
+ ++task_data->task_complete;
ast_cond_signal(&task_data->cond);
return 0;
}
@@ -55,7 +55,10 @@ AST_TEST_DEFINE(default_taskprocessor)
{
struct ast_taskprocessor *tps;
struct task_data task_data;
+ struct timeval start;
+ struct timespec ts;
enum ast_test_result_state res = AST_TEST_PASS;
+ int timedwait_res;
switch (cmd) {
case TEST_INIT:
@@ -76,6 +79,11 @@ AST_TEST_DEFINE(default_taskprocessor)
return AST_TEST_FAIL;
}
+ start = ast_tvnow();
+
+ ts.tv_sec = start.tv_sec + 30;
+ ts.tv_nsec = start.tv_usec * 1000;
+
ast_cond_init(&task_data.cond, NULL);
ast_mutex_init(&task_data.lock);
task_data.task_complete = 0;
@@ -83,7 +91,10 @@ AST_TEST_DEFINE(default_taskprocessor)
ast_taskprocessor_push(tps, task, &task_data);
ast_mutex_lock(&task_data.lock);
while (!task_data.task_complete) {
- ast_cond_wait(&task_data.cond, &task_data.lock);
+ timedwait_res = ast_cond_timedwait(&task_data.cond, &task_data.lock, &ts);
+ if (timedwait_res == ETIMEDOUT) {
+ break;
+ }
}
if (!task_data.task_complete) {