#include <random>
#include <thread>
+#include "absl/memory/memory.h"
+
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/gpr/env.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
namespace {
struct TestScenario {
- TestScenario(const grpc::string& creds_type, const grpc::string& content)
+ TestScenario(const std::string& creds_type, const std::string& content)
: credentials_type(creds_type), message_content(content) {}
- const grpc::string credentials_type;
- const grpc::string message_content;
+ const std::string credentials_type;
+ const std::string message_content;
};
class FlakyNetworkTest : public ::testing::TestWithParam<TestScenario> {
// ip6-looopback, but ipv6 support is not enabled by default in docker.
port_ = SERVER_PORT;
- server_.reset(new ServerData(port_, GetParam().credentials_type));
+ server_ = absl::make_unique<ServerData>(port_, GetParam().credentials_type);
server_->Start(server_host_);
}
void StopServer() { server_->Shutdown(); }
}
std::shared_ptr<Channel> BuildChannel(
- const grpc::string& lb_policy_name,
+ const std::string& lb_policy_name,
ChannelArguments args = ChannelArguments()) {
- if (lb_policy_name.size() > 0) {
+ if (!lb_policy_name.empty()) {
args.SetLoadBalancingPolicyName(lb_policy_name);
} // else, default to pick first
auto channel_creds = GetCredentialsProvider()->GetChannelCredentials(
bool SendRpc(
const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub,
int timeout_ms = 0, bool wait_for_ready = false) {
- auto response = std::unique_ptr<EchoResponse>(new EchoResponse());
+ auto response = absl::make_unique<EchoResponse>();
EchoRequest request;
auto& msg = GetParam().message_content;
request.set_message(msg);
ClientContext context;
if (timeout_ms > 0) {
context.set_deadline(grpc_timeout_milliseconds_to_deadline(timeout_ms));
+ // Allow an RPC to be canceled (for deadline exceeded) after it has
+ // reached the server.
+ request.mutable_param()->set_skip_cancelled_check(true);
}
// See https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md for
// details of wait-for-ready semantics
struct ServerData {
int port_;
- const grpc::string creds_;
+ const std::string creds_;
std::unique_ptr<Server> server_;
TestServiceImpl service_;
std::unique_ptr<std::thread> thread_;
bool server_ready_ = false;
- ServerData(int port, const grpc::string& creds)
+ ServerData(int port, const std::string& creds)
: port_(port), creds_(creds) {}
- void Start(const grpc::string& server_host) {
+ void Start(const std::string& server_host) {
gpr_log(GPR_INFO, "starting server on port %d", port_);
std::mutex mu;
std::unique_lock<std::mutex> lock(mu);
std::condition_variable cond;
- thread_.reset(new std::thread(
- std::bind(&ServerData::Serve, this, server_host, &mu, &cond)));
+ thread_ = absl::make_unique<std::thread>(
+ std::bind(&ServerData::Serve, this, server_host, &mu, &cond));
cond.wait(lock, [this] { return server_ready_; });
server_ready_ = false;
gpr_log(GPR_INFO, "server startup complete");
}
- void Serve(const grpc::string& server_host, std::mutex* mu,
+ void Serve(const std::string& server_host, std::mutex* mu,
std::condition_variable* cond) {
std::ostringstream server_address;
server_address << server_host << ":" << port_;
}
private:
- const grpc::string server_host_;
- const grpc::string interface_;
- const grpc::string ipv4_address_;
- const grpc::string netmask_;
+ const std::string server_host_;
+ const std::string interface_;
+ const std::string ipv4_address_;
+ const std::string netmask_;
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_;
std::unique_ptr<ServerData> server_;
const int SERVER_PORT = 32750;
std::vector<TestScenario> CreateTestScenarios() {
std::vector<TestScenario> scenarios;
- std::vector<grpc::string> credentials_types;
- std::vector<grpc::string> messages;
+ std::vector<std::string> credentials_types;
+ std::vector<std::string> messages;
credentials_types.push_back(kInsecureCredentialsType);
auto sec_list = GetCredentialsProvider()->GetSecureCredentialsTypeList();
messages.push_back("🖖");
for (size_t k = 1; k < GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH / 1024; k *= 32) {
- grpc::string big_msg;
+ std::string big_msg;
for (size_t i = 0; i < k * 1024; ++i) {
char c = 'a' + (i % 26);
big_msg += c;