• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
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>
26 #include <grpc/compression.h>
27 #include <grpc/support/alloc.h>
28 #include <grpc/support/log.h>
29 #include <grpc/support/string_util.h>
30 #include <grpc/support/time.h>
31 
32 #include "src/core/lib/channel/channel_args.h"
33 #include "src/core/lib/surface/call.h"
34 #include "src/core/lib/surface/call_test_only.h"
35 #include "src/core/lib/transport/static_metadata.h"
36 #include "test/core/end2end/cq_verifier.h"
37 
tag(intptr_t t)38 static void* tag(intptr_t t) { return (void*)t; }
39 
begin_test(grpc_end2end_test_config config,const char * test_name,grpc_channel_args * client_args,grpc_channel_args * server_args)40 static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
41                                             const char* test_name,
42                                             grpc_channel_args* client_args,
43                                             grpc_channel_args* server_args) {
44   grpc_end2end_test_fixture f;
45   gpr_log(GPR_INFO, "Running test: %s/%s", test_name, config.name);
46   f = config.create_fixture(client_args, server_args);
47   config.init_server(&f, server_args);
48   config.init_client(&f, client_args);
49   return f;
50 }
51 
n_seconds_from_now(int n)52 static gpr_timespec n_seconds_from_now(int n) {
53   return grpc_timeout_seconds_to_deadline(n);
54 }
55 
five_seconds_from_now(void)56 static gpr_timespec five_seconds_from_now(void) {
57   return n_seconds_from_now(5);
58 }
59 
drain_cq(grpc_completion_queue * cq)60 static void drain_cq(grpc_completion_queue* cq) {
61   grpc_event ev;
62   do {
63     ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
64   } while (ev.type != GRPC_QUEUE_SHUTDOWN);
65 }
66 
shutdown_server(grpc_end2end_test_fixture * f)67 static void shutdown_server(grpc_end2end_test_fixture* f) {
68   if (!f->server) return;
69   grpc_server_shutdown_and_notify(f->server, f->shutdown_cq, tag(1000));
70   GPR_ASSERT(grpc_completion_queue_pluck(f->shutdown_cq, tag(1000),
71                                          grpc_timeout_seconds_to_deadline(5),
72                                          nullptr)
73                  .type == GRPC_OP_COMPLETE);
74   grpc_server_destroy(f->server);
75   f->server = nullptr;
76 }
77 
shutdown_client(grpc_end2end_test_fixture * f)78 static void shutdown_client(grpc_end2end_test_fixture* f) {
79   if (!f->client) return;
80   grpc_channel_destroy(f->client);
81   f->client = nullptr;
82 }
83 
end_test(grpc_end2end_test_fixture * f)84 static void end_test(grpc_end2end_test_fixture* f) {
85   shutdown_server(f);
86   shutdown_client(f);
87 
88   grpc_completion_queue_shutdown(f->cq);
89   drain_cq(f->cq);
90   grpc_completion_queue_destroy(f->cq);
91   grpc_completion_queue_destroy(f->shutdown_cq);
92 }
93 
request_for_disabled_algorithm(grpc_end2end_test_config config,const char * test_name,uint32_t send_flags_bitmask,grpc_compression_algorithm algorithm_to_disable,grpc_compression_algorithm requested_client_compression_algorithm,grpc_status_code expected_error,grpc_metadata * client_metadata)94 static void request_for_disabled_algorithm(
95     grpc_end2end_test_config config, const char* test_name,
96     uint32_t send_flags_bitmask,
97     grpc_compression_algorithm algorithm_to_disable,
98     grpc_compression_algorithm requested_client_compression_algorithm,
99     grpc_status_code expected_error, grpc_metadata* client_metadata) {
100   grpc_call* c;
101   grpc_call* s;
102   grpc_slice request_payload_slice;
103   grpc_byte_buffer* request_payload;
104   grpc_channel_args* client_args;
105   grpc_channel_args* server_args;
106   grpc_end2end_test_fixture f;
107   grpc_op ops[6];
108   grpc_op* op;
109   grpc_metadata_array initial_metadata_recv;
110   grpc_metadata_array trailing_metadata_recv;
111   grpc_metadata_array request_metadata_recv;
112   grpc_byte_buffer* request_payload_recv = nullptr;
113   grpc_call_details call_details;
114   grpc_status_code status;
115   grpc_call_error error;
116   grpc_slice details;
117   int was_cancelled = 2;
118   cq_verifier* cqv;
119   char str[1024];
120 
121   memset(str, 'x', 1023);
122   str[1023] = '\0';
123   request_payload_slice = grpc_slice_from_copied_string(str);
124   request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1);
125 
126   client_args = grpc_channel_args_set_compression_algorithm(
127       nullptr, requested_client_compression_algorithm);
128   server_args =
129       grpc_channel_args_set_compression_algorithm(nullptr, GRPC_COMPRESS_NONE);
130   {
131     grpc_core::ExecCtx exec_ctx;
132     server_args = grpc_channel_args_compression_algorithm_set_state(
133         &server_args, algorithm_to_disable, false);
134   }
135 
136   f = begin_test(config, test_name, client_args, server_args);
137   cqv = cq_verifier_create(f.cq);
138 
139   gpr_timespec deadline = five_seconds_from_now();
140   c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
141                                grpc_slice_from_static_string("/foo"), nullptr,
142                                deadline, nullptr);
143   GPR_ASSERT(c);
144 
145   grpc_metadata_array_init(&initial_metadata_recv);
146   grpc_metadata_array_init(&trailing_metadata_recv);
147   grpc_metadata_array_init(&request_metadata_recv);
148   grpc_call_details_init(&call_details);
149 
150   error =
151       grpc_server_request_call(f.server, &s, &call_details,
152                                &request_metadata_recv, f.cq, f.cq, tag(101));
153   GPR_ASSERT(GRPC_CALL_OK == error);
154 
155   memset(ops, 0, sizeof(ops));
156   op = ops;
157   op->op = GRPC_OP_SEND_INITIAL_METADATA;
158   if (client_metadata != nullptr) {
159     op->data.send_initial_metadata.count = 1;
160     op->data.send_initial_metadata.metadata = client_metadata;
161   } else {
162     op->data.send_initial_metadata.count = 0;
163   }
164   op->flags = 0;
165   op->reserved = nullptr;
166   op++;
167   op->op = GRPC_OP_SEND_MESSAGE;
168   op->data.send_message.send_message = request_payload;
169   op->flags = send_flags_bitmask;
170   op->reserved = nullptr;
171   op++;
172   op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
173   op->flags = 0;
174   op->reserved = nullptr;
175   op++;
176   op->op = GRPC_OP_RECV_INITIAL_METADATA;
177   op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv;
178   op->flags = 0;
179   op->reserved = nullptr;
180   op++;
181   op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
182   op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
183   op->data.recv_status_on_client.status = &status;
184   op->data.recv_status_on_client.status_details = &details;
185   op->flags = 0;
186   op->reserved = nullptr;
187   op++;
188   error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
189                                 nullptr);
190   GPR_ASSERT(GRPC_CALL_OK == error);
191 
192   CQ_EXPECT_COMPLETION(cqv, tag(101), true);
193   CQ_EXPECT_COMPLETION(cqv, tag(1), true);
194   cq_verify(cqv);
195 
196   op = ops;
197   op->op = GRPC_OP_SEND_INITIAL_METADATA;
198   op->data.send_initial_metadata.count = 0;
199   op->flags = 0;
200   op->reserved = nullptr;
201   op++;
202   op->op = GRPC_OP_RECV_MESSAGE;
203   op->data.recv_message.recv_message = &request_payload_recv;
204   op->flags = 0;
205   op->reserved = nullptr;
206   op++;
207   error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
208                                 nullptr);
209   GPR_ASSERT(GRPC_CALL_OK == error);
210 
211   CQ_EXPECT_COMPLETION(cqv, tag(102), false);
212 
213   op = ops;
214   op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
215   op->data.recv_close_on_server.cancelled = &was_cancelled;
216   op->flags = 0;
217   op->reserved = nullptr;
218   op++;
219   error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(103),
220                                 nullptr);
221   GPR_ASSERT(GRPC_CALL_OK == error);
222 
223   CQ_EXPECT_COMPLETION(cqv, tag(103), true);
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 
231   const char* algo_name = nullptr;
232   GPR_ASSERT(grpc_compression_algorithm_name(algorithm_to_disable, &algo_name));
233   char* expected_details = nullptr;
234   gpr_asprintf(&expected_details, "Compression algorithm '%s' is disabled.",
235                algo_name);
236   /* and we expect a specific reason for it */
237   GPR_ASSERT(0 == grpc_slice_str_cmp(details, expected_details));
238   gpr_free(expected_details);
239   GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo"));
240 
241   grpc_slice_unref(details);
242   grpc_metadata_array_destroy(&initial_metadata_recv);
243   grpc_metadata_array_destroy(&trailing_metadata_recv);
244   grpc_metadata_array_destroy(&request_metadata_recv);
245   grpc_call_details_destroy(&call_details);
246 
247   grpc_call_unref(c);
248   grpc_call_unref(s);
249 
250   cq_verifier_destroy(cqv);
251 
252   grpc_slice_unref(request_payload_slice);
253   grpc_byte_buffer_destroy(request_payload);
254   grpc_byte_buffer_destroy(request_payload_recv);
255 
256   {
257     grpc_core::ExecCtx exec_ctx;
258     grpc_channel_args_destroy(client_args);
259     grpc_channel_args_destroy(server_args);
260   }
261 
262   end_test(&f);
263   config.tear_down_data(&f);
264 }
265 
request_with_payload_template(grpc_end2end_test_config config,const char * test_name,uint32_t client_send_flags_bitmask,grpc_compression_algorithm default_client_channel_compression_algorithm,grpc_compression_algorithm default_server_channel_compression_algorithm,grpc_compression_algorithm expected_client_compression_algorithm,grpc_compression_algorithm expected_server_compression_algorithm,grpc_metadata * client_init_metadata,bool set_server_level,grpc_compression_level server_compression_level,bool send_message_before_initial_metadata,bool set_default_server_message_compression_algorithm,grpc_compression_algorithm default_server_message_compression_algorithm)266 static void request_with_payload_template(
267     grpc_end2end_test_config config, const char* test_name,
268     uint32_t client_send_flags_bitmask,
269     grpc_compression_algorithm default_client_channel_compression_algorithm,
270     grpc_compression_algorithm default_server_channel_compression_algorithm,
271     grpc_compression_algorithm expected_client_compression_algorithm,
272     grpc_compression_algorithm expected_server_compression_algorithm,
273     grpc_metadata* client_init_metadata, bool set_server_level,
274     grpc_compression_level server_compression_level,
275     bool send_message_before_initial_metadata,
276     bool set_default_server_message_compression_algorithm,
277     grpc_compression_algorithm default_server_message_compression_algorithm) {
278   grpc_call* c;
279   grpc_call* s;
280   grpc_slice request_payload_slice;
281   grpc_byte_buffer* request_payload = nullptr;
282   grpc_channel_args* client_args;
283   grpc_channel_args* server_args;
284   grpc_end2end_test_fixture f;
285   grpc_op ops[6];
286   grpc_op* op;
287   grpc_metadata_array initial_metadata_recv;
288   grpc_metadata_array trailing_metadata_recv;
289   grpc_metadata_array request_metadata_recv;
290   grpc_byte_buffer* request_payload_recv = nullptr;
291   grpc_byte_buffer* response_payload;
292   grpc_byte_buffer* response_payload_recv;
293   grpc_call_details call_details;
294   grpc_status_code status;
295   grpc_call_error error;
296   grpc_slice details;
297   int was_cancelled = 2;
298   cq_verifier* cqv;
299   char request_str[1024];
300   char response_str[1024];
301 
302   memset(request_str, 'x', 1023);
303   request_str[1023] = '\0';
304 
305   memset(response_str, 'y', 1023);
306   response_str[1023] = '\0';
307 
308   request_payload_slice = grpc_slice_from_copied_string(request_str);
309   grpc_slice response_payload_slice =
310       grpc_slice_from_copied_string(response_str);
311 
312   client_args = grpc_channel_args_set_compression_algorithm(
313       nullptr, default_client_channel_compression_algorithm);
314   if (set_default_server_message_compression_algorithm) {
315     server_args = grpc_channel_args_set_compression_algorithm(
316         nullptr, default_server_message_compression_algorithm);
317   } else {
318     server_args = grpc_channel_args_set_compression_algorithm(
319         nullptr, default_server_channel_compression_algorithm);
320   }
321 
322   f = begin_test(config, test_name, client_args, server_args);
323   cqv = cq_verifier_create(f.cq);
324 
325   gpr_timespec deadline = five_seconds_from_now();
326   c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
327                                grpc_slice_from_static_string("/foo"), nullptr,
328                                deadline, nullptr);
329   GPR_ASSERT(c);
330 
331   grpc_metadata_array_init(&initial_metadata_recv);
332   grpc_metadata_array_init(&trailing_metadata_recv);
333   grpc_metadata_array_init(&request_metadata_recv);
334   grpc_call_details_init(&call_details);
335 
336   if (send_message_before_initial_metadata) {
337     request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1);
338     memset(ops, 0, sizeof(ops));
339     op = ops;
340     op->op = GRPC_OP_SEND_MESSAGE;
341     op->data.send_message.send_message = request_payload;
342     op->flags = client_send_flags_bitmask;
343     op->reserved = nullptr;
344     op++;
345     error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(2),
346                                   nullptr);
347     GPR_ASSERT(GRPC_CALL_OK == error);
348     CQ_EXPECT_COMPLETION(cqv, tag(2), true);
349   }
350 
351   memset(ops, 0, sizeof(ops));
352   op = ops;
353   op->op = GRPC_OP_SEND_INITIAL_METADATA;
354   if (client_init_metadata != nullptr) {
355     op->data.send_initial_metadata.count = 1;
356     op->data.send_initial_metadata.metadata = client_init_metadata;
357   } else {
358     op->data.send_initial_metadata.count = 0;
359   }
360   op->flags = 0;
361   op->reserved = nullptr;
362   op++;
363   op->op = GRPC_OP_RECV_INITIAL_METADATA;
364   op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv;
365   op->flags = 0;
366   op->reserved = nullptr;
367   op++;
368   op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
369   op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
370   op->data.recv_status_on_client.status = &status;
371   op->data.recv_status_on_client.status_details = &details;
372   op->flags = 0;
373   op->reserved = nullptr;
374   op++;
375   error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
376                                 nullptr);
377   GPR_ASSERT(GRPC_CALL_OK == error);
378 
379   error =
380       grpc_server_request_call(f.server, &s, &call_details,
381                                &request_metadata_recv, f.cq, f.cq, tag(100));
382   GPR_ASSERT(GRPC_CALL_OK == error);
383   CQ_EXPECT_COMPLETION(cqv, tag(100), true);
384   cq_verify(cqv);
385 
386   GPR_ASSERT(GPR_BITCOUNT(grpc_call_test_only_get_encodings_accepted_by_peer(
387                  s)) == GRPC_COMPRESS_ALGORITHMS_COUNT);
388   GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
389                         GRPC_COMPRESS_NONE) != 0);
390   GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
391                         GRPC_COMPRESS_DEFLATE) != 0);
392   GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
393                         GRPC_COMPRESS_GZIP) != 0);
394   GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
395                         GRPC_COMPRESS_STREAM_GZIP) != 0);
396   GPR_ASSERT(GPR_BITCOUNT(grpc_call_test_only_get_encodings_accepted_by_peer(
397                  s)) == GRPC_COMPRESS_ALGORITHMS_COUNT);
398 
399   memset(ops, 0, sizeof(ops));
400   op = ops;
401   op->op = GRPC_OP_SEND_INITIAL_METADATA;
402   op->data.send_initial_metadata.count = 0;
403   if (set_server_level) {
404     op->data.send_initial_metadata.maybe_compression_level.is_set = true;
405     op->data.send_initial_metadata.maybe_compression_level.level =
406         server_compression_level;
407   }
408   op->flags = 0;
409   op->reserved = nullptr;
410   op++;
411   op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
412   op->data.recv_close_on_server.cancelled = &was_cancelled;
413   op->flags = 0;
414   op->reserved = nullptr;
415   op++;
416   error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(101),
417                                 nullptr);
418   GPR_ASSERT(GRPC_CALL_OK == error);
419 
420   for (int i = 0; i < 2; i++) {
421     response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1);
422 
423     if (i > 0 || !send_message_before_initial_metadata) {
424       request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1);
425       memset(ops, 0, sizeof(ops));
426       op = ops;
427       op->op = GRPC_OP_SEND_MESSAGE;
428       op->data.send_message.send_message = request_payload;
429       op->flags = client_send_flags_bitmask;
430       op->reserved = nullptr;
431       op++;
432       error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
433                                     tag(2), nullptr);
434       GPR_ASSERT(GRPC_CALL_OK == error);
435       CQ_EXPECT_COMPLETION(cqv, tag(2), 1);
436     }
437 
438     memset(ops, 0, sizeof(ops));
439     op = ops;
440     op->op = GRPC_OP_RECV_MESSAGE;
441     op->data.recv_message.recv_message = &request_payload_recv;
442     op->flags = 0;
443     op->reserved = nullptr;
444     op++;
445     error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
446                                   tag(102), nullptr);
447     GPR_ASSERT(GRPC_CALL_OK == error);
448 
449     CQ_EXPECT_COMPLETION(cqv, tag(102), 1);
450     cq_verify(cqv);
451 
452     GPR_ASSERT(request_payload_recv->type == GRPC_BB_RAW);
453     GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, request_str));
454 
455     memset(ops, 0, sizeof(ops));
456     op = ops;
457     op->op = GRPC_OP_SEND_MESSAGE;
458     op->data.send_message.send_message = response_payload;
459     op->flags = 0;
460     op->reserved = nullptr;
461     op++;
462     error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
463                                   tag(103), nullptr);
464     GPR_ASSERT(GRPC_CALL_OK == error);
465 
466     memset(ops, 0, sizeof(ops));
467     op = ops;
468     op->op = GRPC_OP_RECV_MESSAGE;
469     op->data.recv_message.recv_message = &response_payload_recv;
470     op->flags = 0;
471     op->reserved = nullptr;
472     op++;
473     error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(3),
474                                   nullptr);
475     GPR_ASSERT(GRPC_CALL_OK == error);
476 
477     CQ_EXPECT_COMPLETION(cqv, tag(103), 1);
478     CQ_EXPECT_COMPLETION(cqv, tag(3), 1);
479     cq_verify(cqv);
480 
481     GPR_ASSERT(response_payload_recv->type == GRPC_BB_RAW);
482     GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, response_str));
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 
490   grpc_slice_unref(request_payload_slice);
491   grpc_slice_unref(response_payload_slice);
492 
493   memset(ops, 0, sizeof(ops));
494   op = ops;
495   op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
496   op->flags = 0;
497   op->reserved = nullptr;
498   op++;
499   error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(4),
500                                 nullptr);
501   GPR_ASSERT(GRPC_CALL_OK == error);
502 
503   memset(ops, 0, sizeof(ops));
504   op = ops;
505   op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
506   op->data.send_status_from_server.trailing_metadata_count = 0;
507   op->data.send_status_from_server.status = GRPC_STATUS_OK;
508   grpc_slice status_details = grpc_slice_from_static_string("xyz");
509   op->data.send_status_from_server.status_details = &status_details;
510   op->flags = 0;
511   op->reserved = nullptr;
512   op++;
513   error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(104),
514                                 nullptr);
515   GPR_ASSERT(GRPC_CALL_OK == error);
516 
517   CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
518   CQ_EXPECT_COMPLETION(cqv, tag(4), 1);
519   CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
520   CQ_EXPECT_COMPLETION(cqv, tag(104), 1);
521   cq_verify(cqv);
522 
523   GPR_ASSERT(status == GRPC_STATUS_OK);
524   GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz"));
525   GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo"));
526   GPR_ASSERT(was_cancelled == 0);
527 
528   grpc_slice_unref(details);
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 
534   grpc_call_unref(c);
535   grpc_call_unref(s);
536 
537   cq_verifier_destroy(cqv);
538 
539   {
540     grpc_core::ExecCtx exec_ctx;
541     grpc_channel_args_destroy(client_args);
542     grpc_channel_args_destroy(server_args);
543   }
544 
545   end_test(&f);
546   config.tear_down_data(&f);
547 }
548 
test_invoke_request_with_compressed_payload(grpc_end2end_test_config config)549 static void test_invoke_request_with_compressed_payload(
550     grpc_end2end_test_config config) {
551   request_with_payload_template(
552       config, "test_invoke_request_with_compressed_payload", 0,
553       GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_STREAM_GZIP,
554       GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_STREAM_GZIP, nullptr,
555       false, /* ignored */
556       GRPC_COMPRESS_LEVEL_NONE, false, false, GRPC_COMPRESS_NONE);
557 }
558 
test_invoke_request_with_send_message_before_initial_metadata(grpc_end2end_test_config config)559 static void test_invoke_request_with_send_message_before_initial_metadata(
560     grpc_end2end_test_config config) {
561   request_with_payload_template(
562       config, "test_invoke_request_with_send_message_before_initial_metadata",
563       0, GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_STREAM_GZIP,
564       GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_STREAM_GZIP, nullptr,
565       false, /* ignored */
566       GRPC_COMPRESS_LEVEL_NONE, true, false, GRPC_COMPRESS_NONE);
567 }
568 
test_invoke_request_with_compressed_payload_md_override(grpc_end2end_test_config config)569 static void test_invoke_request_with_compressed_payload_md_override(
570     grpc_end2end_test_config config) {
571   grpc_metadata gzip_compression_override;
572   grpc_metadata identity_compression_override;
573 
574   gzip_compression_override.key =
575       GRPC_MDSTR_GRPC_INTERNAL_STREAM_ENCODING_REQUEST;
576   gzip_compression_override.value =
577       grpc_slice_from_static_string("stream/gzip");
578   memset(&gzip_compression_override.internal_data, 0,
579          sizeof(gzip_compression_override.internal_data));
580 
581   identity_compression_override.key =
582       GRPC_MDSTR_GRPC_INTERNAL_STREAM_ENCODING_REQUEST;
583   identity_compression_override.value =
584       grpc_slice_from_static_string("identity");
585   memset(&identity_compression_override.internal_data, 0,
586          sizeof(identity_compression_override.internal_data));
587 
588   /* Channel default NONE (aka IDENTITY), call override to stream GZIP */
589   request_with_payload_template(
590       config, "test_invoke_request_with_compressed_payload_md_override_1", 0,
591       GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_STREAM_GZIP,
592       GRPC_COMPRESS_NONE, &gzip_compression_override, false,
593       /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false, false, GRPC_COMPRESS_NONE);
594 
595   /* Channel default stream GZIP, call override to NONE (aka IDENTITY) */
596   request_with_payload_template(
597       config, "test_invoke_request_with_compressed_payload_md_override_3", 0,
598       GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE,
599       GRPC_COMPRESS_NONE, &identity_compression_override, false,
600       /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false, false, GRPC_COMPRESS_NONE);
601 }
602 
test_invoke_request_with_disabled_algorithm(grpc_end2end_test_config config)603 static void test_invoke_request_with_disabled_algorithm(
604     grpc_end2end_test_config config) {
605   request_for_disabled_algorithm(
606       config, "test_invoke_request_with_disabled_algorithm", 0,
607       GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_STREAM_GZIP,
608       GRPC_STATUS_UNIMPLEMENTED, nullptr);
609 }
610 
stream_compression_compressed_payload(grpc_end2end_test_config config)611 void stream_compression_compressed_payload(grpc_end2end_test_config config) {
612   test_invoke_request_with_compressed_payload(config);
613   test_invoke_request_with_send_message_before_initial_metadata(config);
614   test_invoke_request_with_compressed_payload_md_override(config);
615   test_invoke_request_with_disabled_algorithm(config);
616 }
617 
stream_compression_compressed_payload_pre_init(void)618 void stream_compression_compressed_payload_pre_init(void) {}
619