Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | *is % allowed in string |
| 32 | */ |
| 33 | |
| 34 | #include <memory> |
| 35 | #include <string> |
| 36 | #include <thread> |
| 37 | #include <utility> |
| 38 | #include <vector> |
| 39 | |
| 40 | #include <gflags/gflags.h> |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 41 | #include <grpc++/create_channel.h> |
| 42 | #include <grpc++/grpc++.h> |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 43 | #include <grpc++/impl/thd.h> |
David Garcia Quintas | c79b065 | 2016-07-27 21:11:58 -0700 | [diff] [blame] | 44 | #include <grpc/support/log.h> |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 45 | #include <grpc/support/time.h> |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 46 | |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 47 | #include "src/proto/grpc/testing/metrics.grpc.pb.h" |
| 48 | #include "src/proto/grpc/testing/metrics.pb.h" |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 49 | #include "test/cpp/interop/client_helper.h" |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 50 | #include "test/cpp/interop/interop_client.h" |
| 51 | #include "test/cpp/interop/stress_interop_client.h" |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 52 | #include "test/cpp/util/metrics_server.h" |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 53 | #include "test/cpp/util/test_config.h" |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 54 | |
Sree Kuchibhotla | 0fa95ea | 2016-01-06 07:58:10 -0800 | [diff] [blame] | 55 | extern "C" { |
| 56 | extern void gpr_default_log(gpr_log_func_args* args); |
| 57 | } |
| 58 | |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 59 | DEFINE_int32(metrics_port, 8081, "The metrics server port."); |
| 60 | |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 61 | DEFINE_int32(sleep_duration_ms, 0, |
| 62 | "The duration (in millisec) between two" |
| 63 | " consecutive test calls (per server) issued by the server."); |
| 64 | |
| 65 | DEFINE_int32(test_duration_secs, -1, |
| 66 | "The length of time (in seconds) to run" |
| 67 | " the test. Enter -1 if the test should run continuously until" |
| 68 | " forcefully terminated."); |
| 69 | |
| 70 | DEFINE_string(server_addresses, "localhost:8080", |
| 71 | "The list of server" |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 72 | "addresses. This option is ignored if either\n" |
| 73 | "server_port or server_host is specified. The format is: \n" |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 74 | " \"<name_1>:<port_1>,<name_2>:<port_1>...<name_N>:<port_N>\"\n" |
| 75 | " Note: <name> can be servername or IP address."); |
| 76 | |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 77 | DEFINE_int32(num_channels_per_server, 1, "Number of channels for each server"); |
| 78 | |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 79 | DEFINE_int32(num_stubs_per_channel, 1, |
| 80 | "Number of stubs per each channels to server. This number also " |
| 81 | "indicates the max number of parallel RPC calls on each channel " |
| 82 | "at any given time."); |
| 83 | |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 84 | DEFINE_string(test_case, "", |
| 85 | "Configure different test cases. Valid options are:\n\n" |
| 86 | "all : all test cases;\n" |
| 87 | "cancel_after_begin : cancel stream after starting it;\n" |
| 88 | "cancel_after_first_response: cancel on first response;\n" |
| 89 | "client_compressed_streaming : compressed request streaming with " |
| 90 | "client_compressed_unary : single compressed request;\n" |
| 91 | "client_streaming : request streaming with single response;\n" |
| 92 | "compute_engine_creds: large_unary with compute engine auth;\n" |
| 93 | "custom_metadata: server will echo custom metadata;\n" |
| 94 | "empty_stream : bi-di stream with no request/response;\n" |
| 95 | "empty_unary : empty (zero bytes) request and response;\n" |
| 96 | "half_duplex : half-duplex streaming;\n" |
| 97 | "jwt_token_creds: large_unary with JWT token auth;\n" |
| 98 | "large_unary : single request and (large) response;\n" |
| 99 | "oauth2_auth_token: raw oauth2 access token auth;\n" |
| 100 | "per_rpc_creds: raw oauth2 access token on a single rpc;\n" |
| 101 | "ping_pong : full-duplex streaming;\n" |
| 102 | "response streaming;\n" |
| 103 | "server_compressed_streaming : single request with compressed " |
| 104 | "server_compressed_unary : single compressed response;\n" |
| 105 | "server_streaming : single request with response streaming;\n" |
| 106 | "slow_consumer : single request with response streaming with " |
| 107 | "slow client consumer;\n" |
| 108 | "status_code_and_message: verify status code & message;\n" |
| 109 | "timeout_on_sleeping_server: deadline exceeds on stream;\n" |
| 110 | "unimplemented_method: client calls an unimplemented_method;\n"); |
| 111 | |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 112 | // TODO(sreek): Add more test cases here in future |
| 113 | DEFINE_string(test_cases, "", |
| 114 | "List of test cases to call along with the" |
| 115 | " relative weights in the following format:\n" |
| 116 | " \"<testcase_1:w_1>,<testcase_2:w_2>...<testcase_n:w_n>\"\n" |
| 117 | " The following testcases are currently supported:\n" |
| 118 | " empty_unary\n" |
| 119 | " large_unary\n" |
| 120 | " large_compressed_unary\n" |
| 121 | " client_streaming\n" |
| 122 | " server_streaming\n" |
Sree Kuchibhotla | 5130427 | 2016-05-05 15:19:00 -0700 | [diff] [blame] | 123 | " server_compressed_streaming\n" |
| 124 | " slow_consumer\n" |
| 125 | " half_duplex\n" |
| 126 | " ping_pong\n" |
| 127 | " cancel_after_begin\n" |
| 128 | " cancel_after_first_response\n" |
| 129 | " timeout_on_sleeping_server\n" |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 130 | " empty_stream\n" |
Sree Kuchibhotla | 5130427 | 2016-05-05 15:19:00 -0700 | [diff] [blame] | 131 | " status_code_and_message\n" |
| 132 | " custom_metadata\n" |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 133 | " Example: \"empty_unary:20,large_unary:10,empty_stream:70\"\n" |
| 134 | " The above will execute 'empty_unary', 20% of the time," |
| 135 | " 'large_unary', 10% of the time and 'empty_stream' the remaining" |
| 136 | " 70% of the time"); |
| 137 | |
Sree Kuchibhotla | 16dd3e4 | 2016-03-31 09:46:20 -0700 | [diff] [blame] | 138 | DEFINE_int32(log_level, GPR_LOG_SEVERITY_INFO, |
Sree Kuchibhotla | 0fa95ea | 2016-01-06 07:58:10 -0800 | [diff] [blame] | 139 | "Severity level of messages that should be logged. Any messages " |
| 140 | "greater than or equal to the level set here will be logged. " |
| 141 | "The choices are: 0 (GPR_LOG_SEVERITY_DEBUG), 1 " |
Sree Kuchibhotla | 16dd3e4 | 2016-03-31 09:46:20 -0700 | [diff] [blame] | 142 | "(GPR_LOG_SEVERITY_INFO) and 2 (GPR_LOG_SEVERITY_ERROR)"); |
Sree Kuchibhotla | 0fa95ea | 2016-01-06 07:58:10 -0800 | [diff] [blame] | 143 | |
Sree Kuchibhotla | ad0f792 | 2016-05-04 19:49:31 -0700 | [diff] [blame] | 144 | DEFINE_bool(do_not_abort_on_transient_failures, true, |
| 145 | "If set to 'true', abort() is not called in case of transient " |
| 146 | "failures like temporary connection failures."); |
| 147 | |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 148 | // Options from client.cc (for compatibility with interop test). |
| 149 | // TODO(sreek): Consolidate overlapping options |
| 150 | DEFINE_bool(use_tls, false, "Whether to use tls."); |
| 151 | DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); |
| 152 | DEFINE_int32(server_port, 0, "Server port."); |
| 153 | DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); |
| 154 | DEFINE_string(server_host_override, "foo.test.google.fr", |
| 155 | "Override the server host which is sent in HTTP header"); |
| 156 | DEFINE_string(service_account_key_file, "", |
| 157 | "Path to service account json key file."); |
| 158 | |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 159 | using grpc::testing::kTestCaseList; |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 160 | using grpc::testing::MetricsService; |
| 161 | using grpc::testing::MetricsServiceImpl; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 162 | using grpc::testing::StressTestInteropClient; |
| 163 | using grpc::testing::TestCaseType; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 164 | using grpc::testing::UNKNOWN_TEST; |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 165 | using grpc::testing::WeightedRandomTestSelector; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 166 | |
Sree Kuchibhotla | 0fa95ea | 2016-01-06 07:58:10 -0800 | [diff] [blame] | 167 | static int log_level = GPR_LOG_SEVERITY_DEBUG; |
| 168 | |
| 169 | // A simple wrapper to grp_default_log() function. This only logs messages at or |
| 170 | // above the current log level (set in 'log_level' variable) |
| 171 | void TestLogFunction(gpr_log_func_args* args) { |
| 172 | if (args->severity >= log_level) { |
| 173 | gpr_default_log(args); |
| 174 | } |
| 175 | } |
| 176 | |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 177 | TestCaseType GetTestTypeFromName(const grpc::string& test_name) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 178 | TestCaseType test_case = UNKNOWN_TEST; |
| 179 | |
| 180 | for (auto it = kTestCaseList.begin(); it != kTestCaseList.end(); it++) { |
| 181 | if (test_name == it->second) { |
| 182 | test_case = it->first; |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | return test_case; |
| 188 | } |
| 189 | |
| 190 | // Converts a string of comma delimited tokens to a vector of tokens |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 191 | bool ParseCommaDelimitedString(const grpc::string& comma_delimited_str, |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 192 | std::vector<grpc::string>& tokens) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 193 | size_t bpos = 0; |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 194 | size_t epos = grpc::string::npos; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 195 | |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 196 | while ((epos = comma_delimited_str.find(',', bpos)) != grpc::string::npos) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 197 | tokens.emplace_back(comma_delimited_str.substr(bpos, epos - bpos)); |
| 198 | bpos = epos + 1; |
| 199 | } |
| 200 | |
| 201 | tokens.emplace_back(comma_delimited_str.substr(bpos)); // Last token |
| 202 | return true; |
| 203 | } |
| 204 | |
| 205 | // Input: Test case string "<testcase_name:weight>,<testcase_name:weight>...." |
| 206 | // Output: |
| 207 | // - Whether parsing was successful (return value) |
| 208 | // - Vector of (test_type_enum, weight) pairs returned via 'tests' parameter |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 209 | bool ParseTestCasesString(const grpc::string& test_cases, |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 210 | std::vector<std::pair<TestCaseType, int>>& tests) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 211 | bool is_success = true; |
| 212 | |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 213 | std::vector<grpc::string> tokens; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 214 | ParseCommaDelimitedString(test_cases, tokens); |
| 215 | |
| 216 | for (auto it = tokens.begin(); it != tokens.end(); it++) { |
| 217 | // Token is in the form <test_name>:<test_weight> |
| 218 | size_t colon_pos = it->find(':'); |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 219 | if (colon_pos == grpc::string::npos) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 220 | gpr_log(GPR_ERROR, "Error in parsing test case string: %s", it->c_str()); |
| 221 | is_success = false; |
| 222 | break; |
| 223 | } |
| 224 | |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 225 | grpc::string test_name = it->substr(0, colon_pos); |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 226 | int weight = std::stoi(it->substr(colon_pos + 1)); |
| 227 | TestCaseType test_case = GetTestTypeFromName(test_name); |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 228 | if (test_case == UNKNOWN_TEST) { |
| 229 | gpr_log(GPR_ERROR, "Unknown test case: %s", test_name.c_str()); |
| 230 | is_success = false; |
| 231 | break; |
| 232 | } |
| 233 | |
| 234 | tests.emplace_back(std::make_pair(test_case, weight)); |
| 235 | } |
| 236 | |
| 237 | return is_success; |
| 238 | } |
| 239 | |
| 240 | // For debugging purposes |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 241 | void LogParameterInfo(const std::vector<grpc::string>& addresses, |
| 242 | const std::vector<std::pair<TestCaseType, int>>& tests) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 243 | gpr_log(GPR_INFO, "server_addresses: %s", FLAGS_server_addresses.c_str()); |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 244 | gpr_log(GPR_INFO, "server_host: %s", FLAGS_server_host.c_str()); |
| 245 | gpr_log(GPR_INFO, "server_port: %d", FLAGS_server_port); |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 246 | gpr_log(GPR_INFO, "test_cases : %s", FLAGS_test_cases.c_str()); |
| 247 | gpr_log(GPR_INFO, "sleep_duration_ms: %d", FLAGS_sleep_duration_ms); |
| 248 | gpr_log(GPR_INFO, "test_duration_secs: %d", FLAGS_test_duration_secs); |
Sree Kuchibhotla | ad0f792 | 2016-05-04 19:49:31 -0700 | [diff] [blame] | 249 | gpr_log(GPR_INFO, "num_channels_per_server: %d", |
| 250 | FLAGS_num_channels_per_server); |
| 251 | gpr_log(GPR_INFO, "num_stubs_per_channel: %d", FLAGS_num_stubs_per_channel); |
| 252 | gpr_log(GPR_INFO, "log_level: %d", FLAGS_log_level); |
| 253 | gpr_log(GPR_INFO, "do_not_abort_on_transient_failures: %s", |
| 254 | FLAGS_do_not_abort_on_transient_failures ? "true" : "false"); |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 255 | |
| 256 | int num = 0; |
| 257 | for (auto it = addresses.begin(); it != addresses.end(); it++) { |
| 258 | gpr_log(GPR_INFO, "%d:%s", ++num, it->c_str()); |
| 259 | } |
| 260 | |
| 261 | num = 0; |
| 262 | for (auto it = tests.begin(); it != tests.end(); it++) { |
| 263 | TestCaseType test_case = it->first; |
| 264 | int weight = it->second; |
| 265 | gpr_log(GPR_INFO, "%d. TestCaseType: %d, Weight: %d", ++num, test_case, |
| 266 | weight); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | int main(int argc, char** argv) { |
| 271 | grpc::testing::InitTest(&argc, &argv, true); |
| 272 | |
Sree Kuchibhotla | 0fa95ea | 2016-01-06 07:58:10 -0800 | [diff] [blame] | 273 | if (FLAGS_log_level > GPR_LOG_SEVERITY_ERROR || |
| 274 | FLAGS_log_level < GPR_LOG_SEVERITY_DEBUG) { |
| 275 | gpr_log(GPR_ERROR, "log_level should be an integer between %d and %d", |
| 276 | GPR_LOG_SEVERITY_DEBUG, GPR_LOG_SEVERITY_ERROR); |
| 277 | return 1; |
| 278 | } |
| 279 | |
| 280 | // Change the default log function to TestLogFunction which respects the |
| 281 | // log_level setting. |
| 282 | log_level = FLAGS_log_level; |
| 283 | gpr_set_log_function(TestLogFunction); |
| 284 | |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 285 | srand(time(NULL)); |
| 286 | |
| 287 | // Parse the server addresses |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 288 | std::vector<grpc::string> server_addresses; |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 289 | if (FLAGS_server_port != 0) { |
| 290 | // We are using interop_client style cmdline options. |
| 291 | const int host_port_buf_size = 1024; |
| 292 | char host_port[host_port_buf_size]; |
| 293 | snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), |
| 294 | FLAGS_server_port); |
| 295 | std::string host_port_str(host_port); |
| 296 | ParseCommaDelimitedString(host_port_str, server_addresses); |
| 297 | } else { |
| 298 | ParseCommaDelimitedString(FLAGS_server_addresses, server_addresses); |
| 299 | } |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 300 | |
| 301 | // Parse test cases and weights |
| 302 | if (FLAGS_test_cases.length() == 0) { |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 303 | // We are using interop_client style test_case option |
| 304 | FLAGS_test_cases = FLAGS_test_case + ":100"; |
| 305 | } else if (FLAGS_test_case != "") { |
| 306 | gpr_log(GPR_ERROR, "specify --test_case or --test_cases but not both."); |
Sree Kuchibhotla | 117c8af | 2015-10-26 10:59:17 -0700 | [diff] [blame] | 307 | return 1; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 310 | std::vector<std::pair<TestCaseType, int>> tests; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 311 | if (!ParseTestCasesString(FLAGS_test_cases, tests)) { |
| 312 | gpr_log(GPR_ERROR, "Error in parsing test cases string %s ", |
| 313 | FLAGS_test_cases.c_str()); |
| 314 | return 1; |
| 315 | } |
| 316 | |
| 317 | LogParameterInfo(server_addresses, tests); |
| 318 | |
| 319 | WeightedRandomTestSelector test_selector(tests); |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 320 | MetricsServiceImpl metrics_service; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 321 | |
| 322 | gpr_log(GPR_INFO, "Starting test(s).."); |
Sree Kuchibhotla | 728a610 | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 323 | |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 324 | std::vector<grpc::thread> test_threads; |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 325 | |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 326 | // Create and start the test threads. |
| 327 | // Note that: |
| 328 | // - Each server can have multiple channels (as configured by |
| 329 | // FLAGS_num_channels_per_server). |
| 330 | // |
| 331 | // - Each channel can have multiple stubs (as configured by |
| 332 | // FLAGS_num_stubs_per_channel). This is to test calling multiple RPCs in |
| 333 | // parallel on the same channel. |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 334 | int thread_idx = 0; |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 335 | int server_idx = -1; |
| 336 | char buffer[256]; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 337 | for (auto it = server_addresses.begin(); it != server_addresses.end(); it++) { |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 338 | ++server_idx; |
| 339 | // Create channel(s) for each server |
| 340 | for (int channel_idx = 0; channel_idx < FLAGS_num_channels_per_server; |
| 341 | channel_idx++) { |
Makarand Dharmapurikar | f01f7b6 | 2016-10-21 09:07:06 -0700 | [diff] [blame^] | 342 | gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), |
| 343 | channel_idx); |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 344 | std::shared_ptr<grpc::Channel> channel; |
| 345 | if (FLAGS_use_tls) { |
| 346 | channel = grpc::testing::CreateChannelForTestCase(FLAGS_test_case); |
| 347 | } else { |
| 348 | channel = grpc::CreateChannel(*it, grpc::InsecureChannelCredentials()); |
| 349 | } |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 350 | |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 351 | // Create stub(s) for each channel |
| 352 | for (int stub_idx = 0; stub_idx < FLAGS_num_stubs_per_channel; |
| 353 | stub_idx++) { |
| 354 | StressTestInteropClient* client = new StressTestInteropClient( |
| 355 | ++thread_idx, *it, channel, test_selector, FLAGS_test_duration_secs, |
Sree Kuchibhotla | ad0f792 | 2016-05-04 19:49:31 -0700 | [diff] [blame] | 356 | FLAGS_sleep_duration_ms, FLAGS_do_not_abort_on_transient_failures); |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 357 | |
Sree Kuchibhotla | 3714e30 | 2016-04-22 09:50:46 -0700 | [diff] [blame] | 358 | bool is_already_created = false; |
| 359 | // QpsGauge name |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 360 | std::snprintf(buffer, sizeof(buffer), |
| 361 | "/stress_test/server_%d/channel_%d/stub_%d/qps", |
| 362 | server_idx, channel_idx, stub_idx); |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 363 | |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 364 | test_threads.emplace_back(grpc::thread( |
| 365 | &StressTestInteropClient::MainLoop, client, |
Sree Kuchibhotla | 3714e30 | 2016-04-22 09:50:46 -0700 | [diff] [blame] | 366 | metrics_service.CreateQpsGauge(buffer, &is_already_created))); |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 367 | |
Sree Kuchibhotla | 3714e30 | 2016-04-22 09:50:46 -0700 | [diff] [blame] | 368 | // The QpsGauge should not have been already created |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 369 | GPR_ASSERT(!is_already_created); |
| 370 | } |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 371 | } |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 374 | // Start metrics server before waiting for the stress test threads |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 375 | if (FLAGS_metrics_port > 0) { |
| 376 | std::unique_ptr<grpc::Server> metrics_server = |
| 377 | metrics_service.StartServer(FLAGS_metrics_port); |
| 378 | } |
| 379 | |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 380 | // Wait for the stress test threads to complete |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 381 | for (auto it = test_threads.begin(); it != test_threads.end(); it++) { |
| 382 | it->join(); |
| 383 | } |
| 384 | |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 385 | return 0; |
| 386 | } |