David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include "test/core/end2end/end2end_tests.h" |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include <grpc/byte_buffer.h> |
| 25 | #include <grpc/byte_buffer_reader.h> |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 26 | #include <grpc/compression.h> |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 27 | #include <grpc/support/alloc.h> |
| 28 | #include <grpc/support/log.h> |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 29 | #include <grpc/support/string_util.h> |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 30 | #include <grpc/support/time.h> |
| 31 | #include <grpc/support/useful.h> |
| 32 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 33 | #include "src/core/lib/channel/channel_args.h" |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 34 | #include "src/core/lib/surface/call.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 35 | #include "src/core/lib/surface/call_test_only.h" |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 36 | #include "src/core/lib/transport/static_metadata.h" |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 37 | #include "test/core/end2end/cq_verifier.h" |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 38 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 39 | static void* tag(intptr_t t) { return (void*)t; } |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 40 | |
| 41 | static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 42 | const char* test_name, |
| 43 | grpc_channel_args* client_args, |
| 44 | grpc_channel_args* server_args) { |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 45 | grpc_end2end_test_fixture f; |
Robbie Shade | 55a046a | 2017-01-25 15:14:28 -0500 | [diff] [blame] | 46 | gpr_log(GPR_INFO, "Running test: %s/%s", test_name, config.name); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 47 | f = config.create_fixture(client_args, server_args); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 48 | config.init_server(&f, server_args); |
Mark D. Roth | e127a39 | 2016-10-27 08:27:15 -0700 | [diff] [blame] | 49 | config.init_client(&f, client_args); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 50 | return f; |
| 51 | } |
| 52 | |
Chris Evans | ed2a547 | 2017-03-27 17:34:51 -0500 | [diff] [blame] | 53 | static gpr_timespec n_seconds_from_now(int n) { |
Robbie Shade | ca7effc | 2017-01-17 09:14:29 -0500 | [diff] [blame] | 54 | return grpc_timeout_seconds_to_deadline(n); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Chris Evans | ed2a547 | 2017-03-27 17:34:51 -0500 | [diff] [blame] | 57 | static gpr_timespec five_seconds_from_now(void) { |
| 58 | return n_seconds_from_now(5); |
| 59 | } |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 60 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 61 | static void drain_cq(grpc_completion_queue* cq) { |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 62 | grpc_event ev; |
| 63 | do { |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 64 | ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 65 | } while (ev.type != GRPC_QUEUE_SHUTDOWN); |
| 66 | } |
| 67 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 68 | static void shutdown_server(grpc_end2end_test_fixture* f) { |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 69 | if (!f->server) return; |
Sree Kuchibhotla | 321881d | 2017-02-27 11:25:28 -0800 | [diff] [blame] | 70 | grpc_server_shutdown_and_notify(f->server, f->shutdown_cq, tag(1000)); |
| 71 | GPR_ASSERT(grpc_completion_queue_pluck(f->shutdown_cq, tag(1000), |
| 72 | grpc_timeout_seconds_to_deadline(5), |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 73 | nullptr) |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 74 | .type == GRPC_OP_COMPLETE); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 75 | grpc_server_destroy(f->server); |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 76 | f->server = nullptr; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 79 | static void shutdown_client(grpc_end2end_test_fixture* f) { |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 80 | if (!f->client) return; |
| 81 | grpc_channel_destroy(f->client); |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 82 | f->client = nullptr; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 85 | static void end_test(grpc_end2end_test_fixture* f) { |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 86 | shutdown_server(f); |
| 87 | shutdown_client(f); |
| 88 | |
David Garcia Quintas | 92ce588 | 2015-06-23 17:07:12 -0700 | [diff] [blame] | 89 | grpc_completion_queue_shutdown(f->cq); |
| 90 | drain_cq(f->cq); |
| 91 | grpc_completion_queue_destroy(f->cq); |
Sree Kuchibhotla | 321881d | 2017-02-27 11:25:28 -0800 | [diff] [blame] | 92 | grpc_completion_queue_destroy(f->shutdown_cq); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 93 | } |
| 94 | |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 95 | static void request_for_disabled_algorithm( |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 96 | grpc_end2end_test_config config, const char* test_name, |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 97 | uint32_t send_flags_bitmask, |
| 98 | grpc_compression_algorithm algorithm_to_disable, |
| 99 | grpc_compression_algorithm requested_client_compression_algorithm, |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 100 | grpc_status_code expected_error, grpc_metadata* client_metadata) { |
| 101 | grpc_call* c; |
| 102 | grpc_call* s; |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 103 | grpc_slice request_payload_slice; |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 104 | grpc_byte_buffer* request_payload; |
| 105 | grpc_channel_args* client_args; |
| 106 | grpc_channel_args* server_args; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 107 | grpc_end2end_test_fixture f; |
| 108 | grpc_op ops[6]; |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 109 | grpc_op* op; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 110 | grpc_metadata_array initial_metadata_recv; |
| 111 | grpc_metadata_array trailing_metadata_recv; |
| 112 | grpc_metadata_array request_metadata_recv; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 113 | grpc_byte_buffer* request_payload_recv = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 114 | grpc_call_details call_details; |
| 115 | grpc_status_code status; |
| 116 | grpc_call_error error; |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 117 | grpc_slice details; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 118 | int was_cancelled = 2; |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 119 | cq_verifier* cqv; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 120 | char str[1024]; |
| 121 | |
| 122 | memset(str, 'x', 1023); |
| 123 | str[1023] = '\0'; |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 124 | request_payload_slice = grpc_slice_from_copied_string(str); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 125 | request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); |
| 126 | |
| 127 | client_args = grpc_channel_args_set_compression_algorithm( |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 128 | nullptr, requested_client_compression_algorithm); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 129 | server_args = |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 130 | grpc_channel_args_set_compression_algorithm(nullptr, GRPC_COMPRESS_NONE); |
Craig Tiller | 87a7e1f | 2016-11-09 09:42:19 -0800 | [diff] [blame] | 131 | { |
Yash Tibrewal | 8cf1470 | 2017-12-06 09:47:54 -0800 | [diff] [blame] | 132 | grpc_core::ExecCtx exec_ctx; |
Craig Tiller | 87a7e1f | 2016-11-09 09:42:19 -0800 | [diff] [blame] | 133 | server_args = grpc_channel_args_compression_algorithm_set_state( |
Yash Tibrewal | 8cf1470 | 2017-12-06 09:47:54 -0800 | [diff] [blame] | 134 | &server_args, algorithm_to_disable, false); |
Craig Tiller | 87a7e1f | 2016-11-09 09:42:19 -0800 | [diff] [blame] | 135 | } |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 136 | |
| 137 | f = begin_test(config, test_name, client_args, server_args); |
| 138 | cqv = cq_verifier_create(f.cq); |
| 139 | |
Chris Evans | ed2a547 | 2017-03-27 17:34:51 -0500 | [diff] [blame] | 140 | gpr_timespec deadline = five_seconds_from_now(); |
Muxi Yan | 5ebd327 | 2016-10-31 07:27:07 -0700 | [diff] [blame] | 141 | c = grpc_channel_create_call( |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 142 | f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq, |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 143 | grpc_slice_from_static_string("/foo"), |
| 144 | get_host_override_slice("foo.test.google.fr:1234", config), deadline, |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 145 | nullptr); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 146 | GPR_ASSERT(c); |
| 147 | |
| 148 | grpc_metadata_array_init(&initial_metadata_recv); |
| 149 | grpc_metadata_array_init(&trailing_metadata_recv); |
| 150 | grpc_metadata_array_init(&request_metadata_recv); |
| 151 | grpc_call_details_init(&call_details); |
| 152 | |
Muxi Yan | 4b527a7 | 2017-09-20 13:35:05 -0700 | [diff] [blame] | 153 | error = |
| 154 | grpc_server_request_call(f.server, &s, &call_details, |
| 155 | &request_metadata_recv, f.cq, f.cq, tag(101)); |
| 156 | GPR_ASSERT(GRPC_CALL_OK == error); |
| 157 | |
David Garcia Quintas | ac09447 | 2016-05-18 20:25:57 -0700 | [diff] [blame] | 158 | memset(ops, 0, sizeof(ops)); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 159 | op = ops; |
| 160 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 161 | if (client_metadata != nullptr) { |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 162 | op->data.send_initial_metadata.count = 1; |
| 163 | op->data.send_initial_metadata.metadata = client_metadata; |
| 164 | } else { |
| 165 | op->data.send_initial_metadata.count = 0; |
| 166 | } |
| 167 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 168 | op->reserved = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 169 | op++; |
| 170 | op->op = GRPC_OP_SEND_MESSAGE; |
Mark D. Roth | 435f9f2 | 2017-01-25 12:53:54 -0800 | [diff] [blame] | 171 | op->data.send_message.send_message = request_payload; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 172 | op->flags = send_flags_bitmask; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 173 | op->reserved = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 174 | op++; |
| 175 | op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; |
| 176 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 177 | op->reserved = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 178 | op++; |
| 179 | op->op = GRPC_OP_RECV_INITIAL_METADATA; |
Mark D. Roth | 435f9f2 | 2017-01-25 12:53:54 -0800 | [diff] [blame] | 180 | op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 181 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 182 | op->reserved = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 183 | op++; |
| 184 | op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
| 185 | op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; |
| 186 | op->data.recv_status_on_client.status = &status; |
| 187 | op->data.recv_status_on_client.status_details = &details; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 188 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 189 | op->reserved = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 190 | op++; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 191 | error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 192 | GPR_ASSERT(GRPC_CALL_OK == error); |
| 193 | |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 194 | CQ_EXPECT_COMPLETION(cqv, tag(101), true); |
Yash Tibrewal | bdf998a | 2017-09-27 17:07:43 -0700 | [diff] [blame] | 195 | CQ_EXPECT_COMPLETION(cqv, tag(1), true); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 196 | cq_verify(cqv); |
| 197 | |
| 198 | op = ops; |
| 199 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
| 200 | op->data.send_initial_metadata.count = 0; |
| 201 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 202 | op->reserved = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 203 | op++; |
| 204 | op->op = GRPC_OP_RECV_MESSAGE; |
Mark D. Roth | 435f9f2 | 2017-01-25 12:53:54 -0800 | [diff] [blame] | 205 | op->data.recv_message.recv_message = &request_payload_recv; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 206 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 207 | op->reserved = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 208 | op++; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 209 | error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 210 | GPR_ASSERT(GRPC_CALL_OK == error); |
| 211 | |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 212 | CQ_EXPECT_COMPLETION(cqv, tag(102), false); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 213 | |
| 214 | op = ops; |
| 215 | op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; |
| 216 | op->data.recv_close_on_server.cancelled = &was_cancelled; |
| 217 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 218 | op->reserved = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 219 | op++; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 220 | error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 221 | GPR_ASSERT(GRPC_CALL_OK == error); |
| 222 | |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 223 | CQ_EXPECT_COMPLETION(cqv, tag(103), true); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 224 | cq_verify(cqv); |
| 225 | |
| 226 | /* call was cancelled (closed) ... */ |
| 227 | GPR_ASSERT(was_cancelled != 0); |
| 228 | /* with a certain error */ |
| 229 | GPR_ASSERT(status == expected_error); |
| 230 | |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 231 | const char* algo_name = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 232 | GPR_ASSERT(grpc_compression_algorithm_name(algorithm_to_disable, &algo_name)); |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 233 | char* expected_details = nullptr; |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 234 | gpr_asprintf(&expected_details, "Compression algorithm '%s' is disabled.", |
| 235 | algo_name); |
| 236 | /* and we expect a specific reason for it */ |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 237 | GPR_ASSERT(0 == grpc_slice_str_cmp(details, expected_details)); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 238 | gpr_free(expected_details); |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 239 | GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); |
Muxi Yan | 5ebd327 | 2016-10-31 07:27:07 -0700 | [diff] [blame] | 240 | validate_host_override_string("foo.test.google.fr:1234", call_details.host, |
| 241 | config); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 242 | |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 243 | grpc_slice_unref(details); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 244 | grpc_metadata_array_destroy(&initial_metadata_recv); |
| 245 | grpc_metadata_array_destroy(&trailing_metadata_recv); |
| 246 | grpc_metadata_array_destroy(&request_metadata_recv); |
| 247 | grpc_call_details_destroy(&call_details); |
| 248 | |
Craig Tiller | dd36b15 | 2017-03-31 08:27:28 -0700 | [diff] [blame] | 249 | grpc_call_unref(c); |
| 250 | grpc_call_unref(s); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 251 | |
| 252 | cq_verifier_destroy(cqv); |
| 253 | |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 254 | grpc_slice_unref(request_payload_slice); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 255 | grpc_byte_buffer_destroy(request_payload); |
| 256 | grpc_byte_buffer_destroy(request_payload_recv); |
| 257 | |
Craig Tiller | 87a7e1f | 2016-11-09 09:42:19 -0800 | [diff] [blame] | 258 | { |
Yash Tibrewal | 8cf1470 | 2017-12-06 09:47:54 -0800 | [diff] [blame] | 259 | grpc_core::ExecCtx exec_ctx; |
| 260 | grpc_channel_args_destroy(client_args); |
| 261 | grpc_channel_args_destroy(server_args); |
Craig Tiller | 87a7e1f | 2016-11-09 09:42:19 -0800 | [diff] [blame] | 262 | } |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 263 | |
| 264 | end_test(&f); |
| 265 | config.tear_down_data(&f); |
| 266 | } |
| 267 | |
David Garcia Quintas | 5927aec | 2015-06-18 17:24:44 -0700 | [diff] [blame] | 268 | static void request_with_payload_template( |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 269 | grpc_end2end_test_config config, const char* test_name, |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 270 | uint32_t client_send_flags_bitmask, |
| 271 | grpc_compression_algorithm default_client_channel_compression_algorithm, |
| 272 | grpc_compression_algorithm default_server_channel_compression_algorithm, |
| 273 | grpc_compression_algorithm expected_algorithm_from_client, |
| 274 | grpc_compression_algorithm expected_algorithm_from_server, |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 275 | grpc_metadata* client_init_metadata, bool set_server_level, |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 276 | grpc_compression_level server_compression_level, |
| 277 | bool send_message_before_initial_metadata) { |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 278 | grpc_call* c; |
| 279 | grpc_call* s; |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 280 | grpc_slice request_payload_slice; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 281 | grpc_byte_buffer* request_payload = nullptr; |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 282 | grpc_channel_args* client_args; |
| 283 | grpc_channel_args* server_args; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 284 | grpc_end2end_test_fixture f; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 285 | grpc_op ops[6]; |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 286 | grpc_op* op; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 287 | grpc_metadata_array initial_metadata_recv; |
| 288 | grpc_metadata_array trailing_metadata_recv; |
| 289 | grpc_metadata_array request_metadata_recv; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 290 | grpc_byte_buffer* request_payload_recv = nullptr; |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 291 | grpc_byte_buffer* response_payload; |
| 292 | grpc_byte_buffer* response_payload_recv; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 293 | grpc_call_details call_details; |
| 294 | grpc_status_code status; |
Nicolas "Pixel" Noble | 9a123df | 2015-07-29 23:45:08 +0200 | [diff] [blame] | 295 | grpc_call_error error; |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 296 | grpc_slice details; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 297 | int was_cancelled = 2; |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 298 | cq_verifier* cqv; |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 299 | char request_str[1024]; |
| 300 | char response_str[1024]; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 301 | |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 302 | memset(request_str, 'x', 1023); |
| 303 | request_str[1023] = '\0'; |
| 304 | |
| 305 | memset(response_str, 'y', 1023); |
| 306 | response_str[1023] = '\0'; |
| 307 | |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 308 | request_payload_slice = grpc_slice_from_copied_string(request_str); |
Craig Tiller | 28b7242 | 2016-10-26 21:15:29 -0700 | [diff] [blame] | 309 | grpc_slice response_payload_slice = |
| 310 | grpc_slice_from_copied_string(response_str); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 311 | |
David Garcia Quintas | cadbf22 | 2015-07-17 15:33:13 -0700 | [diff] [blame] | 312 | client_args = grpc_channel_args_set_compression_algorithm( |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 313 | nullptr, default_client_channel_compression_algorithm); |
David Garcia Quintas | cadbf22 | 2015-07-17 15:33:13 -0700 | [diff] [blame] | 314 | server_args = grpc_channel_args_set_compression_algorithm( |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 315 | nullptr, default_server_channel_compression_algorithm); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 316 | |
David Garcia Quintas | 5927aec | 2015-06-18 17:24:44 -0700 | [diff] [blame] | 317 | f = begin_test(config, test_name, client_args, server_args); |
David Garcia Quintas | 92ce588 | 2015-06-23 17:07:12 -0700 | [diff] [blame] | 318 | cqv = cq_verifier_create(f.cq); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 319 | |
Chris Evans | ed2a547 | 2017-03-27 17:34:51 -0500 | [diff] [blame] | 320 | gpr_timespec deadline = five_seconds_from_now(); |
Muxi Yan | 5ebd327 | 2016-10-31 07:27:07 -0700 | [diff] [blame] | 321 | c = grpc_channel_create_call( |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 322 | f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq, |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 323 | grpc_slice_from_static_string("/foo"), |
| 324 | get_host_override_slice("foo.test.google.fr:1234", config), deadline, |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 325 | nullptr); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 326 | GPR_ASSERT(c); |
| 327 | |
| 328 | grpc_metadata_array_init(&initial_metadata_recv); |
| 329 | grpc_metadata_array_init(&trailing_metadata_recv); |
| 330 | grpc_metadata_array_init(&request_metadata_recv); |
| 331 | grpc_call_details_init(&call_details); |
| 332 | |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 333 | if (send_message_before_initial_metadata) { |
| 334 | request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); |
| 335 | memset(ops, 0, sizeof(ops)); |
| 336 | op = ops; |
| 337 | op->op = GRPC_OP_SEND_MESSAGE; |
| 338 | op->data.send_message.send_message = request_payload; |
| 339 | op->flags = client_send_flags_bitmask; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 340 | op->reserved = nullptr; |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 341 | op++; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 342 | error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), nullptr); |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 343 | GPR_ASSERT(GRPC_CALL_OK == error); |
| 344 | CQ_EXPECT_COMPLETION(cqv, tag(2), true); |
| 345 | } |
| 346 | |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 347 | memset(ops, 0, sizeof(ops)); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 348 | op = ops; |
| 349 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 350 | if (client_init_metadata != nullptr) { |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 351 | op->data.send_initial_metadata.count = 1; |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 352 | op->data.send_initial_metadata.metadata = client_init_metadata; |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 353 | } else { |
| 354 | op->data.send_initial_metadata.count = 0; |
| 355 | } |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 356 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 357 | op->reserved = nullptr; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 358 | op++; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 359 | op->op = GRPC_OP_RECV_INITIAL_METADATA; |
Mark D. Roth | 435f9f2 | 2017-01-25 12:53:54 -0800 | [diff] [blame] | 360 | op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 361 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 362 | op->reserved = nullptr; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 363 | op++; |
| 364 | op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
| 365 | op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; |
| 366 | op->data.recv_status_on_client.status = &status; |
| 367 | op->data.recv_status_on_client.status_details = &details; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 368 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 369 | op->reserved = nullptr; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 370 | op++; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 371 | error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); |
Nicolas "Pixel" Noble | 9a123df | 2015-07-29 23:45:08 +0200 | [diff] [blame] | 372 | GPR_ASSERT(GRPC_CALL_OK == error); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 373 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 374 | error = |
| 375 | grpc_server_request_call(f.server, &s, &call_details, |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 376 | &request_metadata_recv, f.cq, f.cq, tag(100)); |
Nicolas "Pixel" Noble | 9a123df | 2015-07-29 23:45:08 +0200 | [diff] [blame] | 377 | GPR_ASSERT(GRPC_CALL_OK == error); |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 378 | CQ_EXPECT_COMPLETION(cqv, tag(100), true); |
David Garcia Quintas | 92ce588 | 2015-06-23 17:07:12 -0700 | [diff] [blame] | 379 | cq_verify(cqv); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 380 | |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 381 | GPR_ASSERT(GPR_BITCOUNT(grpc_call_test_only_get_encodings_accepted_by_peer( |
| 382 | s)) == GRPC_COMPRESS_ALGORITHMS_COUNT); |
David Garcia Quintas | 0c33188 | 2015-10-08 14:51:54 -0700 | [diff] [blame] | 383 | GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), |
David Garcia Quintas | e091af8 | 2015-07-15 21:37:02 -0700 | [diff] [blame] | 384 | GRPC_COMPRESS_NONE) != 0); |
David Garcia Quintas | 0c33188 | 2015-10-08 14:51:54 -0700 | [diff] [blame] | 385 | GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), |
David Garcia Quintas | e091af8 | 2015-07-15 21:37:02 -0700 | [diff] [blame] | 386 | GRPC_COMPRESS_DEFLATE) != 0); |
David Garcia Quintas | 0c33188 | 2015-10-08 14:51:54 -0700 | [diff] [blame] | 387 | GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), |
David Garcia Quintas | e091af8 | 2015-07-15 21:37:02 -0700 | [diff] [blame] | 388 | GRPC_COMPRESS_GZIP) != 0); |
| 389 | |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 390 | memset(ops, 0, sizeof(ops)); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 391 | op = ops; |
| 392 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
| 393 | op->data.send_initial_metadata.count = 0; |
David Garcia Quintas | 1ebf1f1 | 2016-05-17 19:15:43 -0700 | [diff] [blame] | 394 | if (set_server_level) { |
| 395 | op->data.send_initial_metadata.maybe_compression_level.is_set = true; |
David Garcia Quintas | 8ba42be | 2016-06-07 17:30:20 -0700 | [diff] [blame] | 396 | op->data.send_initial_metadata.maybe_compression_level.level = |
David Garcia Quintas | 1ebf1f1 | 2016-05-17 19:15:43 -0700 | [diff] [blame] | 397 | server_compression_level; |
| 398 | } |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 399 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 400 | op->reserved = nullptr; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 401 | op++; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 402 | op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; |
| 403 | op->data.recv_close_on_server.cancelled = &was_cancelled; |
| 404 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 405 | op->reserved = nullptr; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 406 | op++; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 407 | error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(101), nullptr); |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 408 | GPR_ASSERT(GRPC_CALL_OK == error); |
| 409 | |
| 410 | for (int i = 0; i < 2; i++) { |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 411 | response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); |
| 412 | |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 413 | if (i > 0 || !send_message_before_initial_metadata) { |
| 414 | request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); |
| 415 | memset(ops, 0, sizeof(ops)); |
| 416 | op = ops; |
| 417 | op->op = GRPC_OP_SEND_MESSAGE; |
| 418 | op->data.send_message.send_message = request_payload; |
| 419 | op->flags = client_send_flags_bitmask; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 420 | op->reserved = nullptr; |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 421 | op++; |
Craig Tiller | be98d24 | 2017-11-10 15:26:57 -0800 | [diff] [blame] | 422 | error = |
| 423 | grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), nullptr); |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 424 | GPR_ASSERT(GRPC_CALL_OK == error); |
| 425 | CQ_EXPECT_COMPLETION(cqv, tag(2), 1); |
| 426 | } |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 427 | |
| 428 | memset(ops, 0, sizeof(ops)); |
| 429 | op = ops; |
| 430 | op->op = GRPC_OP_RECV_MESSAGE; |
Mark D. Roth | 435f9f2 | 2017-01-25 12:53:54 -0800 | [diff] [blame] | 431 | op->data.recv_message.recv_message = &request_payload_recv; |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 432 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 433 | op->reserved = nullptr; |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 434 | op++; |
Craig Tiller | be98d24 | 2017-11-10 15:26:57 -0800 | [diff] [blame] | 435 | error = |
| 436 | grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 437 | GPR_ASSERT(GRPC_CALL_OK == error); |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 438 | |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 439 | CQ_EXPECT_COMPLETION(cqv, tag(102), 1); |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 440 | cq_verify(cqv); |
| 441 | |
| 442 | GPR_ASSERT(request_payload_recv->type == GRPC_BB_RAW); |
| 443 | GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, request_str)); |
| 444 | GPR_ASSERT(request_payload_recv->data.raw.compression == |
| 445 | expected_algorithm_from_client); |
| 446 | |
| 447 | memset(ops, 0, sizeof(ops)); |
| 448 | op = ops; |
| 449 | op->op = GRPC_OP_SEND_MESSAGE; |
Mark D. Roth | 435f9f2 | 2017-01-25 12:53:54 -0800 | [diff] [blame] | 450 | op->data.send_message.send_message = response_payload; |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 451 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 452 | op->reserved = nullptr; |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 453 | op++; |
Craig Tiller | be98d24 | 2017-11-10 15:26:57 -0800 | [diff] [blame] | 454 | error = |
| 455 | grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), nullptr); |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 456 | GPR_ASSERT(GRPC_CALL_OK == error); |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 457 | |
| 458 | memset(ops, 0, sizeof(ops)); |
| 459 | op = ops; |
| 460 | op->op = GRPC_OP_RECV_MESSAGE; |
| 461 | op->data.recv_message.recv_message = &response_payload_recv; |
| 462 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 463 | op->reserved = nullptr; |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 464 | op++; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 465 | error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), nullptr); |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 466 | GPR_ASSERT(GRPC_CALL_OK == error); |
| 467 | |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 468 | CQ_EXPECT_COMPLETION(cqv, tag(103), 1); |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 469 | CQ_EXPECT_COMPLETION(cqv, tag(3), 1); |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 470 | cq_verify(cqv); |
| 471 | |
| 472 | GPR_ASSERT(response_payload_recv->type == GRPC_BB_RAW); |
| 473 | GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, response_str)); |
| 474 | if (server_compression_level > GRPC_COMPRESS_LEVEL_NONE) { |
| 475 | const grpc_compression_algorithm algo_for_server_level = |
| 476 | grpc_call_compression_for_level(s, server_compression_level); |
| 477 | GPR_ASSERT(response_payload_recv->data.raw.compression == |
| 478 | algo_for_server_level); |
| 479 | } else { |
| 480 | GPR_ASSERT(response_payload_recv->data.raw.compression == |
| 481 | expected_algorithm_from_server); |
| 482 | } |
| 483 | |
| 484 | grpc_byte_buffer_destroy(request_payload); |
| 485 | grpc_byte_buffer_destroy(response_payload); |
| 486 | grpc_byte_buffer_destroy(request_payload_recv); |
| 487 | grpc_byte_buffer_destroy(response_payload_recv); |
| 488 | } |
| 489 | |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 490 | grpc_slice_unref(request_payload_slice); |
| 491 | grpc_slice_unref(response_payload_slice); |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 492 | |
| 493 | memset(ops, 0, sizeof(ops)); |
| 494 | op = ops; |
| 495 | op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; |
| 496 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 497 | op->reserved = nullptr; |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 498 | op++; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 499 | error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), nullptr); |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 500 | GPR_ASSERT(GRPC_CALL_OK == error); |
| 501 | |
| 502 | memset(ops, 0, sizeof(ops)); |
| 503 | op = ops; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 504 | op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; |
| 505 | op->data.send_status_from_server.trailing_metadata_count = 0; |
| 506 | op->data.send_status_from_server.status = GRPC_STATUS_OK; |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 507 | grpc_slice status_details = grpc_slice_from_static_string("xyz"); |
| 508 | op->data.send_status_from_server.status_details = &status_details; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 509 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 510 | op->reserved = nullptr; |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 511 | op++; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 512 | error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), nullptr); |
Nicolas "Pixel" Noble | 9a123df | 2015-07-29 23:45:08 +0200 | [diff] [blame] | 513 | GPR_ASSERT(GRPC_CALL_OK == error); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 514 | |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 515 | CQ_EXPECT_COMPLETION(cqv, tag(1), 1); |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 516 | CQ_EXPECT_COMPLETION(cqv, tag(4), 1); |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 517 | CQ_EXPECT_COMPLETION(cqv, tag(101), 1); |
| 518 | CQ_EXPECT_COMPLETION(cqv, tag(104), 1); |
David Garcia Quintas | 92ce588 | 2015-06-23 17:07:12 -0700 | [diff] [blame] | 519 | cq_verify(cqv); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 520 | |
| 521 | GPR_ASSERT(status == GRPC_STATUS_OK); |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 522 | GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); |
| 523 | GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); |
Muxi Yan | 5ebd327 | 2016-10-31 07:27:07 -0700 | [diff] [blame] | 524 | validate_host_override_string("foo.test.google.fr:1234", call_details.host, |
| 525 | config); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 526 | GPR_ASSERT(was_cancelled == 0); |
David Garcia Quintas | 5927aec | 2015-06-18 17:24:44 -0700 | [diff] [blame] | 527 | |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 528 | grpc_slice_unref(details); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 529 | grpc_metadata_array_destroy(&initial_metadata_recv); |
| 530 | grpc_metadata_array_destroy(&trailing_metadata_recv); |
| 531 | grpc_metadata_array_destroy(&request_metadata_recv); |
| 532 | grpc_call_details_destroy(&call_details); |
| 533 | |
Craig Tiller | dd36b15 | 2017-03-31 08:27:28 -0700 | [diff] [blame] | 534 | grpc_call_unref(c); |
| 535 | grpc_call_unref(s); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 536 | |
David Garcia Quintas | 92ce588 | 2015-06-23 17:07:12 -0700 | [diff] [blame] | 537 | cq_verifier_destroy(cqv); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 538 | |
Craig Tiller | 87a7e1f | 2016-11-09 09:42:19 -0800 | [diff] [blame] | 539 | { |
Yash Tibrewal | 8cf1470 | 2017-12-06 09:47:54 -0800 | [diff] [blame] | 540 | grpc_core::ExecCtx exec_ctx; |
| 541 | grpc_channel_args_destroy(client_args); |
| 542 | grpc_channel_args_destroy(server_args); |
Craig Tiller | 87a7e1f | 2016-11-09 09:42:19 -0800 | [diff] [blame] | 543 | } |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 544 | |
| 545 | end_test(&f); |
| 546 | config.tear_down_data(&f); |
| 547 | } |
| 548 | |
David Garcia Quintas | d16af0e | 2015-06-22 22:39:21 -0700 | [diff] [blame] | 549 | static void test_invoke_request_with_exceptionally_uncompressed_payload( |
David Garcia Quintas | 5927aec | 2015-06-18 17:24:44 -0700 | [diff] [blame] | 550 | grpc_end2end_test_config config) { |
| 551 | request_with_payload_template( |
David Garcia Quintas | d16af0e | 2015-06-22 22:39:21 -0700 | [diff] [blame] | 552 | config, "test_invoke_request_with_exceptionally_uncompressed_payload", |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 553 | GRPC_WRITE_NO_COMPRESS, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 554 | GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, nullptr, false, |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 555 | /* ignored */ GRPC_COMPRESS_LEVEL_NONE, false); |
David Garcia Quintas | 5927aec | 2015-06-18 17:24:44 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static void test_invoke_request_with_uncompressed_payload( |
| 559 | grpc_end2end_test_config config) { |
| 560 | request_with_payload_template( |
| 561 | config, "test_invoke_request_with_uncompressed_payload", 0, |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 562 | GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, |
Craig Tiller | be98d24 | 2017-11-10 15:26:57 -0800 | [diff] [blame] | 563 | GRPC_COMPRESS_NONE, nullptr, false, |
| 564 | /* ignored */ GRPC_COMPRESS_LEVEL_NONE, false); |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | static void test_invoke_request_with_compressed_payload( |
| 568 | grpc_end2end_test_config config) { |
| 569 | request_with_payload_template( |
| 570 | config, "test_invoke_request_with_compressed_payload", 0, |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 571 | GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, |
Craig Tiller | be98d24 | 2017-11-10 15:26:57 -0800 | [diff] [blame] | 572 | GRPC_COMPRESS_GZIP, nullptr, false, |
| 573 | /* ignored */ GRPC_COMPRESS_LEVEL_NONE, false); |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | static void test_invoke_request_with_send_message_before_initial_metadata( |
| 577 | grpc_end2end_test_config config) { |
| 578 | request_with_payload_template( |
| 579 | config, "test_invoke_request_with_compressed_payload", 0, |
| 580 | GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, |
Craig Tiller | be98d24 | 2017-11-10 15:26:57 -0800 | [diff] [blame] | 581 | GRPC_COMPRESS_GZIP, nullptr, false, |
| 582 | /* ignored */ GRPC_COMPRESS_LEVEL_NONE, true); |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | static void test_invoke_request_with_server_level( |
| 586 | grpc_end2end_test_config config) { |
| 587 | request_with_payload_template( |
| 588 | config, "test_invoke_request_with_server_level", 0, GRPC_COMPRESS_NONE, |
| 589 | GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE /* ignored */, |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 590 | nullptr, true, GRPC_COMPRESS_LEVEL_HIGH, false); |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | static void test_invoke_request_with_compressed_payload_md_override( |
| 594 | grpc_end2end_test_config config) { |
| 595 | grpc_metadata gzip_compression_override; |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 596 | grpc_metadata identity_compression_override; |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 597 | |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 598 | gzip_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; |
| 599 | gzip_compression_override.value = grpc_slice_from_static_string("gzip"); |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 600 | memset(&gzip_compression_override.internal_data, 0, |
| 601 | sizeof(gzip_compression_override.internal_data)); |
| 602 | |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 603 | identity_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; |
| 604 | identity_compression_override.value = |
| 605 | grpc_slice_from_static_string("identity"); |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 606 | memset(&identity_compression_override.internal_data, 0, |
| 607 | sizeof(identity_compression_override.internal_data)); |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 608 | |
David Garcia Quintas | cddd95b | 2015-08-13 16:59:16 -0700 | [diff] [blame] | 609 | /* Channel default NONE (aka IDENTITY), call override to GZIP */ |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 610 | request_with_payload_template( |
| 611 | config, "test_invoke_request_with_compressed_payload_md_override_1", 0, |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 612 | GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, |
David Garcia Quintas | 1ebf1f1 | 2016-05-17 19:15:43 -0700 | [diff] [blame] | 613 | GRPC_COMPRESS_NONE, &gzip_compression_override, false, |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 614 | /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false); |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 615 | |
| 616 | /* Channel default DEFLATE, call override to GZIP */ |
| 617 | request_with_payload_template( |
| 618 | config, "test_invoke_request_with_compressed_payload_md_override_2", 0, |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 619 | GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, |
David Garcia Quintas | 1ebf1f1 | 2016-05-17 19:15:43 -0700 | [diff] [blame] | 620 | GRPC_COMPRESS_NONE, &gzip_compression_override, false, |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 621 | /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false); |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 622 | |
David Garcia Quintas | cddd95b | 2015-08-13 16:59:16 -0700 | [diff] [blame] | 623 | /* Channel default DEFLATE, call override to NONE (aka IDENTITY) */ |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 624 | request_with_payload_template( |
| 625 | config, "test_invoke_request_with_compressed_payload_md_override_3", 0, |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 626 | GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, |
David Garcia Quintas | 1ebf1f1 | 2016-05-17 19:15:43 -0700 | [diff] [blame] | 627 | GRPC_COMPRESS_NONE, &identity_compression_override, false, |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 628 | /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false); |
David Garcia Quintas | 5927aec | 2015-06-18 17:24:44 -0700 | [diff] [blame] | 629 | } |
| 630 | |
David Garcia Quintas | af1c7e4 | 2016-05-17 11:38:45 -0700 | [diff] [blame] | 631 | static void test_invoke_request_with_disabled_algorithm( |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 632 | grpc_end2end_test_config config) { |
Craig Tiller | be98d24 | 2017-11-10 15:26:57 -0800 | [diff] [blame] | 633 | request_for_disabled_algorithm(config, |
| 634 | "test_invoke_request_with_disabled_algorithm", |
| 635 | 0, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, |
| 636 | GRPC_STATUS_UNIMPLEMENTED, nullptr); |
David Garcia Quintas | 73dcbda | 2016-04-23 00:17:05 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Craig Tiller | 0fe5ee7 | 2015-12-22 12:50:36 -0800 | [diff] [blame] | 639 | void compressed_payload(grpc_end2end_test_config config) { |
David Garcia Quintas | d16af0e | 2015-06-22 22:39:21 -0700 | [diff] [blame] | 640 | test_invoke_request_with_exceptionally_uncompressed_payload(config); |
David Garcia Quintas | 5927aec | 2015-06-18 17:24:44 -0700 | [diff] [blame] | 641 | test_invoke_request_with_uncompressed_payload(config); |
David Garcia Quintas | 92ce588 | 2015-06-23 17:07:12 -0700 | [diff] [blame] | 642 | test_invoke_request_with_compressed_payload(config); |
Mark D. Roth | 7cd1425 | 2017-06-22 10:49:43 -0700 | [diff] [blame] | 643 | test_invoke_request_with_send_message_before_initial_metadata(config); |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 644 | test_invoke_request_with_server_level(config); |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 645 | test_invoke_request_with_compressed_payload_md_override(config); |
David Garcia Quintas | af1c7e4 | 2016-05-17 11:38:45 -0700 | [diff] [blame] | 646 | test_invoke_request_with_disabled_algorithm(config); |
David Garcia Quintas | f74a49e | 2015-06-18 17:22:45 -0700 | [diff] [blame] | 647 | } |
Craig Tiller | 9e9edbc | 2016-04-04 10:38:49 -0700 | [diff] [blame] | 648 | |
| 649 | void compressed_payload_pre_init(void) {} |