Debian Codegraph @

test/core/end2end/fixtures/h2_full_no_retry.cc

raw
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 <string.h>
20
21 #include <string>
22
23 #include <grpc/grpc.h>
24 #include <grpc/grpc_security.h>
25 #include <grpc/support/log.h>
26
27 #include "src/core/lib/channel/channel_args.h"
28 #include "src/core/lib/gprpp/host_port.h"
29 #include "test/core/end2end/end2end_tests.h"
30 #include "test/core/util/port.h"
31 #include "test/core/util/test_config.h"
32
33 struct fullstack_fixture_data {
34 std::string localaddr;
35 };
36
37 static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
38 const grpc_channel_args* /*client_args*/,
39 const grpc_channel_args* /*server_args*/) {
40 grpc_end2end_test_fixture f;
41 int port = grpc_pick_unused_port_or_die();
42 fullstack_fixture_data* ffd = new fullstack_fixture_data();
43 memset(&f, 0, sizeof(f));
44
45 ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
46
47 f.fixture_data = ffd;
48 f.cq = grpc_completion_queue_create_for_next(nullptr);
49
50 return f;
51 }
52
53 void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
54 const grpc_channel_args* client_args) {
55 fullstack_fixture_data* ffd =
56 static_cast<fullstack_fixture_data*>(f->fixture_data);
57 grpc_channel_credentials* creds = grpc_insecure_credentials_create();
58 grpc_arg no_retry = grpc_channel_arg_integer_create(
59 const_cast<char*>(GRPC_ARG_ENABLE_RETRIES), 0);
60 client_args = grpc_channel_args_copy_and_add(client_args, &no_retry, 1);
61 f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
62 grpc_channel_args_destroy(client_args);
63 grpc_channel_credentials_release(creds);
64 GPR_ASSERT(f->client);
65 }
66
67 void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
68 const grpc_channel_args* server_args) {
69 fullstack_fixture_data* ffd =
70 static_cast<fullstack_fixture_data*>(f->fixture_data);
71 if (f->server) {
72 grpc_server_destroy(f->server);
73 }
74 f->server = grpc_server_create(server_args, nullptr);
75 grpc_server_register_completion_queue(f->server, f->cq, nullptr);
76 grpc_server_credentials* server_creds =
77 grpc_insecure_server_credentials_create();
78 GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
79 server_creds));
80 grpc_server_credentials_release(server_creds);
81 grpc_server_start(f->server);
82 }
83
84 void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
85 fullstack_fixture_data* ffd =
86 static_cast<fullstack_fixture_data*>(f->fixture_data);
87 delete ffd;
88 }
89
90 /* All test configurations */
91 static grpc_end2end_test_config configs[] = {
92 {"chttp2/fullstack",
93 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
94 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
95 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
96 nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
97 chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
98 };
99
100 int main(int argc, char** argv) {
101 size_t i;
102
103 grpc::testing::TestEnvironment env(&argc, argv);
104 grpc_end2end_tests_pre_init();
105 grpc_init();
106
107 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
108 grpc_end2end_tests(argc, argv, configs[i]);
109 }
110
111 grpc_shutdown();
112
113 return 0;
114 }