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> |
David Garcia Quintas | c79b065 | 2016-07-27 21:11:58 -0700 | [diff] [blame] | 43 | #include <grpc/support/log.h> |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 44 | #include <grpc/support/time.h> |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 45 | |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 46 | #include "src/proto/grpc/testing/metrics.grpc.pb.h" |
| 47 | #include "src/proto/grpc/testing/metrics.pb.h" |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 48 | #include "test/cpp/interop/interop_client.h" |
| 49 | #include "test/cpp/interop/stress_interop_client.h" |
ncteisen | 9c7a08d | 2017-01-17 16:26:40 -0800 | [diff] [blame] | 50 | #include "test/cpp/util/create_test_channel.h" |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 51 | #include "test/cpp/util/metrics_server.h" |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 52 | #include "test/cpp/util/test_config.h" |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 53 | |
Sree Kuchibhotla | 0fa95ea | 2016-01-06 07:58:10 -0800 | [diff] [blame] | 54 | extern "C" { |
| 55 | extern void gpr_default_log(gpr_log_func_args* args); |
| 56 | } |
| 57 | |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 58 | DEFINE_int32(metrics_port, 8081, "The metrics server port."); |
| 59 | |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 60 | DEFINE_int32(sleep_duration_ms, 0, |
| 61 | "The duration (in millisec) between two" |
| 62 | " consecutive test calls (per server) issued by the server."); |
| 63 | |
| 64 | DEFINE_int32(test_duration_secs, -1, |
| 65 | "The length of time (in seconds) to run" |
| 66 | " the test. Enter -1 if the test should run continuously until" |
| 67 | " forcefully terminated."); |
| 68 | |
| 69 | DEFINE_string(server_addresses, "localhost:8080", |
ncteisen | 9c7a08d | 2017-01-17 16:26:40 -0800 | [diff] [blame] | 70 | "The list of server addresses. The format is: \n" |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 71 | " \"<name_1>:<port_1>,<name_2>:<port_1>...<name_N>:<port_N>\"\n" |
| 72 | " Note: <name> can be servername or IP address."); |
| 73 | |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 74 | DEFINE_int32(num_channels_per_server, 1, "Number of channels for each server"); |
| 75 | |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 76 | DEFINE_int32(num_stubs_per_channel, 1, |
| 77 | "Number of stubs per each channels to server. This number also " |
| 78 | "indicates the max number of parallel RPC calls on each channel " |
| 79 | "at any given time."); |
| 80 | |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 81 | // TODO(sreek): Add more test cases here in future |
| 82 | DEFINE_string(test_cases, "", |
| 83 | "List of test cases to call along with the" |
| 84 | " relative weights in the following format:\n" |
| 85 | " \"<testcase_1:w_1>,<testcase_2:w_2>...<testcase_n:w_n>\"\n" |
| 86 | " The following testcases are currently supported:\n" |
| 87 | " empty_unary\n" |
| 88 | " large_unary\n" |
| 89 | " large_compressed_unary\n" |
| 90 | " client_streaming\n" |
| 91 | " server_streaming\n" |
Sree Kuchibhotla | 5130427 | 2016-05-05 15:19:00 -0700 | [diff] [blame] | 92 | " server_compressed_streaming\n" |
| 93 | " slow_consumer\n" |
| 94 | " half_duplex\n" |
| 95 | " ping_pong\n" |
| 96 | " cancel_after_begin\n" |
| 97 | " cancel_after_first_response\n" |
| 98 | " timeout_on_sleeping_server\n" |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 99 | " empty_stream\n" |
Sree Kuchibhotla | 5130427 | 2016-05-05 15:19:00 -0700 | [diff] [blame] | 100 | " status_code_and_message\n" |
| 101 | " custom_metadata\n" |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 102 | " Example: \"empty_unary:20,large_unary:10,empty_stream:70\"\n" |
| 103 | " The above will execute 'empty_unary', 20% of the time," |
| 104 | " 'large_unary', 10% of the time and 'empty_stream' the remaining" |
| 105 | " 70% of the time"); |
| 106 | |
Sree Kuchibhotla | 16dd3e4 | 2016-03-31 09:46:20 -0700 | [diff] [blame] | 107 | DEFINE_int32(log_level, GPR_LOG_SEVERITY_INFO, |
Sree Kuchibhotla | 0fa95ea | 2016-01-06 07:58:10 -0800 | [diff] [blame] | 108 | "Severity level of messages that should be logged. Any messages " |
| 109 | "greater than or equal to the level set here will be logged. " |
| 110 | "The choices are: 0 (GPR_LOG_SEVERITY_DEBUG), 1 " |
Sree Kuchibhotla | 16dd3e4 | 2016-03-31 09:46:20 -0700 | [diff] [blame] | 111 | "(GPR_LOG_SEVERITY_INFO) and 2 (GPR_LOG_SEVERITY_ERROR)"); |
Sree Kuchibhotla | 0fa95ea | 2016-01-06 07:58:10 -0800 | [diff] [blame] | 112 | |
Sree Kuchibhotla | ad0f792 | 2016-05-04 19:49:31 -0700 | [diff] [blame] | 113 | DEFINE_bool(do_not_abort_on_transient_failures, true, |
| 114 | "If set to 'true', abort() is not called in case of transient " |
| 115 | "failures like temporary connection failures."); |
| 116 | |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 117 | // Options from client.cc (for compatibility with interop test). |
| 118 | // TODO(sreek): Consolidate overlapping options |
| 119 | DEFINE_bool(use_tls, false, "Whether to use tls."); |
| 120 | DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 121 | DEFINE_string(server_host_override, "foo.test.google.fr", |
| 122 | "Override the server host which is sent in HTTP header"); |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 123 | |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 124 | using grpc::testing::kTestCaseList; |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 125 | using grpc::testing::MetricsService; |
| 126 | using grpc::testing::MetricsServiceImpl; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 127 | using grpc::testing::StressTestInteropClient; |
| 128 | using grpc::testing::TestCaseType; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 129 | using grpc::testing::UNKNOWN_TEST; |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 130 | using grpc::testing::WeightedRandomTestSelector; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 131 | |
Sree Kuchibhotla | 0fa95ea | 2016-01-06 07:58:10 -0800 | [diff] [blame] | 132 | static int log_level = GPR_LOG_SEVERITY_DEBUG; |
| 133 | |
| 134 | // A simple wrapper to grp_default_log() function. This only logs messages at or |
| 135 | // above the current log level (set in 'log_level' variable) |
| 136 | void TestLogFunction(gpr_log_func_args* args) { |
| 137 | if (args->severity >= log_level) { |
| 138 | gpr_default_log(args); |
| 139 | } |
| 140 | } |
| 141 | |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 142 | TestCaseType GetTestTypeFromName(const grpc::string& test_name) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 143 | TestCaseType test_case = UNKNOWN_TEST; |
| 144 | |
| 145 | for (auto it = kTestCaseList.begin(); it != kTestCaseList.end(); it++) { |
| 146 | if (test_name == it->second) { |
| 147 | test_case = it->first; |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return test_case; |
| 153 | } |
| 154 | |
| 155 | // Converts a string of comma delimited tokens to a vector of tokens |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 156 | bool ParseCommaDelimitedString(const grpc::string& comma_delimited_str, |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 157 | std::vector<grpc::string>& tokens) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 158 | size_t bpos = 0; |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 159 | size_t epos = grpc::string::npos; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 160 | |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 161 | while ((epos = comma_delimited_str.find(',', bpos)) != grpc::string::npos) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 162 | tokens.emplace_back(comma_delimited_str.substr(bpos, epos - bpos)); |
| 163 | bpos = epos + 1; |
| 164 | } |
| 165 | |
| 166 | tokens.emplace_back(comma_delimited_str.substr(bpos)); // Last token |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | // Input: Test case string "<testcase_name:weight>,<testcase_name:weight>...." |
| 171 | // Output: |
| 172 | // - Whether parsing was successful (return value) |
| 173 | // - Vector of (test_type_enum, weight) pairs returned via 'tests' parameter |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 174 | bool ParseTestCasesString(const grpc::string& test_cases, |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 175 | std::vector<std::pair<TestCaseType, int>>& tests) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 176 | bool is_success = true; |
| 177 | |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 178 | std::vector<grpc::string> tokens; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 179 | ParseCommaDelimitedString(test_cases, tokens); |
| 180 | |
| 181 | for (auto it = tokens.begin(); it != tokens.end(); it++) { |
| 182 | // Token is in the form <test_name>:<test_weight> |
| 183 | size_t colon_pos = it->find(':'); |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 184 | if (colon_pos == grpc::string::npos) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 185 | gpr_log(GPR_ERROR, "Error in parsing test case string: %s", it->c_str()); |
| 186 | is_success = false; |
| 187 | break; |
| 188 | } |
| 189 | |
Sree Kuchibhotla | f51ea7a | 2015-10-26 13:34:41 -0700 | [diff] [blame] | 190 | grpc::string test_name = it->substr(0, colon_pos); |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 191 | int weight = std::stoi(it->substr(colon_pos + 1)); |
| 192 | TestCaseType test_case = GetTestTypeFromName(test_name); |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 193 | if (test_case == UNKNOWN_TEST) { |
| 194 | gpr_log(GPR_ERROR, "Unknown test case: %s", test_name.c_str()); |
| 195 | is_success = false; |
| 196 | break; |
| 197 | } |
| 198 | |
| 199 | tests.emplace_back(std::make_pair(test_case, weight)); |
| 200 | } |
| 201 | |
| 202 | return is_success; |
| 203 | } |
| 204 | |
| 205 | // For debugging purposes |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 206 | void LogParameterInfo(const std::vector<grpc::string>& addresses, |
| 207 | const std::vector<std::pair<TestCaseType, int>>& tests) { |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 208 | gpr_log(GPR_INFO, "server_addresses: %s", FLAGS_server_addresses.c_str()); |
| 209 | gpr_log(GPR_INFO, "test_cases : %s", FLAGS_test_cases.c_str()); |
| 210 | gpr_log(GPR_INFO, "sleep_duration_ms: %d", FLAGS_sleep_duration_ms); |
| 211 | gpr_log(GPR_INFO, "test_duration_secs: %d", FLAGS_test_duration_secs); |
Sree Kuchibhotla | ad0f792 | 2016-05-04 19:49:31 -0700 | [diff] [blame] | 212 | gpr_log(GPR_INFO, "num_channels_per_server: %d", |
| 213 | FLAGS_num_channels_per_server); |
| 214 | gpr_log(GPR_INFO, "num_stubs_per_channel: %d", FLAGS_num_stubs_per_channel); |
| 215 | gpr_log(GPR_INFO, "log_level: %d", FLAGS_log_level); |
| 216 | gpr_log(GPR_INFO, "do_not_abort_on_transient_failures: %s", |
| 217 | FLAGS_do_not_abort_on_transient_failures ? "true" : "false"); |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 218 | |
| 219 | int num = 0; |
| 220 | for (auto it = addresses.begin(); it != addresses.end(); it++) { |
| 221 | gpr_log(GPR_INFO, "%d:%s", ++num, it->c_str()); |
| 222 | } |
| 223 | |
| 224 | num = 0; |
| 225 | for (auto it = tests.begin(); it != tests.end(); it++) { |
| 226 | TestCaseType test_case = it->first; |
| 227 | int weight = it->second; |
| 228 | gpr_log(GPR_INFO, "%d. TestCaseType: %d, Weight: %d", ++num, test_case, |
| 229 | weight); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | int main(int argc, char** argv) { |
| 234 | grpc::testing::InitTest(&argc, &argv, true); |
| 235 | |
Sree Kuchibhotla | 0fa95ea | 2016-01-06 07:58:10 -0800 | [diff] [blame] | 236 | if (FLAGS_log_level > GPR_LOG_SEVERITY_ERROR || |
| 237 | FLAGS_log_level < GPR_LOG_SEVERITY_DEBUG) { |
| 238 | gpr_log(GPR_ERROR, "log_level should be an integer between %d and %d", |
| 239 | GPR_LOG_SEVERITY_DEBUG, GPR_LOG_SEVERITY_ERROR); |
| 240 | return 1; |
| 241 | } |
| 242 | |
| 243 | // Change the default log function to TestLogFunction which respects the |
| 244 | // log_level setting. |
| 245 | log_level = FLAGS_log_level; |
| 246 | gpr_set_log_function(TestLogFunction); |
| 247 | |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 248 | srand(time(NULL)); |
| 249 | |
| 250 | // Parse the server addresses |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 251 | std::vector<grpc::string> server_addresses; |
ncteisen | 9c7a08d | 2017-01-17 16:26:40 -0800 | [diff] [blame] | 252 | ParseCommaDelimitedString(FLAGS_server_addresses, server_addresses); |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 253 | |
| 254 | // Parse test cases and weights |
| 255 | if (FLAGS_test_cases.length() == 0) { |
ncteisen | 9c7a08d | 2017-01-17 16:26:40 -0800 | [diff] [blame] | 256 | gpr_log(GPR_ERROR, "No test cases supplied"); |
Sree Kuchibhotla | 117c8af | 2015-10-26 10:59:17 -0700 | [diff] [blame] | 257 | return 1; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Sree Kuchibhotla | b047c0f | 2015-11-16 11:52:54 -0800 | [diff] [blame] | 260 | std::vector<std::pair<TestCaseType, int>> tests; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 261 | if (!ParseTestCasesString(FLAGS_test_cases, tests)) { |
| 262 | gpr_log(GPR_ERROR, "Error in parsing test cases string %s ", |
| 263 | FLAGS_test_cases.c_str()); |
| 264 | return 1; |
| 265 | } |
| 266 | |
| 267 | LogParameterInfo(server_addresses, tests); |
| 268 | |
| 269 | WeightedRandomTestSelector test_selector(tests); |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 270 | MetricsServiceImpl metrics_service; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 271 | |
| 272 | gpr_log(GPR_INFO, "Starting test(s).."); |
Sree Kuchibhotla | 728a610 | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 273 | |
Vijay Pai | 320ed13 | 2016-11-01 17:16:55 -0700 | [diff] [blame] | 274 | std::vector<std::thread> test_threads; |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 275 | |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 276 | // Create and start the test threads. |
| 277 | // Note that: |
| 278 | // - Each server can have multiple channels (as configured by |
| 279 | // FLAGS_num_channels_per_server). |
| 280 | // |
| 281 | // - Each channel can have multiple stubs (as configured by |
| 282 | // FLAGS_num_stubs_per_channel). This is to test calling multiple RPCs in |
| 283 | // parallel on the same channel. |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 284 | int thread_idx = 0; |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 285 | int server_idx = -1; |
| 286 | char buffer[256]; |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 287 | for (auto it = server_addresses.begin(); it != server_addresses.end(); it++) { |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 288 | ++server_idx; |
| 289 | // Create channel(s) for each server |
| 290 | for (int channel_idx = 0; channel_idx < FLAGS_num_channels_per_server; |
| 291 | channel_idx++) { |
Makarand Dharmapurikar | f01f7b6 | 2016-10-21 09:07:06 -0700 | [diff] [blame] | 292 | gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), |
| 293 | channel_idx); |
ncteisen | 9c7a08d | 2017-01-17 16:26:40 -0800 | [diff] [blame] | 294 | std::shared_ptr<grpc::Channel> channel = grpc::CreateTestChannel( |
| 295 | *it, FLAGS_server_host_override, FLAGS_use_tls, !FLAGS_use_test_ca); |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 296 | |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 297 | // Create stub(s) for each channel |
| 298 | for (int stub_idx = 0; stub_idx < FLAGS_num_stubs_per_channel; |
| 299 | stub_idx++) { |
| 300 | StressTestInteropClient* client = new StressTestInteropClient( |
| 301 | ++thread_idx, *it, channel, test_selector, FLAGS_test_duration_secs, |
Sree Kuchibhotla | ad0f792 | 2016-05-04 19:49:31 -0700 | [diff] [blame] | 302 | FLAGS_sleep_duration_ms, FLAGS_do_not_abort_on_transient_failures); |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 303 | |
Sree Kuchibhotla | 3714e30 | 2016-04-22 09:50:46 -0700 | [diff] [blame] | 304 | bool is_already_created = false; |
| 305 | // QpsGauge name |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 306 | std::snprintf(buffer, sizeof(buffer), |
| 307 | "/stress_test/server_%d/channel_%d/stub_%d/qps", |
| 308 | server_idx, channel_idx, stub_idx); |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 309 | |
Vijay Pai | 320ed13 | 2016-11-01 17:16:55 -0700 | [diff] [blame] | 310 | test_threads.emplace_back(std::thread( |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 311 | &StressTestInteropClient::MainLoop, client, |
Sree Kuchibhotla | 3714e30 | 2016-04-22 09:50:46 -0700 | [diff] [blame] | 312 | metrics_service.CreateQpsGauge(buffer, &is_already_created))); |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 313 | |
Sree Kuchibhotla | 3714e30 | 2016-04-22 09:50:46 -0700 | [diff] [blame] | 314 | // The QpsGauge should not have been already created |
Sree Kuchibhotla | e1330ff | 2015-11-20 09:53:44 -0800 | [diff] [blame] | 315 | GPR_ASSERT(!is_already_created); |
| 316 | } |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 317 | } |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 320 | // Start metrics server before waiting for the stress test threads |
Sree Kuchibhotla | 7eef316 | 2016-12-16 11:30:35 -0800 | [diff] [blame] | 321 | std::unique_ptr<grpc::Server> metrics_server; |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 322 | if (FLAGS_metrics_port > 0) { |
Sree Kuchibhotla | 7eef316 | 2016-12-16 11:30:35 -0800 | [diff] [blame] | 323 | metrics_server = metrics_service.StartServer(FLAGS_metrics_port); |
Makarand Dharmapurikar | e3dd1d7 | 2016-10-20 10:37:39 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Sree Kuchibhotla | b5e98c5 | 2015-10-27 22:55:26 -0700 | [diff] [blame] | 326 | // Wait for the stress test threads to complete |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 327 | for (auto it = test_threads.begin(); it != test_threads.end(); it++) { |
| 328 | it->join(); |
| 329 | } |
| 330 | |
Sree Kuchibhotla | fbc376f | 2015-10-16 10:56:31 -0700 | [diff] [blame] | 331 | return 0; |
| 332 | } |