예제 #1
0
int main(int argc, char **argv) {
  grpc_closure destroyed;
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
  gpr_subprocess *server;
  char *me = argv[0];
  char *lslash = strrchr(me, '/');
  char *args[5];
  int port = grpc_pick_unused_port_or_die();

  GPR_ASSERT(argc <= 2);
  if (argc == 2) {
    args[0] = gpr_strdup(argv[1]);
  } else {
    /* figure out where we are */
    char *root;
    if (lslash) {
      root = gpr_malloc((size_t)(lslash - me + 1));
      memcpy(root, me, (size_t)(lslash - me));
      root[lslash - me] = 0;
    } else {
      root = gpr_strdup(".");
    }
    gpr_asprintf(&args[0], "%s/../../test/core/httpcli/test_server.py", root);
    gpr_free(root);
  }

  /* start the server */
  args[1] = "--port";
  gpr_asprintf(&args[2], "%d", port);
  args[3] = "--ssl";
  server = gpr_subprocess_create(4, (const char **)args);
  GPR_ASSERT(server);
  gpr_free(args[0]);
  gpr_free(args[2]);

  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_init(&g_pollset);

  test_get(port);
  test_post(port);

  grpc_httpcli_context_destroy(&g_context);
  grpc_closure_init(&destroyed, destroy_pollset, &g_pollset);
  grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed);
  grpc_exec_ctx_finish(&exec_ctx);
  grpc_shutdown();

  gpr_subprocess_destroy(server);

  return 0;
}
int main() {
    try {
        //auto start = std::chrono::system_clock::now();
        test_get();
        test_post();
        test_put();
        test_delete();
        test_connectfail();
        //auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start);
        //std::cout << elapsed.count() << std::endl;
    } catch (const std::exception& e) {
        std::cout << e.what() << std::endl;
        return 1;
    }
    return 0;
}
예제 #3
0
int main() {
    test_get();
    test_post();
    return 0;
}