mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-23 14:44:28 +00:00
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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
ast_taskprocessor_push(tps, listener_test_task, NULL);
|
||||
ast_taskprocessor_push(tps, listener_test_task, NULL);
|
||||
|
||||
ast_taskprocessor_execute(tps);
|
||||
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);
|
||||
|
||||
ast_taskprocessor_push(tps, listener_test_task, NULL);
|
||||
|
||||
if (check_stats(test, pvt, 1, 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_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);
|
||||
|
||||
if (check_stats(test, pvt, 2, 1, 1) < 0) {
|
||||
res = AST_TEST_FAIL;
|
||||
goto test_exit;
|
||||
}
|
||||
|
Reference in New Issue
Block a user