diff options
author | Mark Michelson <mmichelson@digium.com> | 2012-11-17 21:55:42 +0000 |
---|---|---|
committer | Mark Michelson <mmichelson@digium.com> | 2012-11-17 21:55:42 +0000 |
commit | da0e2169ded72ce3a6172f7c67cc35b8b8a45bd7 (patch) | |
tree | 99ed076d6583efe844c7eb83f2dbcabfa85e88d3 /tests/test_taskprocessor.c | |
parent | f209bc6f9dab88285751acc06002a75bb4d63fc8 (diff) |
Add a second default taskprocessor test that executes 20000 tasks.
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376412 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_taskprocessor.c')
-rw-r--r-- | tests/test_taskprocessor.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/test_taskprocessor.c b/tests/test_taskprocessor.c index 6a2755747..b9f40f18b 100644 --- a/tests/test_taskprocessor.c +++ b/tests/test_taskprocessor.c @@ -110,6 +110,71 @@ test_end: return res; } +AST_TEST_DEFINE(default_taskprocessor_load) +{ + static const int NUM_TASKS = 20000; + 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; + int i; + + switch (cmd) { + case TEST_INIT: + info->name = "default_taskprocessor_load"; + info->category = "/main/taskprocessor/"; + info->summary = "Load test of default taskproccesor"; + info->description = + "Ensure that many queued tasks are executed."; + return AST_TEST_NOT_RUN; + case TEST_EXECUTE: + break; + } + + tps = ast_taskprocessor_get("test", TPS_REF_DEFAULT); + + if (!tps) { + ast_test_status_update(test, "Unable to create test taskprocessor\n"); + return AST_TEST_FAIL; + } + + start = ast_tvnow(); + + ts.tv_sec = start.tv_sec + 60; + 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; + + for (i = 0; i < NUM_TASKS; ++i) { + ast_taskprocessor_push(tps, task, &task_data); + } + + ast_mutex_lock(&task_data.lock); + while (task_data.task_complete < NUM_TASKS) { + timedwait_res = ast_cond_timedwait(&task_data.cond, &task_data.lock, &ts); + if (timedwait_res == ETIMEDOUT) { + break; + } + } + + if (task_data.task_complete != NUM_TASKS) { + ast_test_status_update(test, "Unexpected number of tasks executed. Expected %d but got %d\n", + NUM_TASKS, task_data.task_complete); + res = AST_TEST_FAIL; + goto test_end; + } + +test_end: + tps = ast_taskprocessor_unreference(tps); + ast_mutex_destroy(&task_data.lock); + ast_cond_destroy(&task_data.cond); + return res; +} + struct test_listener_pvt { int num_pushed; int num_emptied; @@ -267,6 +332,7 @@ test_exit: static int unload_module(void) { ast_test_unregister(default_taskprocessor); + ast_test_unregister(default_taskprocessor_load); ast_test_unregister(taskprocessor_listener); return 0; } @@ -274,6 +340,7 @@ static int unload_module(void) static int load_module(void) { ast_test_register(default_taskprocessor); + ast_test_register(default_taskprocessor_load); ast_test_register(taskprocessor_listener); return AST_MODULE_LOAD_SUCCESS; } |