#include <memory>
#include <mutex>
+#include <thread>
#include <grpc/grpc.h>
#include <grpc/support/time.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/slice.h>
+#include "absl/memory/memory.h"
+
#include "src/cpp/common/channel_filter.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"
using grpc::testing::EchoRequest;
using grpc::testing::EchoResponse;
-using std::chrono::system_clock;
namespace grpc {
namespace testing {
class ChannelDataImpl : public ChannelData {
public:
- grpc_error* Init(grpc_channel_element* elem,
- grpc_channel_element_args* args) {
+ grpc_error* Init(grpc_channel_element* /*elem*/,
+ grpc_channel_element_args* /*args*/) override {
IncrementConnectionCounter();
return GRPC_ERROR_NONE;
}
bool ignored_ok;
cli_cq_.Shutdown();
srv_cq_->Shutdown();
- while (cli_cq_.Next(&ignored_tag, &ignored_ok))
- ;
- while (srv_cq_->Next(&ignored_tag, &ignored_ok))
- ;
+ while (cli_cq_.Next(&ignored_tag, &ignored_ok)) {
+ }
+ while (srv_cq_->Next(&ignored_tag, &ignored_ok)) {
+ }
}
void ResetStub() {
std::shared_ptr<Channel> channel = grpc::CreateChannel(
server_address_.str(), InsecureChannelCredentials());
- generic_stub_.reset(new GenericStub(channel));
+ generic_stub_ = absl::make_unique<GenericStub>(channel);
ResetConnectionCounter();
ResetCallCounter();
}
void client_fail(int i) { verify_ok(&cli_cq_, i, false); }
void SendRpc(int num_rpcs) {
- const grpc::string kMethodName("/grpc.cpp.test.util.EchoTestService/Echo");
+ const std::string kMethodName("/grpc.cpp.test.util.EchoTestService/Echo");
for (int i = 0; i < num_rpcs; i++) {
EchoRequest send_request;
EchoRequest recv_request;
// The string needs to be long enough to test heap-based slice.
send_request.set_message("Hello world. Hello world. Hello world.");
+ std::thread request_call([this]() { server_ok(4); });
std::unique_ptr<GenericClientAsyncReaderWriter> call =
generic_stub_->PrepareCall(&cli_ctx, kMethodName, &cli_cq_);
call->StartCall(tag(1));
generic_service_.RequestCall(&srv_ctx, &stream, srv_cq_.get(),
srv_cq_.get(), tag(4));
- verify_ok(srv_cq_.get(), 4, true);
+ request_call.join();
EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
EXPECT_EQ(kMethodName, srv_ctx.method());
ByteBuffer recv_buffer;
std::unique_ptr<grpc::GenericStub> generic_stub_;
std::unique_ptr<Server> server_;
AsyncGenericService generic_service_;
- const grpc::string server_host_;
+ const std::string server_host_;
std::ostringstream server_address_;
};
EXPECT_EQ(0, GetConnectionCounterValue());
EXPECT_EQ(0, GetCallCounterValue());
- const grpc::string kMethodName(
+ const std::string kMethodName(
"/grpc.cpp.test.util.EchoTestService/BidiStream");
EchoRequest send_request;
EchoRequest recv_request;
cli_ctx.set_compression_algorithm(GRPC_COMPRESS_GZIP);
send_request.set_message("Hello");
+ std::thread request_call([this]() { server_ok(2); });
std::unique_ptr<GenericClientAsyncReaderWriter> cli_stream =
generic_stub_->PrepareCall(&cli_ctx, kMethodName, &cli_cq_);
cli_stream->StartCall(tag(1));
generic_service_.RequestCall(&srv_ctx, &srv_stream, srv_cq_.get(),
srv_cq_.get(), tag(2));
- verify_ok(srv_cq_.get(), 2, true);
+ request_call.join();
EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
EXPECT_EQ(kMethodName, srv_ctx.method());