diff options
author | Sree Kuchibhotla <sreek@google.com> | 2017-02-02 09:39:07 -0800 |
---|---|---|
committer | Sree Kuchibhotla <sreek@google.com> | 2017-02-02 09:39:07 -0800 |
commit | 6613168ad609c0cfe7651fb33e8fbc0f1638dbb7 (patch) | |
tree | 933b58629efafa521100c505084dedc05f5651eb /test | |
parent | 5862f76bd14be059b1ffcd27d72548adede7e7b3 (diff) | |
parent | 26623b3d77ae78e66f66b996593acf57a7cf1197 (diff) |
Merge branch 'master' into pollset_set_test
Diffstat (limited to 'test')
27 files changed, 485 insertions, 73 deletions
diff --git a/test/core/census/data/context_full.pb b/test/core/census/data/context_full.pb Binary files differindex 80ebcf280b..7b5895cbf1 100644 --- a/test/core/census/data/context_full.pb +++ b/test/core/census/data/context_full.pb diff --git a/test/core/census/data/context_full.txt b/test/core/census/data/context_full.txt index 7901a10c33..7d8df37ea1 100644 --- a/test/core/census/data/context_full.txt +++ b/test/core/census/data/context_full.txt @@ -1,3 +1,4 @@ -trace_id { hi : 5; lo : 1 } +trace_id_hi : 5 +trace_id_lo : 1 span_id : 7 -is_sampled : true +span_options : 1 diff --git a/test/core/census/data/context_no_sample.pb b/test/core/census/data/context_no_sample.pb Binary files differdeleted file mode 100644 index ab7ad7d109..0000000000 --- a/test/core/census/data/context_no_sample.pb +++ /dev/null diff --git a/test/core/census/data/context_no_sample.txt b/test/core/census/data/context_no_sample.txt deleted file mode 100644 index 150298002f..0000000000 --- a/test/core/census/data/context_no_sample.txt +++ /dev/null @@ -1,2 +0,0 @@ -trace_id { hi : 5; lo : 1 } -span_id : 7 diff --git a/test/core/census/data/context_no_span_options.pb b/test/core/census/data/context_no_span_options.pb Binary files differnew file mode 100644 index 0000000000..4b3425ac01 --- /dev/null +++ b/test/core/census/data/context_no_span_options.pb diff --git a/test/core/census/data/context_no_span_options.txt b/test/core/census/data/context_no_span_options.txt new file mode 100644 index 0000000000..4c8398ffd0 --- /dev/null +++ b/test/core/census/data/context_no_span_options.txt @@ -0,0 +1,3 @@ +trace_id_hi : 5 +trace_id_lo : 1 +span_id : 7 diff --git a/test/core/census/data/context_span_only.pb b/test/core/census/data/context_span_only.pb Binary files differindex 2a9527a75a..a9315be91a 100644 --- a/test/core/census/data/context_span_only.pb +++ b/test/core/census/data/context_span_only.pb diff --git a/test/core/census/data/context_span_only.txt b/test/core/census/data/context_span_only.txt index d90de2e614..4e473fce53 100644 --- a/test/core/census/data/context_span_only.txt +++ b/test/core/census/data/context_span_only.txt @@ -1,2 +1,2 @@ span_id : 7 -is_sampled : true +span_options : 1 diff --git a/test/core/census/data/context_trace_only.pb b/test/core/census/data/context_trace_only.pb Binary files differindex 7fdf6f61a3..aabb325f92 100644 --- a/test/core/census/data/context_trace_only.pb +++ b/test/core/census/data/context_trace_only.pb diff --git a/test/core/census/data/context_trace_only.txt b/test/core/census/data/context_trace_only.txt index 9b68a6aa92..e48a6d7457 100644 --- a/test/core/census/data/context_trace_only.txt +++ b/test/core/census/data/context_trace_only.txt @@ -1,2 +1,3 @@ -trace_id { hi : 5; lo : 1 } -is_sampled : true +trace_id_hi : 5 +trace_id_lo : 1 +span_options : 1 diff --git a/test/core/census/trace_context_test.c b/test/core/census/trace_context_test.c index ee409e8d1a..5963b1a246 100644 --- a/test/core/census/trace_context_test.c +++ b/test/core/census/trace_context_test.c @@ -59,7 +59,6 @@ bool validate_encode_decode_context(google_trace_TraceContext *ctxt1, uint8_t *buffer, size_t buf_size) { google_trace_TraceContext ctxt2 = google_trace_TraceContext_init_zero; size_t msg_length; - GPR_ASSERT(ctxt1->has_trace_id && ctxt1->has_span_id); msg_length = encode_trace_context(ctxt1, buffer, buf_size); if (msg_length == 0) { @@ -70,16 +69,17 @@ bool validate_encode_decode_context(google_trace_TraceContext *ctxt1, return false; } - if (!ctxt2.has_trace_id || !ctxt2.has_span_id) { + if (!ctxt2.has_trace_id_hi || !ctxt2.has_trace_id_lo || !ctxt2.has_span_id) { return false; } - GPR_ASSERT( - ctxt1->trace_id.hi == ctxt2.trace_id.hi && - ctxt1->trace_id.lo == ctxt2.trace_id.lo && - ctxt1->span_id == ctxt2.span_id && - ctxt1->has_is_sampled == ctxt2.has_is_sampled && - (ctxt1->has_is_sampled ? ctxt1->is_sampled == ctxt2.is_sampled : true)); + GPR_ASSERT(ctxt1->trace_id_hi == ctxt2.trace_id_hi && + ctxt1->trace_id_lo == ctxt2.trace_id_lo && + ctxt1->span_id == ctxt2.span_id && + ctxt1->has_span_options == ctxt2.has_span_options && + (ctxt1->has_span_options + ? ctxt1->span_options == ctxt2.span_options + : true)); return true; } @@ -94,7 +94,7 @@ bool validate_decode_context(google_trace_TraceContext *ctxt, uint8_t *buffer, return false; } - if (!ctxt->has_trace_id || !ctxt->has_span_id) { + if (!ctxt->has_trace_id_hi || !ctxt->has_trace_id_lo || !ctxt->has_span_id) { return false; } @@ -144,49 +144,48 @@ static void test_span_only() { &ctxt, "test/core/census/data/context_span_only.pb", false); } -// Test proto-buffer without is_sampled value. -static void test_no_sample() { +// Test proto-buffer without span_options value. +static void test_no_span_options() { google_trace_TraceContext ctxt = google_trace_TraceContext_init_zero; read_and_validate_context_from_file( - &ctxt, "test/core/census/data/context_no_sample.pb", true); - GPR_ASSERT(ctxt.has_is_sampled == false && ctxt.is_sampled == false); + &ctxt, "test/core/census/data/context_no_span_options.pb", true); + GPR_ASSERT(ctxt.has_span_options == false && ctxt.span_options == 0); } static void test_encode_decode() { uint8_t buffer[BUF_SIZE] = {0}; google_trace_TraceContext ctxt1 = google_trace_TraceContext_init_zero; - ctxt1.has_trace_id = true; - ctxt1.trace_id.has_hi = true; - ctxt1.trace_id.has_lo = true; - ctxt1.trace_id.lo = 1; - ctxt1.trace_id.hi = 2; + ctxt1.has_trace_id_hi = true; + ctxt1.has_trace_id_lo = true; + ctxt1.trace_id_lo = 1; + ctxt1.trace_id_hi = 2; ctxt1.has_span_id = true; ctxt1.span_id = 3; validate_encode_decode_context(&ctxt1, buffer, sizeof(buffer)); + // Missing trace_id. This should fail. google_trace_TraceContext ctxt2 = google_trace_TraceContext_init_zero; - ctxt2.has_trace_id = true; - ctxt2.trace_id.has_hi = false; - ctxt2.trace_id.has_lo = false; + ctxt2.has_trace_id_hi = false; + ctxt2.has_trace_id_lo = false; ctxt2.has_span_id = true; validate_encode_decode_context(&ctxt2, buffer, sizeof(buffer)); } -// Test a corrupted proto-buffer. +// Test a corrupted proto-buffer. This should fail. static void test_corrupt() { uint8_t buffer[BUF_SIZE] = {0}; google_trace_TraceContext ctxt1 = google_trace_TraceContext_init_zero; size_t msg_length; - ctxt1.has_trace_id = true; - ctxt1.trace_id.has_hi = true; - ctxt1.trace_id.has_lo = true; - ctxt1.trace_id.lo = 1; - ctxt1.trace_id.hi = 2; + ctxt1.has_trace_id_hi = true; + ctxt1.has_trace_id_lo = true; + ctxt1.trace_id_lo = 1; + ctxt1.trace_id_hi = 2; ctxt1.has_span_id = true; ctxt1.span_id = 3; - ctxt1.is_sampled = true; + ctxt1.has_span_options = true; + ctxt1.span_options = SPAN_OPTIONS_IS_SAMPLED; msg_length = encode_trace_context(&ctxt1, buffer, sizeof(buffer)); /* Corrupt some bytes. 255 (0xFF) should be illegal for the first byte of the @@ -198,19 +197,19 @@ static void test_corrupt() { } static void test_buffer_size() { - // This buffer is too small, so the encode should fail. + // This buffer is too small. This should fail. uint8_t buffer[16] = {0}; google_trace_TraceContext ctxt1 = google_trace_TraceContext_init_zero; size_t msg_length; - ctxt1.has_trace_id = true; - ctxt1.trace_id.has_hi = true; - ctxt1.trace_id.has_lo = true; - ctxt1.trace_id.lo = 1; - ctxt1.trace_id.hi = 2; + ctxt1.has_trace_id_hi = true; + ctxt1.has_trace_id_lo = true; + ctxt1.trace_id_lo = 1; + ctxt1.trace_id_hi = 2; ctxt1.has_span_id = true; ctxt1.span_id = 3; - ctxt1.is_sampled = true; + ctxt1.has_span_options = true; + ctxt1.span_options = SPAN_OPTIONS_IS_SAMPLED; msg_length = encode_trace_context(&ctxt1, buffer, sizeof(buffer)); GPR_ASSERT(msg_length == 0); @@ -224,7 +223,7 @@ int main(int argc, char **argv) { test_span_only(); test_encode_decode(); test_corrupt(); - test_no_sample(); + test_no_span_options(); test_buffer_size(); return 0; diff --git a/test/core/end2end/data/ssl_test_data.h b/test/core/end2end/data/ssl_test_data.h index 4a64af1e27..0b274e0d95 100644 --- a/test/core/end2end/data/ssl_test_data.h +++ b/test/core/end2end/data/ssl_test_data.h @@ -34,6 +34,10 @@ #ifndef GRPC_TEST_CORE_END2END_DATA_SSL_TEST_DATA_H #define GRPC_TEST_CORE_END2END_DATA_SSL_TEST_DATA_H +#ifdef __cplusplus +extern "C" { +#endif + extern const char test_root_cert[]; extern const char test_server1_cert[]; extern const char test_server1_key[]; @@ -42,4 +46,8 @@ extern const char test_self_signed_client_key[]; extern const char test_signed_client_cert[]; extern const char test_signed_client_key[]; +#ifdef __cplusplus +} +#endif + #endif /* GRPC_TEST_CORE_END2END_DATA_SSL_TEST_DATA_H */ diff --git a/test/core/end2end/tests/max_concurrent_streams.c b/test/core/end2end/tests/max_concurrent_streams.c index bd2d69513b..e81a628944 100644 --- a/test/core/end2end/tests/max_concurrent_streams.c +++ b/test/core/end2end/tests/max_concurrent_streams.c @@ -447,7 +447,395 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { config.tear_down_data(&f); } +static void test_max_concurrent_streams_with_timeout_on_first( + 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; + cq_verifier *cqv; + 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; + grpc_slice details1 = grpc_empty_slice(); + grpc_status_code status2; + grpc_slice details2 = grpc_empty_slice(); + grpc_op ops[6]; + grpc_op *op; + int was_cancelled; + + 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_with_timeout_on_first", + 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(config, f); + /* perform another one to make sure that the one stream case still works */ + simple_request_body(config, f); + + /* start two requests - ensuring that the second is not accepted until + the first completes */ + c1 = grpc_channel_create_call( + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/alpha"), + get_host_override_slice("foo.test.google.fr:1234", config), + n_seconds_time(3), NULL); + GPR_ASSERT(c1); + c2 = grpc_channel_create_call( + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/beta"), + get_host_override_slice("foo.test.google.fr:1234", config), + n_seconds_time(1000), 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))); + + memset(ops, 0, sizeof(ops)); + 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); + + memset(ops, 0, sizeof(ops)); + 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->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.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); + + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + CQ_EXPECT_COMPLETION(cqv, tag(301), 1); + cq_verify(cqv); + + memset(ops, 0, sizeof(ops)); + 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); + + memset(ops, 0, sizeof(ops)); + 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->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = + &initial_metadata_recv2; + 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); + + grpc_call_details_destroy(&call_details); + grpc_call_details_init(&call_details); + 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(302), 1); + /* first request is finished, we should be able to start the second */ + CQ_EXPECT_COMPLETION(cqv, tag(401), 1); + CQ_EXPECT_COMPLETION(cqv, tag(201), 1); + cq_verify(cqv); + + memset(ops, 0, sizeof(ops)); + 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; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; + 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(402), 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); + + grpc_slice_unref(details1); + grpc_slice_unref(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_with_timeout_on_second( + 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; + cq_verifier *cqv; + 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; + grpc_slice details1 = grpc_empty_slice(); + grpc_status_code status2; + grpc_slice details2 = grpc_empty_slice(); + grpc_op ops[6]; + grpc_op *op; + int was_cancelled; + + 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_with_timeout_on_second", + 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(config, f); + /* perform another one to make sure that the one stream case still works */ + simple_request_body(config, f); + + /* start two requests - ensuring that the second is not accepted until + the first completes , and the second request will timeout in the + concurrent_list */ + c1 = grpc_channel_create_call( + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/alpha"), + get_host_override_slice("foo.test.google.fr:1234", config), + n_seconds_time(1000), NULL); + GPR_ASSERT(c1); + c2 = grpc_channel_create_call( + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/beta"), + get_host_override_slice("foo.test.google.fr:1234", config), + n_seconds_time(3), 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))); + + memset(ops, 0, sizeof(ops)); + 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); + + memset(ops, 0, sizeof(ops)); + 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->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.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); + + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + CQ_EXPECT_COMPLETION(cqv, tag(301), 1); + cq_verify(cqv); + + memset(ops, 0, sizeof(ops)); + 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); + + memset(ops, 0, sizeof(ops)); + 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->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = + &initial_metadata_recv2; + 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); + + /* the second request is time out*/ + CQ_EXPECT_COMPLETION(cqv, tag(401), 0); + CQ_EXPECT_COMPLETION(cqv, tag(402), 1); + cq_verify(cqv); + + /* second request is finished because of time out, so destroy the second call + */ + grpc_call_destroy(c2); + + /* now reply the first call */ + memset(ops, 0, sizeof(ops)); + 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; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; + 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(302), 1); + CQ_EXPECT_COMPLETION(cqv, tag(102), 1); + cq_verify(cqv); + + cq_verifier_destroy(cqv); + + grpc_call_destroy(c1); + grpc_call_destroy(s1); + + grpc_slice_unref(details1); + grpc_slice_unref(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); +} + void max_concurrent_streams(grpc_end2end_test_config config) { + test_max_concurrent_streams_with_timeout_on_first(config); + test_max_concurrent_streams_with_timeout_on_second(config); test_max_concurrent_streams(config); } diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index f53601297c..32e8a41795 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -42,6 +42,7 @@ #include <grpc++/server_builder.h> #include <grpc++/server_context.h> #include <grpc/grpc.h> +#include <grpc/support/log.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> #include <grpc/support/tls.h> diff --git a/test/cpp/grpclb/grpclb_api_test.cc b/test/cpp/grpclb/grpclb_api_test.cc index 191d729a9e..82ccf436f8 100644 --- a/test/cpp/grpclb/grpclb_api_test.cc +++ b/test/cpp/grpclb/grpclb_api_test.cc @@ -63,7 +63,7 @@ grpc::string PackedStringToIp(const grpc_grpclb_ip_address& pb_ip) { } else { abort(); } - GPR_ASSERT(inet_ntop(af, pb_ip.bytes, ip_str, 46) != NULL); + GPR_ASSERT(inet_ntop(af, (void*)pb_ip.bytes, ip_str, 46) != NULL); return ip_str; } diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 1df2fc8320..8a00b61cef 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -34,8 +34,6 @@ #include <memory> #include <unordered_map> -#include <unistd.h> - #include <gflags/gflags.h> #include <grpc++/channel.h> #include <grpc++/client_context.h> diff --git a/test/cpp/interop/client_helper.cc b/test/cpp/interop/client_helper.cc index 91564e5dce..d3192ad0c9 100644 --- a/test/cpp/interop/client_helper.cc +++ b/test/cpp/interop/client_helper.cc @@ -33,8 +33,6 @@ #include "test/cpp/interop/client_helper.h" -#include <unistd.h> - #include <fstream> #include <memory> #include <sstream> diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index aa34d94f61..b7f2723c39 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -31,7 +31,6 @@ * */ -#include <unistd.h> #include <cinttypes> #include <fstream> #include <memory> @@ -43,6 +42,7 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> +#include <grpc/support/time.h> #include <grpc/support/useful.h> #include "src/core/lib/transport/byte_stream.h" @@ -618,7 +618,9 @@ bool InteropClient::DoResponseStreamingWithSlowConsumer() { GPR_ASSERT(response.payload().body() == grpc::string(kResponseMessageSize, '\0')); gpr_log(GPR_DEBUG, "received message %d", i); - usleep(kReceiveDelayMilliSeconds * 1000); + gpr_sleep_until(gpr_time_add( + gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_millis(kReceiveDelayMilliSeconds, GPR_TIMESPAN))); ++i; } diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 1810cd076f..77e309dde4 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -31,8 +31,6 @@ * */ -#include <unistd.h> - #include <fstream> #include <memory> #include <sstream> @@ -45,6 +43,7 @@ #include <grpc++/server_context.h> #include <grpc/grpc.h> #include <grpc/support/log.h> +#include <grpc/support/time.h> #include <grpc/support/useful.h> #include "src/core/lib/support/string.h" @@ -348,6 +347,7 @@ void grpc::testing::interop::RunServer( std::unique_ptr<Server> server(builder.BuildAndStart()); gpr_log(GPR_INFO, "Server listening on %s", server_address.str().c_str()); while (!gpr_atm_no_barrier_load(&g_got_sigint)) { - sleep(5); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(5, GPR_TIMESPAN))); } } diff --git a/test/cpp/interop/interop_server_bootstrap.cc b/test/cpp/interop/interop_server_bootstrap.cc index 99518c6943..7cbf221a03 100644 --- a/test/cpp/interop/interop_server_bootstrap.cc +++ b/test/cpp/interop/interop_server_bootstrap.cc @@ -32,7 +32,6 @@ */ #include <signal.h> -#include <unistd.h> #include "test/cpp/interop/server_helper.h" #include "test/cpp/util/test_config.h" diff --git a/test/cpp/interop/reconnect_interop_server.cc b/test/cpp/interop/reconnect_interop_server.cc index 53d51e80e7..634d0a90fc 100644 --- a/test/cpp/interop/reconnect_interop_server.cc +++ b/test/cpp/interop/reconnect_interop_server.cc @@ -34,7 +34,6 @@ // Test description at doc/connection-backoff-interop-test-description.md #include <signal.h> -#include <unistd.h> #include <condition_variable> #include <memory> diff --git a/test/cpp/qps/usage_timer.cc b/test/cpp/qps/usage_timer.cc index c6697fbdfd..70ef26e82a 100644 --- a/test/cpp/qps/usage_timer.cc +++ b/test/cpp/qps/usage_timer.cc @@ -39,8 +39,15 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> +#ifdef __linux__ #include <sys/resource.h> #include <sys/time.h> + +static double time_double(struct timeval* tv) { + return tv->tv_sec + 1e-6 * tv->tv_usec; +} +#endif + UsageTimer::UsageTimer() : start_(Sample()) {} double UsageTimer::Now() { @@ -48,8 +55,16 @@ double UsageTimer::Now() { return ts.tv_sec + 1e-9 * ts.tv_nsec; } -static double time_double(struct timeval* tv) { - return tv->tv_sec + 1e-6 * tv->tv_usec; +static void get_resource_usage(double* utime, double* stime) { +#ifdef __linux__ + struct rusage usage; + getrusage(RUSAGE_SELF, &usage); + *utime = time_double(&usage.ru_utime); + *stime = time_double(&usage.ru_stime); +#else + *utime = 0; + *stime = 0; +#endif } static void get_cpu_usage(unsigned long long* total_cpu_time, @@ -74,15 +89,9 @@ static void get_cpu_usage(unsigned long long* total_cpu_time, } UsageTimer::Result UsageTimer::Sample() { - struct rusage usage; - struct timeval tv; - gettimeofday(&tv, NULL); - getrusage(RUSAGE_SELF, &usage); - Result r; - r.wall = time_double(&tv); - r.user = time_double(&usage.ru_utime); - r.system = time_double(&usage.ru_stime); + r.wall = Now(); + get_resource_usage(&r.user, &r.system); r.total_cpu_time = 0; r.idle_cpu_time = 0; get_cpu_usage(&r.total_cpu_time, &r.idle_cpu_time); diff --git a/test/cpp/qps/worker.cc b/test/cpp/qps/worker.cc index 2068b7c213..e88d0647dd 100644 --- a/test/cpp/qps/worker.cc +++ b/test/cpp/qps/worker.cc @@ -31,7 +31,7 @@ * */ -#include <sys/signal.h> +#include <signal.h> #include <chrono> #include <thread> diff --git a/test/cpp/thread_manager/thread_manager_test.cc b/test/cpp/thread_manager/thread_manager_test.cc index 284761c53a..35c8d5d088 100644 --- a/test/cpp/thread_manager/thread_manager_test.cc +++ b/test/cpp/thread_manager/thread_manager_test.cc @@ -31,6 +31,7 @@ *is % allowed in string */ +#include <ctime> #include <memory> #include <string> diff --git a/test/cpp/util/cli_call.cc b/test/cpp/util/cli_call.cc index 4d045da098..041cc0e4c3 100644 --- a/test/cpp/util/cli_call.cc +++ b/test/cpp/util/cli_call.cc @@ -111,7 +111,7 @@ bool CliCall::Read(grpc::string* response, return false; } std::vector<grpc::Slice> slices; - recv_buffer.Dump(&slices); + GPR_ASSERT(recv_buffer.Dump(&slices).ok()); response->clear(); for (size_t i = 0; i < slices.size(); i++) { @@ -196,7 +196,7 @@ bool CliCall::ReadAndMaybeNotifyWrite( } std::vector<grpc::Slice> slices; - recv_buffer.Dump(&slices); + GPR_ASSERT(recv_buffer.Dump(&slices).ok()); response->clear(); for (size_t i = 0; i < slices.size(); i++) { response->append(reinterpret_cast<const char*>(slices[i].begin()), diff --git a/test/cpp/util/grpc_tool.cc b/test/cpp/util/grpc_tool.cc index 39acd8eb4b..856cd32c3c 100644 --- a/test/cpp/util/grpc_tool.cc +++ b/test/cpp/util/grpc_tool.cc @@ -33,7 +33,7 @@ #include "test/cpp/util/grpc_tool.h" -#include <unistd.h> +#include <cstdio> #include <fstream> #include <iostream> #include <memory> @@ -48,12 +48,19 @@ #include <grpc++/security/credentials.h> #include <grpc++/support/string_ref.h> #include <grpc/grpc.h> +#include <grpc/support/port_platform.h> #include "test/cpp/util/cli_call.h" #include "test/cpp/util/proto_file_parser.h" #include "test/cpp/util/proto_reflection_descriptor_database.h" #include "test/cpp/util/service_describer.h" +#if GPR_WINDOWS +#include <io.h> +#else +#include <unistd.h> +#endif + namespace grpc { namespace testing { @@ -484,7 +491,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv, CliCall call(channel, formatted_method_name, client_metadata); if (FLAGS_infile.empty()) { - if (isatty(STDIN_FILENO)) { + if (isatty(fileno(stdin))) { print_mode = true; fprintf(stderr, "reading streaming request message from stdin...\n"); } @@ -566,7 +573,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv, } else { std::stringstream input_stream; if (FLAGS_infile.empty()) { - if (isatty(STDIN_FILENO)) { + if (isatty(fileno(stdin))) { fprintf(stderr, "reading request message from stdin...\n"); } input_stream << std::cin.rdbuf(); @@ -668,7 +675,7 @@ bool GrpcTool::ParseMessage(int argc, const char** argv, } else { std::stringstream input_stream; if (FLAGS_infile.empty()) { - if (isatty(STDIN_FILENO)) { + if (isatty(fileno(stdin))) { fprintf(stderr, "reading request message from stdin...\n"); } input_stream << std::cin.rdbuf(); diff --git a/test/cpp/util/proto_file_parser.cc b/test/cpp/util/proto_file_parser.cc index d501c3697b..5dd1b00e8a 100644 --- a/test/cpp/util/proto_file_parser.cc +++ b/test/cpp/util/proto_file_parser.cc @@ -83,7 +83,7 @@ ProtoFileParser::ProtoFileParser(std::shared_ptr<grpc::Channel> channel, const grpc::string& protofiles) : has_error_(false), dynamic_factory_(new protobuf::DynamicMessageFactory()) { - std::vector<std::string> service_list; + std::vector<grpc::string> service_list; if (channel) { reflection_db_.reset(new grpc::ProtoReflectionDescriptorDatabase(channel)); reflection_db_->GetServices(&service_list); |