aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/http/httpcli_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/http/httpcli_test.cc')
-rw-r--r--test/core/http/httpcli_test.cc107
1 files changed, 54 insertions, 53 deletions
diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc
index d354ad3570..ed5c03558f 100644
--- a/test/core/http/httpcli_test.cc
+++ b/test/core/http/httpcli_test.cc
@@ -141,62 +141,63 @@ static void destroy_pops(void* p, grpc_error* error) {
}
int main(int argc, char** argv) {
- grpc_closure destroyed;
- grpc_core::ExecCtx _local_exec_ctx;
gpr_subprocess* server;
- char* me = argv[0];
- char* lslash = strrchr(me, '/');
- char* args[4];
- int port = grpc_pick_unused_port_or_die();
- int arg_shift = 0;
- /* figure out where we are */
- char* root;
- if (lslash) {
- root = static_cast<char*>(gpr_malloc((size_t)(lslash - me + 1)));
- memcpy(root, me, (size_t)(lslash - me));
- root[lslash - me] = 0;
- } else {
- root = gpr_strdup(".");
- }
-
- GPR_ASSERT(argc <= 2);
- if (argc == 2) {
- args[0] = gpr_strdup(argv[1]);
- } else {
- arg_shift = 1;
- gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root);
- gpr_asprintf(&args[1], "%s/../../test/core/http/test_server.py", root);
- }
-
- /* start the server */
- args[1 + arg_shift] = const_cast<char*>("--port");
- gpr_asprintf(&args[2 + arg_shift], "%d", port);
- server = gpr_subprocess_create(3 + arg_shift, (const char**)args);
- GPR_ASSERT(server);
- gpr_free(args[0]);
- if (arg_shift) gpr_free(args[1]);
- gpr_free(args[2 + arg_shift]);
- gpr_free(root);
-
- gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_seconds(5, GPR_TIMESPAN)));
-
grpc_test_init(argc, argv);
grpc_init();
- grpc_httpcli_context_init(&g_context);
- grpc_pollset* pollset =
- static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
- grpc_pollset_init(pollset, &g_mu);
- g_pops = grpc_polling_entity_create_from_pollset(pollset);
-
- test_get(port);
- test_post(port);
-
- grpc_httpcli_context_destroy(&g_context);
- GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops,
- grpc_schedule_on_exec_ctx);
- grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed);
-
+ {
+ grpc_closure destroyed;
+ grpc_core::ExecCtx _local_exec_ctx;
+ char* me = argv[0];
+ char* lslash = strrchr(me, '/');
+ char* args[4];
+ int port = grpc_pick_unused_port_or_die();
+ int arg_shift = 0;
+ /* figure out where we are */
+ char* root;
+ if (lslash) {
+ root = static_cast<char*>(gpr_malloc((size_t)(lslash - me + 1)));
+ memcpy(root, me, (size_t)(lslash - me));
+ root[lslash - me] = 0;
+ } else {
+ root = gpr_strdup(".");
+ }
+
+ GPR_ASSERT(argc <= 2);
+ if (argc == 2) {
+ args[0] = gpr_strdup(argv[1]);
+ } else {
+ arg_shift = 1;
+ gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root);
+ gpr_asprintf(&args[1], "%s/../../test/core/http/test_server.py", root);
+ }
+
+ /* start the server */
+ args[1 + arg_shift] = const_cast<char*>("--port");
+ gpr_asprintf(&args[2 + arg_shift], "%d", port);
+ server = gpr_subprocess_create(3 + arg_shift, (const char**)args);
+ GPR_ASSERT(server);
+ gpr_free(args[0]);
+ if (arg_shift) gpr_free(args[1]);
+ gpr_free(args[2 + arg_shift]);
+ gpr_free(root);
+
+ gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_seconds(5, GPR_TIMESPAN)));
+
+ grpc_httpcli_context_init(&g_context);
+ grpc_pollset* pollset =
+ static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
+ grpc_pollset_init(pollset, &g_mu);
+ g_pops = grpc_polling_entity_create_from_pollset(pollset);
+
+ test_get(port);
+ test_post(port);
+
+ grpc_httpcli_context_destroy(&g_context);
+ GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops,
+ grpc_schedule_on_exec_ctx);
+ grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed);
+ }
grpc_shutdown();
gpr_free(grpc_polling_entity_pollset(&g_pops));