Example #1
0
static void test_invoke_10_simple_requests(grpc_end2end_test_config config,
                                           int initial_sequence_number) {
  int i;
  grpc_end2end_test_fixture f;
  grpc_arg client_arg;
  grpc_channel_args client_args;
  char *name;

  client_arg.type = GRPC_ARG_INTEGER;
  client_arg.key = GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER;
  client_arg.value.integer = initial_sequence_number;

  client_args.num_args = 1;
  client_args.args = &client_arg;

  gpr_asprintf(&name, "test_invoke_requests first_seqno=%d",
               initial_sequence_number);
  f = begin_test(config, name, &client_args, NULL);
  for (i = 0; i < 10; i++) {
    simple_request_body(f);
    gpr_log(GPR_INFO, "Passed simple request %d", i);
  }
  end_test(&f);
  config.tear_down_data(&f);
  gpr_free(name);
}
Example #2
0
static void test_size(grpc_end2end_test_config config, int encode_size,
                      int decode_size) {
  size_t i;
  grpc_end2end_test_fixture f;
  grpc_arg server_arg;
  grpc_channel_args server_args;
  grpc_arg client_arg;
  grpc_channel_args client_args;
  char *name;

  server_arg.type = GRPC_ARG_INTEGER;
  server_arg.key = GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER;
  server_arg.value.integer = decode_size;
  server_args.num_args = 1;
  server_args.args = &server_arg;

  client_arg.type = GRPC_ARG_INTEGER;
  client_arg.key = GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER;
  client_arg.value.integer = encode_size;
  client_args.num_args = 1;
  client_args.args = &client_arg;

  gpr_asprintf(&name, "test_size:e=%d:d=%d", encode_size, decode_size);
  f = begin_test(config, name, encode_size != 4096 ? &client_args : NULL,
                 decode_size != 4096 ? &server_args : NULL);
  for (i = 0; i < 4 * GPR_ARRAY_SIZE(hobbits); i++) {
    simple_request_body(config, f, i);
  }
  end_test(&f);
  config.tear_down_data(&f);
  gpr_free(name);
}
Example #3
0
static void test_invoke_simple_request(grpc_end2end_test_config config) {
  grpc_end2end_test_fixture f;

  f = begin_test(config, "test_invoke_simple_request", NULL, NULL);
  simple_request_body(f);
  end_test(&f);
  config.tear_down_data(&f);
}
Example #4
0
static void test_invoke_simple_request(grpc_end2end_test_config config) {
  grpc_end2end_test_fixture f =
      begin_test(config, "test_invoke_simple_request", NULL, NULL);
  void *rc = grpc_channel_register_call(f.client, "/foo",
                                        "foo.test.google.fr:1234", NULL);

  simple_request_body(f, rc);
  end_test(&f);
  config.tear_down_data(&f);
}
Example #5
0
static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {
  int i;
  grpc_end2end_test_fixture f =
      begin_test(config, "test_invoke_10_simple_requests", NULL, NULL);
  for (i = 0; i < 10; i++) {
    simple_request_body(f);
    gpr_log(GPR_INFO, "Passed simple request %d", i);
  }
  end_test(&f);
  config.tear_down_data(&f);
}
Example #6
0
static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {
  int i;
  grpc_end2end_test_fixture f =
      begin_test(config, "test_invoke_10_simple_requests", NULL, NULL);
  void *rc = grpc_channel_register_call(f.client, "/foo",
                                        "foo.test.google.fr:1234", NULL);

  for (i = 0; i < 10; i++) {
    simple_request_body(f, rc);
    gpr_log(GPR_INFO, "Passed simple request %d", i);
  }
  end_test(&f);
  config.tear_down_data(&f);
}
Example #7
0
int main(int argc, char **argv) {
  size_t i;
  FILE *roots_file;
  size_t roots_size = strlen(test_root_cert);
  char *roots_filename;

  grpc_test_init(argc, argv);
  grpc_end2end_tests_pre_init();

  /* Set the SSL roots env var. */
  roots_file =
      gpr_tmpfile("chttp2_simple_ssl_cert_fullstack_test", &roots_filename);
  GPR_ASSERT(roots_filename != NULL);
  GPR_ASSERT(roots_file != NULL);
  GPR_ASSERT(fwrite(test_root_cert, 1, roots_size, roots_file) == roots_size);
  fclose(roots_file);
  gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, roots_filename);

  grpc_init();

  for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
    grpc_end2end_test_fixture f =
        begin_test(configs[i].config, "SSL_CERT_tests", NULL, NULL);

    simple_request_body(f, configs[i].result);
    end_test(&f);
    configs[i].config.tear_down_data(&f);
  }

  grpc_shutdown();

  /* Cleanup. */
  remove(roots_filename);
  gpr_free(roots_filename);

  return 0;
}
Example #8
0
static void test_max_concurrent_streams(grpc_end2end_test_config config) {
  grpc_end2end_test_fixture f;
  grpc_arg server_arg;
  grpc_channel_args server_args;
  grpc_call *c1;
  grpc_call *c2;
  grpc_call *s1;
  grpc_call *s2;
  int live_call;
  gpr_timespec deadline;
  cq_verifier *cqv;
  grpc_event ev;
  grpc_call_details call_details;
  grpc_metadata_array request_metadata_recv;
  grpc_metadata_array initial_metadata_recv1;
  grpc_metadata_array trailing_metadata_recv1;
  grpc_metadata_array initial_metadata_recv2;
  grpc_metadata_array trailing_metadata_recv2;
  grpc_status_code status1;
  grpc_call_error error;
  char *details1 = NULL;
  size_t details_capacity1 = 0;
  grpc_status_code status2;
  char *details2 = NULL;
  size_t details_capacity2 = 0;
  grpc_op ops[6];
  grpc_op *op;
  int was_cancelled;
  int got_client_start;
  int got_server_start;

  server_arg.key = GRPC_ARG_MAX_CONCURRENT_STREAMS;
  server_arg.type = GRPC_ARG_INTEGER;
  server_arg.value.integer = 1;

  server_args.num_args = 1;
  server_args.args = &server_arg;

  f = begin_test(config, "test_max_concurrent_streams", NULL, &server_args);
  cqv = cq_verifier_create(f.cq);

  grpc_metadata_array_init(&request_metadata_recv);
  grpc_metadata_array_init(&initial_metadata_recv1);
  grpc_metadata_array_init(&trailing_metadata_recv1);
  grpc_metadata_array_init(&initial_metadata_recv2);
  grpc_metadata_array_init(&trailing_metadata_recv2);
  grpc_call_details_init(&call_details);

  /* perform a ping-pong to ensure that settings have had a chance to round
     trip */
  simple_request_body(f);
  /* perform another one to make sure that the one stream case still works */
  simple_request_body(f);

  /* start two requests - ensuring that the second is not accepted until
     the first completes */
  deadline = n_seconds_time(1000);
  c1 = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
                                "/alpha", "foo.test.google.fr:1234", deadline,
                                NULL);
  GPR_ASSERT(c1);
  c2 = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
                                "/beta", "foo.test.google.fr:1234", deadline,
                                NULL);
  GPR_ASSERT(c2);

  GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
                                 f.server, &s1, &call_details,
                                 &request_metadata_recv, f.cq, f.cq, tag(101)));

  op = ops;
  op->op = GRPC_OP_SEND_INITIAL_METADATA;
  op->data.send_initial_metadata.count = 0;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(301), NULL);
  GPR_ASSERT(GRPC_CALL_OK == error);

  op = ops;
  op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
  op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv1;
  op->data.recv_status_on_client.status = &status1;
  op->data.recv_status_on_client.status_details = &details1;
  op->data.recv_status_on_client.status_details_capacity = &details_capacity1;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_RECV_INITIAL_METADATA;
  op->data.recv_initial_metadata = &initial_metadata_recv1;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(302), NULL);
  GPR_ASSERT(GRPC_CALL_OK == error);

  op = ops;
  op->op = GRPC_OP_SEND_INITIAL_METADATA;
  op->data.send_initial_metadata.count = 0;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(401), NULL);
  GPR_ASSERT(GRPC_CALL_OK == error);

  op = ops;
  op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
  op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv2;
  op->data.recv_status_on_client.status = &status2;
  op->data.recv_status_on_client.status_details = &details2;
  op->data.recv_status_on_client.status_details_capacity = &details_capacity2;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_RECV_INITIAL_METADATA;
  op->data.recv_initial_metadata = &initial_metadata_recv1;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(402), NULL);
  GPR_ASSERT(GRPC_CALL_OK == error);

  got_client_start = 0;
  got_server_start = 0;
  live_call = -1;
  while (!got_client_start || !got_server_start) {
    ev = grpc_completion_queue_next(f.cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3),
                                    NULL);
    GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
    GPR_ASSERT(ev.success);
    if (ev.tag == tag(101)) {
      GPR_ASSERT(!got_server_start);
      got_server_start = 1;
    } else {
      GPR_ASSERT(!got_client_start);
      GPR_ASSERT(ev.tag == tag(301) || ev.tag == tag(401));
      /* The /alpha or /beta calls started above could be invoked (but NOT
       * both);
       * check this here */
      /* We'll get tag 303 or 403, we want 300, 400 */
      live_call = ((int)(intptr_t)ev.tag) - 1;
      got_client_start = 1;
    }
  }
  GPR_ASSERT(live_call == 300 || live_call == 400);

  op = ops;
  op->op = GRPC_OP_SEND_INITIAL_METADATA;
  op->data.send_initial_metadata.count = 0;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
  op->data.recv_close_on_server.cancelled = &was_cancelled;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
  op->data.send_status_from_server.trailing_metadata_count = 0;
  op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
  op->data.send_status_from_server.status_details = "xyz";
  op->flags = 0;
  op->reserved = NULL;
  op++;
  error = grpc_call_start_batch(s1, ops, (size_t)(op - ops), tag(102), NULL);
  GPR_ASSERT(GRPC_CALL_OK == error);

  cq_expect_completion(cqv, tag(102), 1);
  cq_expect_completion(cqv, tag(live_call + 2), 1);
  /* first request is finished, we should be able to start the second */
  live_call = (live_call == 300) ? 400 : 300;
  cq_expect_completion(cqv, tag(live_call + 1), 1);
  cq_verify(cqv);

  GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
                                 f.server, &s2, &call_details,
                                 &request_metadata_recv, f.cq, f.cq, tag(201)));
  cq_expect_completion(cqv, tag(201), 1);
  cq_verify(cqv);

  op = ops;
  op->op = GRPC_OP_SEND_INITIAL_METADATA;
  op->data.send_initial_metadata.count = 0;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
  op->data.recv_close_on_server.cancelled = &was_cancelled;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
  op->data.send_status_from_server.trailing_metadata_count = 0;
  op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
  op->data.send_status_from_server.status_details = "xyz";
  op->flags = 0;
  op->reserved = NULL;
  op++;
  error = grpc_call_start_batch(s2, ops, (size_t)(op - ops), tag(202), NULL);
  GPR_ASSERT(GRPC_CALL_OK == error);

  cq_expect_completion(cqv, tag(live_call + 2), 1);
  cq_expect_completion(cqv, tag(202), 1);
  cq_verify(cqv);

  cq_verifier_destroy(cqv);

  grpc_call_destroy(c1);
  grpc_call_destroy(s1);
  grpc_call_destroy(c2);
  grpc_call_destroy(s2);

  gpr_free(details1);
  gpr_free(details2);
  grpc_metadata_array_destroy(&initial_metadata_recv1);
  grpc_metadata_array_destroy(&trailing_metadata_recv1);
  grpc_metadata_array_destroy(&initial_metadata_recv2);
  grpc_metadata_array_destroy(&trailing_metadata_recv2);
  grpc_metadata_array_destroy(&request_metadata_recv);
  grpc_call_details_destroy(&call_details);

  end_test(&f);
  config.tear_down_data(&f);
}
static void test_max_concurrent_streams(grpc_end2end_test_config config) {
  grpc_end2end_test_fixture f;
  grpc_arg server_arg;
  grpc_channel_args server_args;
  grpc_call *c1;
  grpc_call *c2;
  grpc_call *s1;
  grpc_call *s2;
  int live_call;
  gpr_timespec deadline;
  cq_verifier *v_client;
  cq_verifier *v_server;
  grpc_event *ev;

  server_arg.key = GRPC_ARG_MAX_CONCURRENT_STREAMS;
  server_arg.type = GRPC_ARG_INTEGER;
  server_arg.value.integer = 1;

  server_args.num_args = 1;
  server_args.args = &server_arg;

  f = begin_test(config, __FUNCTION__, NULL, &server_args);
  v_client = cq_verifier_create(f.client_cq);
  v_server = cq_verifier_create(f.server_cq);

  /* perform a ping-pong to ensure that settings have had a chance to round
     trip */
  simple_request_body(f);
  /* perform another one to make sure that the one stream case still works */
  simple_request_body(f);

  /* start two requests - ensuring that the second is not accepted until
     the first completes */
  deadline = five_seconds_time();
  c1 = grpc_channel_create_call_old(f.client, "/alpha", "foo.test.google.fr",
                                    deadline);
  GPR_ASSERT(c1);
  c2 = grpc_channel_create_call_old(f.client, "/beta", "foo.test.google.fr",
                                    deadline);
  GPR_ASSERT(c1);

  GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));

  GPR_ASSERT(GRPC_CALL_OK ==
             grpc_call_invoke_old(c1, f.client_cq, tag(301), tag(302), 0));
  GPR_ASSERT(GRPC_CALL_OK ==
             grpc_call_invoke_old(c2, f.client_cq, tag(401), tag(402), 0));
  GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c1, tag(303)));
  GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c2, tag(403)));

  ev = grpc_completion_queue_next(
      f.client_cq, gpr_time_add(gpr_now(), gpr_time_from_seconds(10)));
  GPR_ASSERT(ev);
  GPR_ASSERT(ev->type == GRPC_FINISH_ACCEPTED);
  GPR_ASSERT(ev->data.invoke_accepted == GRPC_OP_OK);
  /* The /alpha or /beta calls started above could be invoked (but NOT both);
   * check this here */
  /* We'll get tag 303 or 403, we want 300, 400 */
  live_call = ((int)(gpr_intptr) ev->tag) - 3;
  grpc_event_finish(ev);

  cq_expect_server_rpc_new(v_server, &s1, tag(100),
                           live_call == 300 ? "/alpha" : "/beta",
                           "foo.test.google.fr", deadline, NULL);
  cq_verify(v_server);

  GPR_ASSERT(GRPC_CALL_OK ==
             grpc_call_server_accept_old(s1, f.server_cq, tag(102)));
  GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s1, 0));
  cq_expect_client_metadata_read(v_client, tag(live_call + 1), NULL);
  cq_verify(v_client);

  GPR_ASSERT(GRPC_CALL_OK ==
             grpc_call_start_write_status_old(s1, GRPC_STATUS_UNIMPLEMENTED,
                                              "xyz", tag(103)));
  cq_expect_finish_accepted(v_server, tag(103), GRPC_OP_OK);
  cq_expect_finished(v_server, tag(102), NULL);
  cq_verify(v_server);

  /* first request is finished, we should be able to start the second */
  cq_expect_finished_with_status(v_client, tag(live_call + 2),
                                 GRPC_STATUS_UNIMPLEMENTED, "xyz", NULL);
  live_call = (live_call == 300) ? 400 : 300;
  cq_expect_finish_accepted(v_client, tag(live_call + 3), GRPC_OP_OK);
  cq_verify(v_client);

  GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(200)));
  cq_expect_server_rpc_new(v_server, &s2, tag(200),
                           live_call == 300 ? "/alpha" : "/beta",
                           "foo.test.google.fr", deadline, NULL);
  cq_verify(v_server);

  GPR_ASSERT(GRPC_CALL_OK ==
             grpc_call_server_accept_old(s2, f.server_cq, tag(202)));
  GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s2, 0));
  cq_expect_client_metadata_read(v_client, tag(live_call + 1), NULL);
  cq_verify(v_client);

  GPR_ASSERT(GRPC_CALL_OK ==
             grpc_call_start_write_status_old(s2, GRPC_STATUS_UNIMPLEMENTED,
                                              "xyz", tag(203)));
  cq_expect_finish_accepted(v_server, tag(203), GRPC_OP_OK);
  cq_expect_finished(v_server, tag(202), NULL);
  cq_verify(v_server);

  cq_expect_finished_with_status(v_client, tag(live_call + 2),
                                 GRPC_STATUS_UNIMPLEMENTED, "xyz", NULL);
  cq_verify(v_client);

  cq_verifier_destroy(v_client);
  cq_verifier_destroy(v_server);

  grpc_call_destroy(c1);
  grpc_call_destroy(s1);
  grpc_call_destroy(c2);
  grpc_call_destroy(s2);

  end_test(&f);
  config.tear_down_data(&f);
}