|
@@ -55,15 +55,34 @@ using namespace libtest;
|
|
|
#include <tests/workers.h>
|
|
|
#include <tests/start_worker.h>
|
|
|
|
|
|
-static std::string executable;
|
|
|
-
|
|
|
#define WORKER_FUNCTION_NAME "echo_function"
|
|
|
|
|
|
+namespace cli {
|
|
|
+
|
|
|
+struct Context
|
|
|
+{
|
|
|
+ server_startup_st& servers;
|
|
|
+ worker_handle_st *worker;
|
|
|
+
|
|
|
+ Context(server_startup_st& servers_arg,
|
|
|
+ worker_handle_st *worker_arg) :
|
|
|
+ servers(servers_arg),
|
|
|
+ worker(worker_arg)
|
|
|
+ { }
|
|
|
+
|
|
|
+ ~Context()
|
|
|
+ {
|
|
|
+ delete worker;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
static test_return_t gearman_help_test(void *)
|
|
|
{
|
|
|
const char *args[]= { "-H", 0 };
|
|
|
|
|
|
- test_compare(true, exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearman", args));
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -74,7 +93,7 @@ static test_return_t gearman_unknown_test(void *)
|
|
|
const char *args[]= { buffer, "--unknown", 0 };
|
|
|
|
|
|
// The argument doesn't exist, so we should see an error
|
|
|
- test_false(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_FAILURE, exec_cmdline("bin/gearman", args));
|
|
|
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
@@ -86,7 +105,7 @@ static test_return_t gearman_client_background_test(void *)
|
|
|
const char *args[]= { buffer, "-f", WORKER_FUNCTION_NAME, "-b", "payload", 0 };
|
|
|
|
|
|
// The argument doesn't exist, so we should see an error
|
|
|
- test_true(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearman", args));
|
|
|
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
@@ -100,10 +119,10 @@ static test_return_t regression_833394_test(void *)
|
|
|
const char *args[]= { buffer, "-f", REGRESSION_FUNCTION_833394, "-b", "payload", 0 };
|
|
|
|
|
|
gearman_function_t echo_react_fn_v2= gearman_function_create(echo_or_react_worker_v2);
|
|
|
- worker_handle_st *worker= test_worker_start(CLIENT_TEST_PORT, NULL, REGRESSION_FUNCTION_833394, echo_react_fn_v2, NULL, gearman_worker_options_t());
|
|
|
+ worker_handle_st *worker= test_worker_start(default_port(), NULL, REGRESSION_FUNCTION_833394, echo_react_fn_v2, NULL, gearman_worker_options_t());
|
|
|
|
|
|
// The argument doesn't exist, so we should see an error
|
|
|
- test_true(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearman", args));
|
|
|
|
|
|
delete worker;
|
|
|
|
|
@@ -116,21 +135,21 @@ static test_return_t gearadmin_help_test(void *)
|
|
|
snprintf(buffer, sizeof(buffer), "--port=%d", int(default_port()));
|
|
|
const char *args[]= { buffer, "--help", 0 };
|
|
|
|
|
|
- test_true(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", args));
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
|
|
|
|
static test_return_t gearadmin_shutdown_test(void *object)
|
|
|
{
|
|
|
- server_startup_st *servers= (server_startup_st *)object;
|
|
|
+ cli::Context *context= (cli::Context*)object;
|
|
|
|
|
|
char buffer[1024];
|
|
|
snprintf(buffer, sizeof(buffer), "--port=%d", int(default_port()));
|
|
|
const char *args[]= { buffer, "--shutdown", 0 };
|
|
|
|
|
|
- test_true(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", args));
|
|
|
|
|
|
- Server *server= servers->pop_server();
|
|
|
+ Server *server= context->servers.pop_server();
|
|
|
test_true(server);
|
|
|
while (server->ping())
|
|
|
{
|
|
@@ -150,7 +169,7 @@ static test_return_t gearadmin_version_test(void *)
|
|
|
snprintf(buffer, sizeof(buffer), "--port=%d", int(default_port()));
|
|
|
const char *args[]= { buffer, "--server-version", 0 };
|
|
|
|
|
|
- test_true(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", args));
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -160,7 +179,7 @@ static test_return_t gearadmin_verbose_test(void *)
|
|
|
snprintf(buffer, sizeof(buffer), "--port=%d", int(default_port()));
|
|
|
const char *args[]= { buffer, "--server-verbose", 0 };
|
|
|
|
|
|
- test_true(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", args));
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -170,7 +189,7 @@ static test_return_t gearadmin_status_test(void *)
|
|
|
snprintf(buffer, sizeof(buffer), "--port=%d", int(default_port()));
|
|
|
const char *args[]= { buffer, "--status", 0 };
|
|
|
|
|
|
- test_true(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", args));
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -180,7 +199,7 @@ static test_return_t gearadmin_workers_test(void *)
|
|
|
snprintf(buffer, sizeof(buffer), "--port=%d", int(default_port()));
|
|
|
const char *args[]= { buffer, "--workers", 0 };
|
|
|
|
|
|
- test_true(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", args));
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -190,10 +209,10 @@ static test_return_t gearadmin_create_drop_test(void *)
|
|
|
snprintf(buffer, sizeof(buffer), "--port=%d", int(default_port()));
|
|
|
|
|
|
const char *create_args[]= { buffer, "--create-function=test_function", 0 };
|
|
|
- test_true(exec_cmdline(executable, create_args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", create_args));
|
|
|
|
|
|
const char *drop_args[]= { buffer, "--drop-function=test_function", 0 };
|
|
|
- test_true(exec_cmdline(executable, drop_args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", drop_args));
|
|
|
|
|
|
|
|
|
return TEST_SUCCESS;
|
|
@@ -205,7 +224,7 @@ static test_return_t gearadmin_getpid_test(void *)
|
|
|
snprintf(buffer, sizeof(buffer), "--port=%d", int(default_port()));
|
|
|
const char *args[]= { buffer, "--getpid", 0 };
|
|
|
|
|
|
- test_true(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", args));
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -216,7 +235,7 @@ static test_return_t gearadmin_unknown_test(void *)
|
|
|
const char *args[]= { buffer, "--unknown", 0 };
|
|
|
|
|
|
// The argument doesn't exist, so we should see an error
|
|
|
- test_false(exec_cmdline(executable, args));
|
|
|
+ test_compare(EXIT_FAILURE, exec_cmdline("bin/gearadmin", args));
|
|
|
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
@@ -245,14 +264,9 @@ test_st gearadmin_tests[] ={
|
|
|
{0, 0, 0}
|
|
|
};
|
|
|
|
|
|
-static test_return_t pre_skip(void*)
|
|
|
-{
|
|
|
- return TEST_SKIPPED;
|
|
|
-}
|
|
|
-
|
|
|
collection_st collection[] ={
|
|
|
{"gearman", 0, 0, gearman_tests},
|
|
|
- {"gearadmin", pre_skip, 0, gearadmin_tests},
|
|
|
+ {"gearadmin", 0, 0, gearadmin_tests},
|
|
|
{0, 0, 0, 0}
|
|
|
};
|
|
|
|
|
@@ -266,15 +280,17 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
|
|
|
|
|
|
// Echo function
|
|
|
gearman_function_t echo_react_fn_v2= gearman_function_create(echo_or_react_worker_v2);
|
|
|
- worker_handle_st *worker= test_worker_start(CLIENT_TEST_PORT, NULL, WORKER_FUNCTION_NAME, echo_react_fn_v2, NULL, gearman_worker_options_t());
|
|
|
+ worker_handle_st *worker= test_worker_start(default_port(), NULL, WORKER_FUNCTION_NAME, echo_react_fn_v2, NULL, gearman_worker_options_t());
|
|
|
|
|
|
- return worker;
|
|
|
+ cli::Context *context= new cli::Context(servers, worker);
|
|
|
+
|
|
|
+ return context;
|
|
|
}
|
|
|
|
|
|
static bool world_destroy(void *object)
|
|
|
{
|
|
|
- worker_handle_st *worker= (worker_handle_st *)object;
|
|
|
- delete worker;
|
|
|
+ cli::Context *context= (cli::Context*)object;
|
|
|
+ delete context;
|
|
|
|
|
|
return TEST_SUCCESS;
|
|
|
}
|
|
@@ -282,7 +298,6 @@ static bool world_destroy(void *object)
|
|
|
|
|
|
void get_world(Framework *world)
|
|
|
{
|
|
|
- executable= "./bin/gearman";
|
|
|
world->collections= collection;
|
|
|
world->_create= world_create;
|
|
|
world->_destroy= world_destroy;
|