From 75bfb9754827ef63ede77e27ad901e3355536419 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 11 Apr 2017 17:55:12 -0700 Subject: Finish hybrid server stuff, ensure it gets tested --- test/cpp/end2end/async_end2end_test.cc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'test/cpp') diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 0b5215ef8e..cc3958bf13 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,7 @@ #include #include "src/core/lib/iomgr/port.h" +#include "src/proto/grpc/health/v1/health.grpc.pb.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -224,13 +226,15 @@ class ServerBuilderSyncPluginDisabler : public ::grpc::ServerBuilderOption { class TestScenario { public: - TestScenario(bool non_block, const grpc::string& creds_type, + TestScenario(bool non_block, const grpc::string& creds_type, bool hcs, const grpc::string& content) : disable_blocking(non_block), + health_check_service(hcs), credentials_type(creds_type), message_content(content) {} void Log() const; bool disable_blocking; + bool health_check_service; // Although the below grpc::string's are logically const, we can't declare // them const because of a limitation in the way old compilers (e.g., gcc-4.4) // manage vector insertion using a copy constructor @@ -243,6 +247,8 @@ static std::ostream& operator<<(std::ostream& out, return out << "TestScenario{disable_blocking=" << (scenario.disable_blocking ? "true" : "false") << ", credentials='" << scenario.credentials_type + << ", health_check_service=" + << (scenario.health_check_service ? "true" : "false") << "', message_size=" << scenario.message_content.size() << "}"; } @@ -252,6 +258,8 @@ void TestScenario::Log() const { gpr_log(GPR_DEBUG, "%s", out.str().c_str()); } +class HealthCheck : public health::v1::Health::Service {}; + class AsyncEnd2endTest : public ::testing::TestWithParam { protected: AsyncEnd2endTest() { GetParam().Log(); } @@ -268,6 +276,9 @@ class AsyncEnd2endTest : public ::testing::TestWithParam { GetParam().credentials_type); builder.AddListeningPort(server_address_.str(), server_creds); builder.RegisterService(&service_); + if (GetParam().health_check_service) { + builder.RegisterService(&health_check_); + } cq_ = builder.AddCompletionQueue(); // TODO(zyc): make a test option to choose wheather sync plugins should be @@ -340,6 +351,7 @@ class AsyncEnd2endTest : public ::testing::TestWithParam { std::unique_ptr stub_; std::unique_ptr server_; grpc::testing::EchoTestService::AsyncService service_; + HealthCheck health_check_; std::ostringstream server_address_; int port_; @@ -1754,12 +1766,14 @@ std::vector CreateTestScenarios(bool test_disable_blocking, messages.push_back(big_msg); } - for (auto cred = credentials_types.begin(); cred != credentials_types.end(); - ++cred) { - for (auto msg = messages.begin(); msg != messages.end(); msg++) { - scenarios.emplace_back(false, *cred, *msg); - if (test_disable_blocking) { - scenarios.emplace_back(true, *cred, *msg); + for (auto health_check_service : {false, true}) { + for (auto cred = credentials_types.begin(); cred != credentials_types.end(); + ++cred) { + for (auto msg = messages.begin(); msg != messages.end(); msg++) { + scenarios.emplace_back(false, *cred, health_check_service, *msg); + if (test_disable_blocking) { + scenarios.emplace_back(true, *cred, health_check_service, *msg); + } } } } -- cgit v1.2.3 From 31d92d42ff8493fc0a9eb419ff662e4e5244096b Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sat, 8 Apr 2017 15:43:07 -0700 Subject: Initial commit: Auto-generate GMOCK code for client stub. --- Makefile | 7 +- build.yaml | 1 + include/grpc++/test/mock_stream.h | 128 ++++++++++++++++++++++++++ src/compiler/cpp_generator.cc | 184 ++++++++++++++++++++++++++++++++++++++ src/compiler/cpp_generator.h | 12 +++ src/compiler/cpp_plugin.cc | 10 +++ test/cpp/end2end/mock_test.cc | 142 ++++++++--------------------- 7 files changed, 378 insertions(+), 106 deletions(-) create mode 100644 include/grpc++/test/mock_stream.h (limited to 'test/cpp') diff --git a/Makefile b/Makefile index 02840b3c26..4d12b95238 100644 --- a/Makefile +++ b/Makefile @@ -409,8 +409,9 @@ AROPTS = $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little USE_BUILT_PROTOC = false endif -GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc +GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googlemock third_party/googletest/googlemock/src/gmock-all.cc GTEST_LIB += -lgflags + ifeq ($(V),1) E = @: Q = @@ -784,7 +785,7 @@ PROTOBUF_PKG_CONFIG = false PC_REQUIRES_GRPCXX = PC_LIBS_GRPCXX = -CPPFLAGS := -Ithird_party/googletest/googletest/include $(CPPFLAGS) +CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS) PROTOC_PLUGINS_ALL = $(BINDIR)/$(CONFIG)/grpc_cpp_plugin $(BINDIR)/$(CONFIG)/grpc_csharp_plugin $(BINDIR)/$(CONFIG)/grpc_node_plugin $(BINDIR)/$(CONFIG)/grpc_objective_c_plugin $(BINDIR)/$(CONFIG)/grpc_php_plugin $(BINDIR)/$(CONFIG)/grpc_python_plugin $(BINDIR)/$(CONFIG)/grpc_ruby_plugin PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG) @@ -15198,7 +15199,7 @@ else $(BINDIR)/$(CONFIG)/mock_test: $(PROTOBUF_DEP) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/mock_test + $(Q) $(LDXX) $(LDFLAGS) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/mock_test endif diff --git a/build.yaml b/build.yaml index 414950cd6f..d4b50b2599 100644 --- a/build.yaml +++ b/build.yaml @@ -949,6 +949,7 @@ filegroups: language: c++ public_headers: - include/grpc++/test/server_context_test_spouse.h + - include/grpc++/test/mock_stream.h deps: - grpc++ - name: thrift_util diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h new file mode 100644 index 0000000000..f99a1b1128 --- /dev/null +++ b/include/grpc++/test/mock_stream.h @@ -0,0 +1,128 @@ +#ifndef NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ +#define NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ + +#include + +#include +#include +#include +#include +#include + +namespace grpc { +namespace testing { + +template +class MockClientReader : public ClientReaderInterface { + public: + MockClientReader() = default; + + // ClientStreamingInterface + MOCK_METHOD0_T(Finish, Status()); + + // ReaderInterface + MOCK_METHOD1_T(NextMessageSize, bool(uint32_t*)); + MOCK_METHOD1_T(Read, bool(R*)); + + // ClientReaderInterface + MOCK_METHOD0_T(WaitForInitialMetadata, void()); +}; + +template +class MockClientWriter : public ClientWriterInterface { + public: + MockClientWriter() = default; + + // ClientStreamingInterface + MOCK_METHOD0_T(Finish, Status()); + + // WriterInterface + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions&)); + + // ClientWriterInterface + MOCK_METHOD0_T(WritesDone, bool()); +}; + +template +class MockClientReaderWriter : public ClientReaderWriterInterface { + public: + MockClientReaderWriter() = default; + + // ClientStreamingInterface + MOCK_METHOD0_T(Finish, Status()); + + // ReaderInterface + MOCK_METHOD1_T(NextMessageSize, bool(uint32_t*)); + MOCK_METHOD1_T(Read, bool(R*)); + + // WriterInterface + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions)); + + // ClientReaderWriterInterface + MOCK_METHOD0_T(WaitForInitialMetadata, void()); + MOCK_METHOD0_T(WritesDone, bool()); +}; + +template +class MockClientAsyncResponseReader + : public ClientAsyncResponseReaderInterface { + public: + MockClientAsyncResponseReader() = default; + + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD3_T(Finish, void(R*, Status*, void*)); +}; + +template +class MockClientAsyncReader : public ClientAsyncReaderInterface { + public: + MockClientAsyncReader() = default; + + // ClientAsyncStreamingInterface + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD2_T(Finish, void(Status*, void*)); + + // AsyncReaderInterface + MOCK_METHOD2_T(Read, void(R*, void*)); +}; + +template +class MockClientAsyncWriter : public ClientAsyncWriterInterface { + public: + MockClientAsyncWriter() = default; + + // ClientAsyncStreamingInterface + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD2_T(Finish, void(Status*, void*)); + + // AsyncWriterInterface + MOCK_METHOD2_T(Write, void(const W&, void*)); + + // ClientAsyncWriterInterface + MOCK_METHOD1_T(WritesDone, void(void*)); +}; + +template +class MockClientAsyncReaderWriter + : public ClientAsyncReaderWriterInterface { + public: + MockClientAsyncReaderWriter() = default; + + // ClientAsyncStreamingInterface + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD2_T(Finish, void(Status*, void*)); + + // AsyncWriterInterface + MOCK_METHOD2_T(Write, void(const W&, void*)); + + // AsyncReaderInterface + MOCK_METHOD2_T(Read, void(R*, void*)); + + // ClientAsyncReaderWriterInterface + MOCK_METHOD1_T(WritesDone, void(void*)); +}; + +} // namespace testing +} // namespace grpc + +#endif // NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index c01e830cd6..400627ecca 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1407,4 +1407,188 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file, return temp; } +// TODO(mmukhi): Make sure we need parameters or not. +grpc::string GetMockPrologue(File *file, const Parameters & ) { + grpc::string output; + { + // Scope the output stream so it closes and finalizes output to the string. + auto printer = file->CreatePrinter(&output); + std::map vars; + + vars["filename"] = file->filename(); + vars["filename_base"] = file->filename_without_ext(); + vars["message_header_ext"] = file->message_header_ext(); + vars["service_header_ext"] = file->service_header_ext(); + + printer->Print(vars, "// Generated by the gRPC C++ plugin.\n"); + printer->Print(vars, + "// If you make any local change, they will be lost.\n"); + printer->Print(vars, "// source: $filename$\n\n"); + + printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n"); + printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n"); + printer->Print(vars, file->additional_headers().c_str()); + printer->Print(vars, "\n"); + } + return output; +} + +// TODO(mmukhi): Add client-stream and completion-queue headers. +grpc::string GetMockIncludes(File *file, const Parameters ¶ms) { + grpc::string output; + { + // Scope the output stream so it closes and finalizes output to the string. + auto printer = file->CreatePrinter(&output); + std::map vars; + + static const char *headers_strs[] = { + "grpc++/impl/codegen/async_stream.h", + "grpc++/impl/codegen/sync_stream.h", + "gmock/gmock.h", + }; + std::vector headers(headers_strs, array_end(headers_strs)); + PrintIncludes(printer.get(), headers, params); + + if (!file->package().empty()) { + std::vector parts = file->package_parts(); + + for(auto part = parts.begin(); part != parts.end(); part++) { + vars["part"] = *part; + printer->Print(vars, "namespace $part$ {\n"); + } + } + + printer->Print(vars, "\n"); + } + return output; +} + +void PrintMockClientMethods( + Printer *printer, const Method *method, + std::map *vars) { + (*vars)["Method"] = method->name(); + (*vars)["Request"] = method->input_type_name(); + (*vars)["Response"] = method->output_type_name(); + + if (method->NoStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD3($Method$, ::grpc::Status(::grpc::ClientContext* context, " + "const $Request$& request, $Response$* response));\n"); + printer->Print( + *vars, + "MOCK_METHOD3(Async$Method$Raw, " + "::grpc::ClientAsyncResponseReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request, " + "::grpc::CompletionQueue* cq));\n"); + } else if (method->ClientOnlyStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD2($Method$Raw, " + "::grpc::ClientWriterInterface< $Request$>*" + "(::grpc::ClientContext* context, $Response$* response));\n"); + printer->Print( + *vars, + "MOCK_METHOD4(Async$Method$Raw, " + "::grpc::ClientAsyncWriterInterface< $Request$>*" + "(::grpc::ClientContext* context, $Response$* response, " + "::grpc::CompletionQueue* cq, void* tag));\n"); + } else if (method->ServerOnlyStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD2($Method$Raw, " + "::grpc::ClientReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request));\n"); + printer->Print( + *vars, + "MOCK_METHOD4(Async$Method$Raw, " + "::grpc::ClientAsyncReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request, " + "::grpc::CompletionQueue* cq, void* tag));\n"); + } else if (method->BidiStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD1($Method$Raw, " + "::grpc::ClientReaderWriterInterface< $Request$, $Response$>*" + "(::grpc::ClientContext* context));\n"); + printer->Print( + *vars, + "MOCK_METHOD3(Async$Method$Raw, " + "::grpc::ClientAsyncReaderWriterInterface<$Request$, $Response$>*" + "(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, " + "void* tag));\n"); + } +} + +void PrintMockService(Printer *printer, + const Service *service, + std::map *vars) { + (*vars)["Service"] = service->name(); + + printer->Print(service->GetLeadingComments().c_str()); + printer->Print(*vars, + "class Mock$Service$Stub : public $Service$::StubInterface {\n" + " public:\n"); + printer->Indent(); + printer->Print(*vars, + "Mock$Service$Stub(){}\n" + "~Mock$Service$Stub(){}\n"); + for (int i = 0; i < service->method_count(); ++i) { + printer->Print(service->method(i)->GetLeadingComments().c_str()); + PrintMockClientMethods(printer, service->method(i).get(), vars); + printer->Print(service->method(i)->GetTrailingComments().c_str()); + } + printer->Outdent(); + printer->Print("};\n"); + +} + +grpc::string GetMockServices(File *file, + const Parameters ¶ms) { + grpc::string output; + { + // Scope the output stream so it closes and finalizes output to the string. + auto printer = file->CreatePrinter(&output); + std::map vars; + // Package string is empty or ends with a dot. It is used to fully qualify + // method names. + vars["Package"] = file->package(); + if (!file->package().empty()) { + vars["Package"].append("."); + } + + if(!params.services_namespace.empty()) { + vars["services_namespace"] = params.services_namespace; + printer->Print(vars, "\nnamespace $services_namespace$ {\n\n"); + } + + for (int i =0; i < file->service_count(); i++) { + PrintMockService(printer.get(), file->service(i).get(), &vars); + printer->Print("\n"); + } + + if (!params.services_namespace.empty()) { + printer->Print(vars, "} // namespace $services_namespace$\n\n"); + } + } + return output; +} + +grpc::string GetMockEpilogue(File *file, const Parameters &) { + grpc::string temp; + + if (!file->package().empty()) { + std::vector parts = file->package_parts(); + + for (auto part = parts.begin(); part != parts.end(); part++){ + temp.append("} // namespace "); + temp.append(*part); + temp.append("\n"); + } + temp.append("\n"); + } + + return temp; +} + } // namespace grpc_cpp_generator diff --git a/src/compiler/cpp_generator.h b/src/compiler/cpp_generator.h index 69fd8a93e9..55432203d3 100644 --- a/src/compiler/cpp_generator.h +++ b/src/compiler/cpp_generator.h @@ -99,6 +99,18 @@ grpc::string GetSourceServices(grpc_generator::File *file, grpc::string GetSourceEpilogue(grpc_generator::File *file, const Parameters ¶ms); +// Return the prologue of the generated mock file. +grpc::string GetMockPrologue(File *file, const Parameters ¶ms); + +// Return the includes needed for generated mock file. +grpc::string GetMockIncludes(File *file, const Parameters ¶ms); + +// Return the services for generated mock file. +grpc::string GetMockServices(File* file, const Parameters ¶ms); + +// Return the epilogue of generated mock file. +grpc::string GetMockEpilogue(File* file, const Parameters ¶ms); + } // namespace grpc_cpp_generator #endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc index 4ee05ee037..a0986d92ce 100644 --- a/src/compiler/cpp_plugin.cc +++ b/src/compiler/cpp_plugin.cc @@ -114,6 +114,16 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { grpc::protobuf::io::CodedOutputStream source_coded_out(source_output.get()); source_coded_out.WriteRaw(source_code.data(), source_code.size()); + grpc::string mock_code = + grpc_cpp_generator::GetMockPrologue(&pbfile, generator_parameters) + + grpc_cpp_generator::GetMockIncludes(&pbfile, generator_parameters) + + grpc_cpp_generator::GetMockServices(&pbfile, generator_parameters) + + grpc_cpp_generator::GetMockEpilogue(&pbfile, generator_parameters); + std::unique_ptr mock_output( + context->Open(file_name + "_mock.grpc.pb.h")); + grpc::protobuf::io::CodedOutputStream mock_coded_out(mock_output.get()); + mock_coded_out.WriteRaw(mock_code.data(), mock_code.size()); + return true; } diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index fdb2732e50..16c04032ab 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -1,5 +1,5 @@ /* - * +* * Copyright 2015, Google Inc. * All rights reserved. * @@ -45,121 +45,37 @@ #include #include #include +#include + +#include #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" +#include "src/proto/grpc/testing/echo_mock.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" +#include + +using namespace std; using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using grpc::testing::EchoTestService; +using grpc::testing::MockClientReaderWriter; using std::chrono::system_clock; +using ::testing::AtLeast; +using ::testing::SetArgPointee; +using ::testing::SaveArg; +using ::testing::_; +using ::testing::Return; +using ::testing::Invoke; +using ::testing::WithArg; +using ::testing::DoAll; namespace grpc { namespace testing { namespace { -template -class MockClientReaderWriter final : public ClientReaderWriterInterface { - public: - void WaitForInitialMetadata() override {} - bool NextMessageSize(uint32_t* sz) override { - *sz = UINT_MAX; - return true; - } - bool Read(R* msg) override { return true; } - bool Write(const W& msg) override { return true; } - bool WritesDone() override { return true; } - Status Finish() override { return Status::OK; } -}; -template <> -class MockClientReaderWriter final - : public ClientReaderWriterInterface { - public: - MockClientReaderWriter() : writes_done_(false) {} - void WaitForInitialMetadata() override {} - bool NextMessageSize(uint32_t* sz) override { - *sz = UINT_MAX; - return true; - } - bool Read(EchoResponse* msg) override { - if (writes_done_) return false; - msg->set_message(last_message_); - return true; - } - - bool Write(const EchoRequest& msg, WriteOptions options) override { - gpr_log(GPR_INFO, "mock recv msg %s", msg.message().c_str()); - last_message_ = msg.message(); - return true; - } - bool WritesDone() override { - writes_done_ = true; - return true; - } - Status Finish() override { return Status::OK; } - - private: - bool writes_done_; - grpc::string last_message_; -}; - -// Mocked stub. -class MockStub : public EchoTestService::StubInterface { - public: - MockStub() {} - ~MockStub() {} - Status Echo(ClientContext* context, const EchoRequest& request, - EchoResponse* response) override { - response->set_message(request.message()); - return Status::OK; - } - Status Unimplemented(ClientContext* context, const EchoRequest& request, - EchoResponse* response) override { - return Status::OK; - } - - private: - ClientAsyncResponseReaderInterface* AsyncEchoRaw( - ClientContext* context, const EchoRequest& request, - CompletionQueue* cq) override { - return nullptr; - } - ClientWriterInterface* RequestStreamRaw( - ClientContext* context, EchoResponse* response) override { - return nullptr; - } - ClientAsyncWriterInterface* AsyncRequestStreamRaw( - ClientContext* context, EchoResponse* response, CompletionQueue* cq, - void* tag) override { - return nullptr; - } - ClientReaderInterface* ResponseStreamRaw( - ClientContext* context, const EchoRequest& request) override { - return nullptr; - } - ClientAsyncReaderInterface* AsyncResponseStreamRaw( - ClientContext* context, const EchoRequest& request, CompletionQueue* cq, - void* tag) override { - return nullptr; - } - ClientReaderWriterInterface* BidiStreamRaw( - ClientContext* context) override { - return new MockClientReaderWriter(); - } - ClientAsyncReaderWriterInterface* - AsyncBidiStreamRaw(ClientContext* context, CompletionQueue* cq, - void* tag) override { - return nullptr; - } - ClientAsyncResponseReaderInterface* AsyncUnimplementedRaw( - ClientContext* context, const EchoRequest& request, - CompletionQueue* cq) override { - return nullptr; - } -}; - class FakeClient { public: explicit FakeClient(EchoTestService::StubInterface* stub) : stub_(stub) {} @@ -267,16 +183,36 @@ TEST_F(MockTest, SimpleRpc) { ResetStub(); FakeClient client(stub_.get()); client.DoEcho(); - MockStub stub; + MockEchoTestServiceStub stub; + EchoResponse resp; + resp.set_message("hello world"); + EXPECT_CALL(stub, Echo(_, _, _)).Times(AtLeast(1)).WillOnce(DoAll(SetArgPointee<2>(resp), Return(Status::OK))); client.ResetStub(&stub); client.DoEcho(); } +ACTION_P(copy, msg) { + arg0->set_message(msg->message()); +} + TEST_F(MockTest, BidiStream) { ResetStub(); FakeClient client(stub_.get()); client.DoBidiStream(); - MockStub stub; + MockEchoTestServiceStub stub; + auto rw = new MockClientReaderWriter(); + EchoRequest msg; + + EXPECT_CALL(*rw, Write(_, _)).Times(3).WillRepeatedly(DoAll(SaveArg<0>(&msg), Return(true))); + EXPECT_CALL(*rw, Read(_)). + WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). + WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). + WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). + WillOnce(Return(false)); + EXPECT_CALL(*rw, WritesDone()); + EXPECT_CALL(*rw, Finish()).WillOnce(Return(Status::OK)); + + EXPECT_CALL(stub, BidiStreamRaw(_)).WillOnce(Return(rw)); client.ResetStub(&stub); client.DoBidiStream(); } -- cgit v1.2.3 From e536eeb6d060f5b39269a240c1ec7ddacc358484 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sat, 8 Apr 2017 17:49:23 -0700 Subject: Added tests for uni-directional streaming RPCs. --- include/grpc++/test/mock_stream.h | 2 +- test/cpp/end2end/mock_test.cc | 137 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) (limited to 'test/cpp') diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h index f99a1b1128..1b1a735185 100644 --- a/include/grpc++/test/mock_stream.h +++ b/include/grpc++/test/mock_stream.h @@ -37,7 +37,7 @@ class MockClientWriter : public ClientWriterInterface { MOCK_METHOD0_T(Finish, Status()); // WriterInterface - MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions&)); + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions)); // ClientWriterInterface MOCK_METHOD0_T(WritesDone, bool()); diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 16c04032ab..b7968ce230 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -90,6 +90,55 @@ class FakeClient { EXPECT_TRUE(s.ok()); } + void DoRequestStream() { + EchoRequest request; + EchoResponse response; + + ClientContext context; + grpc::string msg("hello"); + grpc::string exp(msg); + + std::unique_ptr> + cstream = stub_->RequestStream(&context, &response); + + request.set_message(msg); + EXPECT_TRUE(cstream->Write(request)); + + msg = ", world"; + request.set_message(msg); + exp.append(msg); + EXPECT_TRUE(cstream->Write(request)); + + cstream->WritesDone(); + Status s = cstream->Finish(); + + EXPECT_EQ(exp, response.message()); + EXPECT_TRUE(s.ok()); + } + + void DoResponseStream() { + EchoRequest request; + EchoResponse response; + request.set_message("hello world"); + + ClientContext context; + std::unique_ptr> + cstream = stub_->ResponseStream(&context, request); + + grpc::string exp = ""; + EXPECT_TRUE(cstream->Read(&response)); + exp.append(response.message() + " "); + + EXPECT_TRUE(cstream->Read(&response)); + exp.append(response.message()); + + EXPECT_FALSE(cstream->Read(&response)); + EXPECT_EQ(request.message(), exp); + + Status s = cstream->Finish(); + EXPECT_TRUE(s.ok()); + } + void DoBidiStream() { EchoRequest request; EchoResponse response; @@ -135,6 +184,31 @@ class TestServiceImpl : public EchoTestService::Service { return Status::OK; } + Status RequestStream(ServerContext* context, + ServerReader* reader, + EchoResponse* response) { + EchoRequest request; + grpc::string resp(""); + while (reader->Read(&request)) { + gpr_log(GPR_INFO, "recv msg %s", request.message().c_str()); + resp.append(request.message()); + } + response->set_message(resp); + return Status::OK; + } + + Status ResponseStream(ServerContext* context, + const EchoRequest* request, + ServerWriter* writer) { + EchoResponse response; + vector tokens = split(request->message()); + for (grpc::string token : tokens) { + response.set_message(token); + writer->Write(response); + } + return Status::OK; + } + Status BidiStream( ServerContext* context, ServerReaderWriter* stream) override { @@ -147,6 +221,26 @@ class TestServiceImpl : public EchoTestService::Service { } return Status::OK; } + private: + const vector split(const grpc::string& input) { + grpc::string buff(""); + vector result; + + for (auto n:input) { + if (n != ' ') { + buff += n; + continue; + } + if (buff == "") + continue; + result.push_back(buff); + buff = ""; + } + if (buff != "") + result.push_back(buff); + + return result; + } }; class MockTest : public ::testing::Test { @@ -191,6 +285,49 @@ TEST_F(MockTest, SimpleRpc) { client.DoEcho(); } +TEST_F(MockTest, ClientStream) { + ResetStub(); + FakeClient client(stub_.get()); + client.DoRequestStream(); + + MockEchoTestServiceStub stub; + auto w = new MockClientWriter(); + EchoResponse resp; + resp.set_message("hello, world"); + + EXPECT_CALL(*w, Write(_, _)).Times(2).WillRepeatedly(Return(true)); + EXPECT_CALL(*w, WritesDone()); + EXPECT_CALL(*w, Finish()).WillOnce(Return(Status::OK)); + + EXPECT_CALL(stub, RequestStreamRaw(_, _)).WillOnce(DoAll(SetArgPointee<1>(resp), Return(w))); + client.ResetStub(&stub); + client.DoRequestStream(); +} + +TEST_F(MockTest, ServerStream) { + ResetStub(); + FakeClient client(stub_.get()); + client.DoResponseStream(); + + MockEchoTestServiceStub stub; + auto r = new MockClientReader(); + EchoResponse resp1; + resp1.set_message("hello"); + EchoResponse resp2; + resp2.set_message("world"); + + EXPECT_CALL(*r, Read(_)). + WillOnce(DoAll(SetArgPointee<0>(resp1), Return(true))). + WillOnce(DoAll(SetArgPointee<0>(resp2), Return(true))). + WillOnce(Return(false)); + EXPECT_CALL(*r, Finish()).WillOnce(Return(Status::OK)); + + EXPECT_CALL(stub, ResponseStreamRaw(_, _)).WillOnce(Return(r)); + + client.ResetStub(&stub); + client.DoResponseStream(); +} + ACTION_P(copy, msg) { arg0->set_message(msg->message()); } -- cgit v1.2.3 From 2814b5148e9f902ef2893da34cc7a81106668e9a Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Thu, 13 Apr 2017 14:45:26 -0700 Subject: formatting --- Makefile | 2 +- include/grpc++/test/mock_stream.h | 2 +- src/compiler/cpp_generator.cc | 60 +++++++++++++++++++-------------------- src/compiler/cpp_generator.h | 26 +++++++++-------- src/compiler/cpp_plugin.cc | 11 +++++++ test/cpp/end2end/mock_test.cc | 59 +++++++++++++++++++------------------- 6 files changed, 86 insertions(+), 74 deletions(-) (limited to 'test/cpp') diff --git a/Makefile b/Makefile index e931d0d13c..4f9184f4a4 100644 --- a/Makefile +++ b/Makefile @@ -2331,7 +2331,7 @@ $(GENDIR)/src/proto/grpc/testing/echo.pb.cc: src/proto/grpc/testing/echo.proto $ $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc: src/proto/grpc/testing/echo.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< + $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=generate_mock_code=true:$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< endif ifeq ($(NO_PROTOC),true) diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h index 1b1a735185..e1dbd5ae3f 100644 --- a/include/grpc++/test/mock_stream.h +++ b/include/grpc++/test/mock_stream.h @@ -3,11 +3,11 @@ #include +#include #include #include #include #include -#include namespace grpc { namespace testing { diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index c13577ce52..d64f8c9532 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1408,7 +1408,8 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file, } // TODO(mmukhi): Make sure we need parameters or not. -grpc::string GetMockPrologue(grpc_generator::File *file, const Parameters & /*params*/ ) { +grpc::string GetMockPrologue(grpc_generator::File *file, + const Parameters & /*params*/) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -1434,7 +1435,8 @@ grpc::string GetMockPrologue(grpc_generator::File *file, const Parameters & /*pa } // TODO(mmukhi): Add client-stream and completion-queue headers. -grpc::string GetMockIncludes(grpc_generator::File *file, const Parameters ¶ms) { +grpc::string GetMockIncludes(grpc_generator::File *file, + const Parameters ¶ms) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -1442,9 +1444,8 @@ grpc::string GetMockIncludes(grpc_generator::File *file, const Parameters ¶m std::map vars; static const char *headers_strs[] = { - "grpc++/impl/codegen/async_stream.h", - "grpc++/impl/codegen/sync_stream.h", - "gmock/gmock.h", + "grpc++/impl/codegen/async_stream.h", + "grpc++/impl/codegen/sync_stream.h", "gmock/gmock.h", }; std::vector headers(headers_strs, array_end(headers_strs)); PrintIncludes(printer.get(), headers, params); @@ -1452,7 +1453,7 @@ grpc::string GetMockIncludes(grpc_generator::File *file, const Parameters ¶m if (!file->package().empty()) { std::vector parts = file->package_parts(); - for(auto part = parts.begin(); part != parts.end(); part++) { + for (auto part = parts.begin(); part != parts.end(); part++) { vars["part"] = *part; printer->Print(vars, "namespace $part$ {\n"); } @@ -1475,36 +1476,33 @@ void PrintMockClientMethods(grpc_generator::Printer *printer, *vars, "MOCK_METHOD3($Method$, ::grpc::Status(::grpc::ClientContext* context, " "const $Request$& request, $Response$* response));\n"); - printer->Print( - *vars, - "MOCK_METHOD3(Async$Method$Raw, " - "::grpc::ClientAsyncResponseReaderInterface< $Response$>*" - "(::grpc::ClientContext* context, const $Request$& request, " - "::grpc::CompletionQueue* cq));\n"); + printer->Print(*vars, + "MOCK_METHOD3(Async$Method$Raw, " + "::grpc::ClientAsyncResponseReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request, " + "::grpc::CompletionQueue* cq));\n"); } else if (ClientOnlyStreaming(method)) { printer->Print( *vars, "MOCK_METHOD2($Method$Raw, " "::grpc::ClientWriterInterface< $Request$>*" "(::grpc::ClientContext* context, $Response$* response));\n"); - printer->Print( - *vars, - "MOCK_METHOD4(Async$Method$Raw, " - "::grpc::ClientAsyncWriterInterface< $Request$>*" - "(::grpc::ClientContext* context, $Response$* response, " - "::grpc::CompletionQueue* cq, void* tag));\n"); + printer->Print(*vars, + "MOCK_METHOD4(Async$Method$Raw, " + "::grpc::ClientAsyncWriterInterface< $Request$>*" + "(::grpc::ClientContext* context, $Response$* response, " + "::grpc::CompletionQueue* cq, void* tag));\n"); } else if (ServerOnlyStreaming(method)) { printer->Print( *vars, "MOCK_METHOD2($Method$Raw, " "::grpc::ClientReaderInterface< $Response$>*" "(::grpc::ClientContext* context, const $Request$& request));\n"); - printer->Print( - *vars, - "MOCK_METHOD4(Async$Method$Raw, " - "::grpc::ClientAsyncReaderInterface< $Response$>*" - "(::grpc::ClientContext* context, const $Request$& request, " - "::grpc::CompletionQueue* cq, void* tag));\n"); + printer->Print(*vars, + "MOCK_METHOD4(Async$Method$Raw, " + "::grpc::ClientAsyncReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request, " + "::grpc::CompletionQueue* cq, void* tag));\n"); } else if (method->BidiStreaming()) { printer->Print( *vars, @@ -1521,8 +1519,8 @@ void PrintMockClientMethods(grpc_generator::Printer *printer, } void PrintMockService(grpc_generator::Printer *printer, - const grpc_generator::Service *service, - std::map *vars) { + const grpc_generator::Service *service, + std::map *vars) { (*vars)["Service"] = service->name(); printer->Print(service->GetLeadingComments("//").c_str()); @@ -1540,7 +1538,6 @@ void PrintMockService(grpc_generator::Printer *printer, } printer->Outdent(); printer->Print("};\n"); - } grpc::string GetMockServices(grpc_generator::File *file, @@ -1557,12 +1554,12 @@ grpc::string GetMockServices(grpc_generator::File *file, vars["Package"].append("."); } - if(!params.services_namespace.empty()) { + if (!params.services_namespace.empty()) { vars["services_namespace"] = params.services_namespace; printer->Print(vars, "\nnamespace $services_namespace$ {\n\n"); } - for (int i =0; i < file->service_count(); i++) { + for (int i = 0; i < file->service_count(); i++) { PrintMockService(printer.get(), file->service(i).get(), &vars); printer->Print("\n"); } @@ -1574,13 +1571,14 @@ grpc::string GetMockServices(grpc_generator::File *file, return output; } -grpc::string GetMockEpilogue(grpc_generator::File *file, const Parameters & /*params*/) { +grpc::string GetMockEpilogue(grpc_generator::File *file, + const Parameters & /*params*/) { grpc::string temp; if (!file->package().empty()) { std::vector parts = file->package_parts(); - for (auto part = parts.begin(); part != parts.end(); part++){ + for (auto part = parts.begin(); part != parts.end(); part++) { temp.append("} // namespace "); temp.append(*part); temp.append("\n"); diff --git a/src/compiler/cpp_generator.h b/src/compiler/cpp_generator.h index cd672d120d..6119ebe289 100644 --- a/src/compiler/cpp_generator.h +++ b/src/compiler/cpp_generator.h @@ -65,6 +65,8 @@ struct Parameters { bool use_system_headers; // Prefix to any grpc include grpc::string grpc_search_path; + // Generate GMOCK code to facilitate unit testing. + bool generate_mock_code; }; // Return the prologue of the generated header file. @@ -101,35 +103,35 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file, // Return the prologue of the generated mock file. grpc::string GetMockPrologue(grpc_generator::File *file, - const Parameters ¶ms); + const Parameters ¶ms); // Return the includes needed for generated mock file. grpc::string GetMockIncludes(grpc_generator::File *file, - const Parameters ¶ms); + const Parameters ¶ms); // Return the services for generated mock file. -grpc::string GetMockServices(grpc_generator::File* file, - const Parameters ¶ms); +grpc::string GetMockServices(grpc_generator::File *file, + const Parameters ¶ms); // Return the epilogue of generated mock file. -grpc::string GetMockEpilogue(grpc_generator::File* file, - const Parameters ¶ms); +grpc::string GetMockEpilogue(grpc_generator::File *file, + const Parameters ¶ms); // Return the prologue of the generated mock file. grpc::string GetMockPrologue(grpc_generator::File *file, - const Parameters ¶ms); + const Parameters ¶ms); // Return the includes needed for generated mock file. grpc::string GetMockIncludes(grpc_generator::File *file, - const Parameters ¶ms); + const Parameters ¶ms); // Return the services for generated mock file. -grpc::string GetMockServices(grpc_generator::File* file, - const Parameters ¶ms); +grpc::string GetMockServices(grpc_generator::File *file, + const Parameters ¶ms); // Return the epilogue of generated mock file. -grpc::string GetMockEpilogue(grpc_generator::File* file, - const Parameters ¶ms); +grpc::string GetMockEpilogue(grpc_generator::File *file, + const Parameters ¶ms); } // namespace grpc_cpp_generator diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc index a0986d92ce..35f1bf3e93 100644 --- a/src/compiler/cpp_plugin.cc +++ b/src/compiler/cpp_plugin.cc @@ -62,6 +62,7 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { grpc_cpp_generator::Parameters generator_parameters; generator_parameters.use_system_headers = true; + generator_parameters.generate_mock_code = false; ProtoBufFile pbfile(file); @@ -85,6 +86,13 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { } } else if (param[0] == "grpc_search_path") { generator_parameters.grpc_search_path = param[1]; + } else if (param[0] == "generate_mock_code") { + if (param[1] == "true") { + generator_parameters.generate_mock_code = true; + } else if (param[1] != "false") { + *error = grpc::string("Invalid parameter: ") + *parameter_string; + return false; + } } else { *error = grpc::string("Unknown parameter: ") + *parameter_string; return false; @@ -114,6 +122,9 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { grpc::protobuf::io::CodedOutputStream source_coded_out(source_output.get()); source_coded_out.WriteRaw(source_code.data(), source_code.size()); + if (!generator_parameters.generate_mock_code) { + return true; + } grpc::string mock_code = grpc_cpp_generator::GetMockPrologue(&pbfile, generator_parameters) + grpc_cpp_generator::GetMockIncludes(&pbfile, generator_parameters) + diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index b7968ce230..9c040a0cc3 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -1,5 +1,5 @@ /* -* + * * Copyright 2015, Google Inc. * All rights reserved. * @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -45,7 +46,6 @@ #include #include #include -#include #include @@ -55,7 +55,7 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" -#include +#include using namespace std; using grpc::testing::EchoRequest; @@ -98,8 +98,8 @@ class FakeClient { grpc::string msg("hello"); grpc::string exp(msg); - std::unique_ptr> - cstream = stub_->RequestStream(&context, &response); + std::unique_ptr> cstream = + stub_->RequestStream(&context, &response); request.set_message(msg); EXPECT_TRUE(cstream->Write(request)); @@ -122,8 +122,8 @@ class FakeClient { request.set_message("hello world"); ClientContext context; - std::unique_ptr> - cstream = stub_->ResponseStream(&context, request); + std::unique_ptr> cstream = + stub_->ResponseStream(&context, request); grpc::string exp = ""; EXPECT_TRUE(cstream->Read(&response)); @@ -197,8 +197,7 @@ class TestServiceImpl : public EchoTestService::Service { return Status::OK; } - Status ResponseStream(ServerContext* context, - const EchoRequest* request, + Status ResponseStream(ServerContext* context, const EchoRequest* request, ServerWriter* writer) { EchoResponse response; vector tokens = split(request->message()); @@ -221,23 +220,22 @@ class TestServiceImpl : public EchoTestService::Service { } return Status::OK; } + private: const vector split(const grpc::string& input) { grpc::string buff(""); vector result; - for (auto n:input) { + for (auto n : input) { if (n != ' ') { buff += n; continue; } - if (buff == "") - continue; + if (buff == "") continue; result.push_back(buff); buff = ""; } - if (buff != "") - result.push_back(buff); + if (buff != "") result.push_back(buff); return result; } @@ -280,7 +278,9 @@ TEST_F(MockTest, SimpleRpc) { MockEchoTestServiceStub stub; EchoResponse resp; resp.set_message("hello world"); - EXPECT_CALL(stub, Echo(_, _, _)).Times(AtLeast(1)).WillOnce(DoAll(SetArgPointee<2>(resp), Return(Status::OK))); + EXPECT_CALL(stub, Echo(_, _, _)) + .Times(AtLeast(1)) + .WillOnce(DoAll(SetArgPointee<2>(resp), Return(Status::OK))); client.ResetStub(&stub); client.DoEcho(); } @@ -299,7 +299,8 @@ TEST_F(MockTest, ClientStream) { EXPECT_CALL(*w, WritesDone()); EXPECT_CALL(*w, Finish()).WillOnce(Return(Status::OK)); - EXPECT_CALL(stub, RequestStreamRaw(_, _)).WillOnce(DoAll(SetArgPointee<1>(resp), Return(w))); + EXPECT_CALL(stub, RequestStreamRaw(_, _)) + .WillOnce(DoAll(SetArgPointee<1>(resp), Return(w))); client.ResetStub(&stub); client.DoRequestStream(); } @@ -316,10 +317,10 @@ TEST_F(MockTest, ServerStream) { EchoResponse resp2; resp2.set_message("world"); - EXPECT_CALL(*r, Read(_)). - WillOnce(DoAll(SetArgPointee<0>(resp1), Return(true))). - WillOnce(DoAll(SetArgPointee<0>(resp2), Return(true))). - WillOnce(Return(false)); + EXPECT_CALL(*r, Read(_)) + .WillOnce(DoAll(SetArgPointee<0>(resp1), Return(true))) + .WillOnce(DoAll(SetArgPointee<0>(resp2), Return(true))) + .WillOnce(Return(false)); EXPECT_CALL(*r, Finish()).WillOnce(Return(Status::OK)); EXPECT_CALL(stub, ResponseStreamRaw(_, _)).WillOnce(Return(r)); @@ -328,9 +329,7 @@ TEST_F(MockTest, ServerStream) { client.DoResponseStream(); } -ACTION_P(copy, msg) { - arg0->set_message(msg->message()); -} +ACTION_P(copy, msg) { arg0->set_message(msg->message()); } TEST_F(MockTest, BidiStream) { ResetStub(); @@ -340,12 +339,14 @@ TEST_F(MockTest, BidiStream) { auto rw = new MockClientReaderWriter(); EchoRequest msg; - EXPECT_CALL(*rw, Write(_, _)).Times(3).WillRepeatedly(DoAll(SaveArg<0>(&msg), Return(true))); - EXPECT_CALL(*rw, Read(_)). - WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). - WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). - WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). - WillOnce(Return(false)); + EXPECT_CALL(*rw, Write(_, _)) + .Times(3) + .WillRepeatedly(DoAll(SaveArg<0>(&msg), Return(true))); + EXPECT_CALL(*rw, Read(_)) + .WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))) + .WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))) + .WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))) + .WillOnce(Return(false)); EXPECT_CALL(*rw, WritesDone()); EXPECT_CALL(*rw, Finish()).WillOnce(Return(Status::OK)); -- cgit v1.2.3 From 443a75dd2282ff442fcd217f1b254ebe8a0f4355 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Fri, 14 Apr 2017 15:33:55 -0700 Subject: 1. Added golden file test. 2. Added support for mock. 3. Sanity fix. --- Makefile | 2 +- bazel/cc_grpc_library.bzl | 4 ++- bazel/generate_cc.bzl | 9 +++++- bazel/grpc_build_system.bzl | 3 +- build.yaml | 2 +- src/proto/grpc/testing/BUILD | 2 ++ test/cpp/codegen/BUILD | 2 +- test/cpp/codegen/compiler_test_mock_golden | 49 ++++++++++++++++++++++++++++++ test/cpp/codegen/golden_file_test.cc | 29 +++++++++++++----- test/cpp/end2end/mock_test.cc | 4 +-- 10 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 test/cpp/codegen/compiler_test_mock_golden (limited to 'test/cpp') diff --git a/Makefile b/Makefile index 4f9184f4a4..bfd31b0236 100644 --- a/Makefile +++ b/Makefile @@ -2286,7 +2286,7 @@ $(GENDIR)/src/proto/grpc/testing/compiler_test.pb.cc: src/proto/grpc/testing/com $(GENDIR)/src/proto/grpc/testing/compiler_test.grpc.pb.cc: src/proto/grpc/testing/compiler_test.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< + $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=generate_mock_code=true:$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< endif ifeq ($(NO_PROTOC),true) diff --git a/bazel/cc_grpc_library.bzl b/bazel/cc_grpc_library.bzl index ab1add476e..03a092192f 100644 --- a/bazel/cc_grpc_library.bzl +++ b/bazel/cc_grpc_library.bzl @@ -2,7 +2,7 @@ load("//:bazel/generate_cc.bzl", "generate_cc") -def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, use_external = False, **kwargs): +def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, generate_mock, use_external = False, **kwargs): """Generates C++ grpc classes from a .proto file. Assumes the generated classes will be used in cc_api_version = 2. @@ -17,6 +17,7 @@ def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, use_externa "@submodule_protobuf//:well_known_protos" use_external: When True the grpc deps are prefixed with //external. This allows grpc to be used as a dependency in other bazel projects. + generate_mock: When true GMOCk code for client stub is generated. **kwargs: rest of arguments, e.g., compatible_with and visibility. """ if len(srcs) > 1: @@ -54,6 +55,7 @@ def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, use_externa srcs = [proto_target], plugin = plugin, well_known_protos = well_known_protos, + generate_mock = generate_mock, **kwargs ) diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index f3961f0a41..7dd2c0486b 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -23,7 +23,10 @@ def generate_cc_impl(ctx): arguments = [] if ctx.executable.plugin: arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path] - arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] + arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags)] + if ctx.attr.generate_mock: + arguments += [",generate_mock_code=true"] + arguments += [":" + dir_out] additional_input = [ctx.executable.plugin] else: arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] @@ -71,6 +74,10 @@ generate_cc = rule( "well_known_protos" : attr.label( mandatory = False, ), + "generate_mock" : attr.bool( + default = False, + mandatory = False, + ), "_protoc": attr.label( default = Label("//external:protocol_compiler"), executable = True, diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 8b524bd0e5..b49ad3aa59 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -59,7 +59,7 @@ def grpc_proto_plugin(name, srcs = [], deps = []): load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library") def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = None, - has_services = True, use_external = False): + has_services = True, use_external = False, generate_mock = False): cc_grpc_library( name = name, srcs = srcs, @@ -67,5 +67,6 @@ def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = None, well_known_protos = well_known_protos, proto_only = not has_services, use_external = use_external, + generate_mock = generate_mock, ) diff --git a/build.yaml b/build.yaml index 15a0839779..8fd1b7bad4 100644 --- a/build.yaml +++ b/build.yaml @@ -3630,7 +3630,7 @@ targets: - grpc - gpr args: - - --generated_file_path=gens/src/proto/grpc/testing/compiler_test.grpc.pb.h + - --generated_file_path=gens/src/proto/grpc/testing - name: grpc_cli build: test run: false diff --git a/src/proto/grpc/testing/BUILD b/src/proto/grpc/testing/BUILD index 6f3422e4d1..805988c337 100644 --- a/src/proto/grpc/testing/BUILD +++ b/src/proto/grpc/testing/BUILD @@ -36,6 +36,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_proto_library") grpc_proto_library( name = "compiler_test_proto", srcs = ["compiler_test.proto"], + generate_mock = True, ) grpc_proto_library( @@ -55,6 +56,7 @@ grpc_proto_library( name = "echo_proto", srcs = ["echo.proto"], deps = ["echo_messages_proto"], + generate_mock = True, ) grpc_proto_library( diff --git a/test/cpp/codegen/BUILD b/test/cpp/codegen/BUILD index 14d5733da2..43d133fc34 100644 --- a/test/cpp/codegen/BUILD +++ b/test/cpp/codegen/BUILD @@ -62,7 +62,7 @@ cc_test( cc_test( name = "golden_file_test", srcs = ["golden_file_test.cc"], - args = ["--generated_file_path=$(GENDIR)/src/proto/grpc/testing/compiler_test.grpc.pb.h"], + args = ["--generated_file_path=$(GENDIR)/src/proto/grpc/testing/"], data = [ ":compiler_test_golden", "//src/proto/grpc/testing:_compiler_test_proto_grpc_codegen", diff --git a/test/cpp/codegen/compiler_test_mock_golden b/test/cpp/codegen/compiler_test_mock_golden new file mode 100644 index 0000000000..ced61aeb94 --- /dev/null +++ b/test/cpp/codegen/compiler_test_mock_golden @@ -0,0 +1,49 @@ +// Generated by the gRPC C++ plugin. +// If you make any local change, they will be lost. +// source: src/proto/grpc/testing/compiler_test.proto + +#include "src/proto/grpc/testing/compiler_test.pb.h" +#include "src/proto/grpc/testing/compiler_test.grpc.pb.h" + +#include +#include +#include +namespace grpc { +namespace testing { + +// ServiceA detached comment 1 +// +// ServiceA detached comment 2 +// +// ServiceA leading comment 1 +class MockServiceAStub : public ServiceA::StubInterface { + public: + MockServiceAStub(){} + ~MockServiceAStub(){} + // MethodA1 leading comment 1 + MOCK_METHOD3(MethodA1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response)); + MOCK_METHOD3(AsyncMethodA1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq)); + // MethodA1 trailing comment 1 + // MethodA2 detached leading comment 1 + // + // Method A2 leading comment 1 + // Method A2 leading comment 2 + MOCK_METHOD2(MethodA2Raw, ::grpc::ClientWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response)); + MOCK_METHOD4(AsyncMethodA2Raw, ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag)); + // MethodA2 trailing comment 1 +}; + +// ServiceB leading comment 1 +class MockServiceBStub : public ServiceB::StubInterface { + public: + MockServiceBStub(){} + ~MockServiceBStub(){} + // MethodB1 leading comment 1 + MOCK_METHOD3(MethodB1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response)); + MOCK_METHOD3(AsyncMethodB1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq)); + // MethodB1 trailing comment 1 +}; + +} // namespace grpc +} // namespace testing + diff --git a/test/cpp/codegen/golden_file_test.cc b/test/cpp/codegen/golden_file_test.cc index 158a4d933c..dd09471fdb 100644 --- a/test/cpp/codegen/golden_file_test.cc +++ b/test/cpp/codegen/golden_file_test.cc @@ -37,16 +37,18 @@ #include #include -DEFINE_string(generated_file_path, "", - "path to the generated compiler_test.grpc.pb.h file"); +DEFINE_string( + generated_file_path, "", + "path to the directory containing generated files compiler_test.grpc.pb.h" + "and compiler_test_mock.grpc.pb.h"); const char kGoldenFilePath[] = "test/cpp/codegen/compiler_test_golden"; +const char kMockGoldenFilePath[] = "test/cpp/codegen/compiler_test_mock_golden"; -TEST(GoldenFileTest, TestGeneratedFile) { - ASSERT_FALSE(FLAGS_generated_file_path.empty()); - - std::ifstream generated(FLAGS_generated_file_path); - std::ifstream golden(kGoldenFilePath); +void run_test(std::basic_string generated_file, + std::basic_string golden_file) { + std::ifstream generated(generated_file); + std::ifstream golden(golden_file); ASSERT_TRUE(generated.good()); ASSERT_TRUE(golden.good()); @@ -61,8 +63,21 @@ TEST(GoldenFileTest, TestGeneratedFile) { golden.close(); } +TEST(GoldenFileTest, TestGeneratedFile) { + run_test(FLAGS_generated_file_path + "compiler_test.grpc.pb.h", + kGoldenFilePath); +} + +TEST(GoldenMockFileTest, TestGeneratedMockFile) { + run_test(FLAGS_generated_file_path + "compiler_test_mock.grpc.pb.h", + kMockGoldenFilePath); +} + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); ::google::ParseCommandLineFlags(&argc, &argv, true); + if (FLAGS_generated_file_path.empty()) return 1; + if (FLAGS_generated_file_path.back() != '/') + FLAGS_generated_file_path.append("/"); return RUN_ALL_TESTS(); } diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 9c040a0cc3..7e330063ed 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -186,7 +186,7 @@ class TestServiceImpl : public EchoTestService::Service { Status RequestStream(ServerContext* context, ServerReader* reader, - EchoResponse* response) { + EchoResponse* response) override { EchoRequest request; grpc::string resp(""); while (reader->Read(&request)) { @@ -198,7 +198,7 @@ class TestServiceImpl : public EchoTestService::Service { } Status ResponseStream(ServerContext* context, const EchoRequest* request, - ServerWriter* writer) { + ServerWriter* writer) override { EchoResponse response; vector tokens = split(request->message()); for (grpc::string token : tokens) { -- cgit v1.2.3 From a68829023c4d20767938a9e2156bab1fe83b082a Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Fri, 14 Apr 2017 17:37:46 -0700 Subject: more sanity trying to fix some sanity nope that didn't work fixing test failiures added debug code more trail and error more trial and error cleaning debug code --- CMakeLists.txt | 1 + bazel/generate_cc.bzl | 6 +++--- build.yaml | 6 ++++-- test/cpp/codegen/golden_file_test.cc | 4 +++- tools/run_tests/generated/sources_and_headers.json | 3 +++ tools/run_tests/generated/tests.json | 2 +- vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj | 2 ++ 7 files changed, 17 insertions(+), 7 deletions(-) (limited to 'test/cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index d3db20d420..4c23d28b90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10082,6 +10082,7 @@ add_executable(golden_file_test ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test_mock.grpc.pb.h test/cpp/codegen/golden_file_test.cc third_party/googletest/googletest/src/gtest-all.cc ) diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index 7dd2c0486b..dac76f67f1 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -23,10 +23,10 @@ def generate_cc_impl(ctx): arguments = [] if ctx.executable.plugin: arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path] - arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags)] + gen_mock = "" if ctx.attr.generate_mock: - arguments += [",generate_mock_code=true"] - arguments += [":" + dir_out] + gen_mock = ",generate_mock_code=true" + arguments += ["--PLUGIN_out=" + gen_mock + ",".join(ctx.attr.flags) + ":" + dir_out] additional_input = [ctx.executable.plugin] else: arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] diff --git a/build.yaml b/build.yaml index 8fd1b7bad4..52ff98c64b 100644 --- a/build.yaml +++ b/build.yaml @@ -948,8 +948,8 @@ filegroups: - name: grpc++_test language: c++ public_headers: - - include/grpc++/test/server_context_test_spouse.h - include/grpc++/test/mock_stream.h + - include/grpc++/test/server_context_test_spouse.h deps: - grpc++ - name: thrift_util @@ -3630,7 +3630,7 @@ targets: - grpc - gpr args: - - --generated_file_path=gens/src/proto/grpc/testing + - --generated_file_path=gens/src/proto/grpc/testing/ - name: grpc_cli build: test run: false @@ -3891,6 +3891,8 @@ targets: gtest: true build: test language: c++ + headers: + - include/grpc++/test/mock_stream.h src: - test/cpp/end2end/mock_test.cc deps: diff --git a/test/cpp/codegen/golden_file_test.cc b/test/cpp/codegen/golden_file_test.cc index dd09471fdb..7789ac738b 100644 --- a/test/cpp/codegen/golden_file_test.cc +++ b/test/cpp/codegen/golden_file_test.cc @@ -76,7 +76,9 @@ TEST(GoldenMockFileTest, TestGeneratedMockFile) { int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); ::google::ParseCommandLineFlags(&argc, &argv, true); - if (FLAGS_generated_file_path.empty()) return 1; + if (FLAGS_generated_file_path.empty()) { + FLAGS_generated_file_path = "gens/src/proto/grpc/testing/"; + } if (FLAGS_generated_file_path.back() != '/') FLAGS_generated_file_path.append("/"); return RUN_ALL_TESTS(); diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index c019996174..fa28af7f7b 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3031,6 +3031,7 @@ ], "headers": [ "src/proto/grpc/testing/compiler_test.grpc.pb.h", + "src/proto/grpc/testing/compiler_test_mock.grpc.pb.h", "src/proto/grpc/testing/compiler_test.pb.h" ], "is_filegroup": false, @@ -8933,12 +8934,14 @@ "grpc++" ], "headers": [ + "include/grpc++/test/mock_stream.h", "include/grpc++/test/server_context_test_spouse.h" ], "is_filegroup": true, "language": "c++", "name": "grpc++_test", "src": [ + "include/grpc++/test/mock_stream.h", "include/grpc++/test/server_context_test_spouse.h" ], "third_party": false, diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index a08caf30d3..408b38f844 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3263,7 +3263,7 @@ }, { "args": [ - "--generated_file_path=gens/src/proto/grpc/testing/compiler_test.grpc.pb.h" + "--generated_file_path=gens/src/proto/grpc/testing/" ], "ci_platforms": [ "linux", diff --git a/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj b/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj index e9802773d8..7deebd1728 100644 --- a/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj +++ b/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj @@ -168,6 +168,8 @@ + + -- cgit v1.2.3 From ea07b60401054e1a6bb5ce8c92ae28e8c4996287 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Tue, 18 Apr 2017 17:05:49 -0700 Subject: Post-review update --- include/grpc++/test/mock_stream.h | 2 +- src/compiler/cpp_generator.cc | 6 -- src/proto/grpc/testing/compiler_test.proto | 8 ++ test/cpp/codegen/compiler_test_golden | 144 ++++++++++++++++++++++++++++- test/cpp/codegen/compiler_test_mock_golden | 23 +---- 5 files changed, 154 insertions(+), 29 deletions(-) (limited to 'test/cpp') diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h index 679fea81bd..f2de9472d6 100644 --- a/include/grpc++/test/mock_stream.h +++ b/include/grpc++/test/mock_stream.h @@ -1,6 +1,6 @@ /* * - * Copyright 2016, Google Inc. + * Copyright 2017, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index d64f8c9532..d01f4ab899 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1523,18 +1523,12 @@ void PrintMockService(grpc_generator::Printer *printer, std::map *vars) { (*vars)["Service"] = service->name(); - printer->Print(service->GetLeadingComments("//").c_str()); printer->Print(*vars, "class Mock$Service$Stub : public $Service$::StubInterface {\n" " public:\n"); printer->Indent(); - printer->Print(*vars, - "Mock$Service$Stub(){}\n" - "~Mock$Service$Stub(){}\n"); for (int i = 0; i < service->method_count(); ++i) { - printer->Print(service->method(i)->GetLeadingComments("//").c_str()); PrintMockClientMethods(printer, service->method(i).get(), vars); - printer->Print(service->method(i)->GetTrailingComments("//").c_str()); } printer->Outdent(); printer->Print("};\n"); diff --git a/src/proto/grpc/testing/compiler_test.proto b/src/proto/grpc/testing/compiler_test.proto index 085e8ae59f..24735522e0 100644 --- a/src/proto/grpc/testing/compiler_test.proto +++ b/src/proto/grpc/testing/compiler_test.proto @@ -59,6 +59,14 @@ service ServiceA { // Method A2 leading comment 2 rpc MethodA2(stream Request) returns (Response); // MethodA2 trailing comment 1 + + // Method A3 leading comment 1 + rpc MethodA3(Request) returns (stream Response); + // Method A3 trailing comment 1 + + // Method A4 leading comment 1 + rpc MethodA4(stream Request) returns (stream Response); + // Method A4 trailing comment 1 } // Ignored ServiceA trailing comment 1 diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden index fd26a17ac1..8e3ae32a49 100644 --- a/test/cpp/codegen/compiler_test_golden +++ b/test/cpp/codegen/compiler_test_golden @@ -89,10 +89,30 @@ class ServiceA final { return std::unique_ptr< ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>>(AsyncMethodA2Raw(context, response, cq, tag)); } // MethodA2 trailing comment 1 + // Method A3 leading comment 1 + std::unique_ptr< ::grpc::ClientReaderInterface< ::grpc::testing::Response>> MethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request) { + return std::unique_ptr< ::grpc::ClientReaderInterface< ::grpc::testing::Response>>(MethodA3Raw(context, request)); + } + std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>> AsyncMethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) { + return std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>>(AsyncMethodA3Raw(context, request, cq, tag)); + } + // Method A3 trailing comment 1 + // Method A4 leading comment 1 + std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>> MethodA4(::grpc::ClientContext* context) { + return std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>>(MethodA4Raw(context)); + } + std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>> AsyncMethodA4(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { + return std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>>(AsyncMethodA4Raw(context, cq, tag)); + } + // Method A4 trailing comment 1 private: virtual ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>* AsyncMethodA1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) = 0; virtual ::grpc::ClientWriterInterface< ::grpc::testing::Request>* MethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response) = 0; virtual ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>* AsyncMethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) = 0; + virtual ::grpc::ClientReaderInterface< ::grpc::testing::Response>* MethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request) = 0; + virtual ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>* AsyncMethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) = 0; + virtual ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>* MethodA4Raw(::grpc::ClientContext* context) = 0; + virtual ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>* AsyncMethodA4Raw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) = 0; }; class Stub final : public StubInterface { public: @@ -107,14 +127,32 @@ class ServiceA final { std::unique_ptr< ::grpc::ClientAsyncWriter< ::grpc::testing::Request>> AsyncMethodA2(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) { return std::unique_ptr< ::grpc::ClientAsyncWriter< ::grpc::testing::Request>>(AsyncMethodA2Raw(context, response, cq, tag)); } + std::unique_ptr< ::grpc::ClientReader< ::grpc::testing::Response>> MethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request) { + return std::unique_ptr< ::grpc::ClientReader< ::grpc::testing::Response>>(MethodA3Raw(context, request)); + } + std::unique_ptr< ::grpc::ClientAsyncReader< ::grpc::testing::Response>> AsyncMethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) { + return std::unique_ptr< ::grpc::ClientAsyncReader< ::grpc::testing::Response>>(AsyncMethodA3Raw(context, request, cq, tag)); + } + std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>> MethodA4(::grpc::ClientContext* context) { + return std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>>(MethodA4Raw(context)); + } + std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>> AsyncMethodA4(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { + return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>>(AsyncMethodA4Raw(context, cq, tag)); + } private: std::shared_ptr< ::grpc::ChannelInterface> channel_; ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>* AsyncMethodA1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) override; ::grpc::ClientWriter< ::grpc::testing::Request>* MethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response) override; ::grpc::ClientAsyncWriter< ::grpc::testing::Request>* AsyncMethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) override; + ::grpc::ClientReader< ::grpc::testing::Response>* MethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request) override; + ::grpc::ClientAsyncReader< ::grpc::testing::Response>* AsyncMethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) override; + ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>* MethodA4Raw(::grpc::ClientContext* context) override; + ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>* AsyncMethodA4Raw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) override; const ::grpc::RpcMethod rpcmethod_MethodA1_; const ::grpc::RpcMethod rpcmethod_MethodA2_; + const ::grpc::RpcMethod rpcmethod_MethodA3_; + const ::grpc::RpcMethod rpcmethod_MethodA4_; }; static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); @@ -131,6 +169,12 @@ class ServiceA final { // Method A2 leading comment 2 virtual ::grpc::Status MethodA2(::grpc::ServerContext* context, ::grpc::ServerReader< ::grpc::testing::Request>* reader, ::grpc::testing::Response* response); // MethodA2 trailing comment 1 + // Method A3 leading comment 1 + virtual ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer); + // Method A3 trailing comment 1 + // Method A4 leading comment 1 + virtual ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream); + // Method A4 trailing comment 1 }; template class WithAsyncMethod_MethodA1 : public BaseClass { @@ -172,7 +216,47 @@ class ServiceA final { ::grpc::Service::RequestAsyncClientStreaming(1, context, reader, new_call_cq, notification_cq, tag); } }; - typedef WithAsyncMethod_MethodA1 > AsyncService; + template + class WithAsyncMethod_MethodA3 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithAsyncMethod_MethodA3() { + ::grpc::Service::MarkMethodAsync(2); + } + ~WithAsyncMethod_MethodA3() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestMethodA3(::grpc::ServerContext* context, ::grpc::testing::Request* request, ::grpc::ServerAsyncWriter< ::grpc::testing::Response>* writer, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncServerStreaming(2, context, request, writer, new_call_cq, notification_cq, tag); + } + }; + template + class WithAsyncMethod_MethodA4 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithAsyncMethod_MethodA4() { + ::grpc::Service::MarkMethodAsync(3); + } + ~WithAsyncMethod_MethodA4() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) final override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestMethodA4(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncBidiStreaming(3, context, stream, new_call_cq, notification_cq, tag); + } + }; + typedef WithAsyncMethod_MethodA1 > > > AsyncService; template class WithGenericMethod_MethodA1 : public BaseClass { private: @@ -208,6 +292,40 @@ class ServiceA final { } }; template + class WithGenericMethod_MethodA3 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithGenericMethod_MethodA3() { + ::grpc::Service::MarkMethodGeneric(2); + } + ~WithGenericMethod_MethodA3() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + }; + template + class WithGenericMethod_MethodA4 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithGenericMethod_MethodA4() { + ::grpc::Service::MarkMethodGeneric(3); + } + ~WithGenericMethod_MethodA4() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) final override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + }; + template class WithStreamedUnaryMethod_MethodA1 : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service *service) {} @@ -228,8 +346,28 @@ class ServiceA final { virtual ::grpc::Status StreamedMethodA1(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::grpc::testing::Request,::grpc::testing::Response>* server_unary_streamer) = 0; }; typedef WithStreamedUnaryMethod_MethodA1 StreamedUnaryService; - typedef Service SplitStreamedService; - typedef WithStreamedUnaryMethod_MethodA1 StreamedService; + template + class WithSplitStreamingMethod_MethodA3 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithSplitStreamingMethod_MethodA3() { + ::grpc::Service::MarkMethodStreamed(2, + new ::grpc::SplitServerStreamingHandler< ::grpc::testing::Request, ::grpc::testing::Response>(std::bind(&WithSplitStreamingMethod_MethodA3::StreamedMethodA3, this, std::placeholders::_1, std::placeholders::_2))); + } + ~WithSplitStreamingMethod_MethodA3() override { + BaseClassMustBeDerivedFromService(this); + } + // disable regular version of this method + ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + // replace default version of method with split streamed + virtual ::grpc::Status StreamedMethodA3(::grpc::ServerContext* context, ::grpc::ServerSplitStreamer< ::grpc::testing::Request,::grpc::testing::Response>* server_split_streamer) = 0; + }; + typedef WithSplitStreamingMethod_MethodA3 SplitStreamedService; + typedef WithStreamedUnaryMethod_MethodA1 > StreamedService; }; // ServiceB leading comment 1 diff --git a/test/cpp/codegen/compiler_test_mock_golden b/test/cpp/codegen/compiler_test_mock_golden index ced61aeb94..8e4b4d5911 100644 --- a/test/cpp/codegen/compiler_test_mock_golden +++ b/test/cpp/codegen/compiler_test_mock_golden @@ -11,37 +11,22 @@ namespace grpc { namespace testing { -// ServiceA detached comment 1 -// -// ServiceA detached comment 2 -// -// ServiceA leading comment 1 class MockServiceAStub : public ServiceA::StubInterface { public: - MockServiceAStub(){} - ~MockServiceAStub(){} - // MethodA1 leading comment 1 MOCK_METHOD3(MethodA1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response)); MOCK_METHOD3(AsyncMethodA1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq)); - // MethodA1 trailing comment 1 - // MethodA2 detached leading comment 1 - // - // Method A2 leading comment 1 - // Method A2 leading comment 2 MOCK_METHOD2(MethodA2Raw, ::grpc::ClientWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response)); MOCK_METHOD4(AsyncMethodA2Raw, ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag)); - // MethodA2 trailing comment 1 + MOCK_METHOD2(MethodA3Raw, ::grpc::ClientReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request)); + MOCK_METHOD4(AsyncMethodA3Raw, ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag)); + MOCK_METHOD1(MethodA4Raw, ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>*(::grpc::ClientContext* context)); + MOCK_METHOD3(AsyncMethodA4Raw, ::grpc::ClientAsyncReaderWriterInterface<::grpc::testing::Request, ::grpc::testing::Response>*(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag)); }; -// ServiceB leading comment 1 class MockServiceBStub : public ServiceB::StubInterface { public: - MockServiceBStub(){} - ~MockServiceBStub(){} - // MethodB1 leading comment 1 MOCK_METHOD3(MethodB1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response)); MOCK_METHOD3(AsyncMethodB1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq)); - // MethodB1 trailing comment 1 }; } // namespace grpc -- cgit v1.2.3 From 0a458b599e723bfcd22cf92755059ac4de0a1489 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 19 Apr 2017 06:35:16 -0700 Subject: Fix Bazel build --- src/proto/grpc/health/v1/BUILD | 39 +++++++++++++++++++++++++++++++++++++++ test/cpp/end2end/BUILD | 1 + 2 files changed, 40 insertions(+) create mode 100644 src/proto/grpc/health/v1/BUILD (limited to 'test/cpp') diff --git a/src/proto/grpc/health/v1/BUILD b/src/proto/grpc/health/v1/BUILD new file mode 100644 index 0000000000..dbb91d9139 --- /dev/null +++ b/src/proto/grpc/health/v1/BUILD @@ -0,0 +1,39 @@ +# Copyright 2017, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +licenses(["notice"]) # 3-clause BSD + +package(default_visibility = ["//visibility:public"]) + +load("//bazel:grpc_build_system.bzl", "grpc_proto_library") + +grpc_proto_library( + name = "health_proto", + srcs = ["health.proto"], +) diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD index 0bf7948fcf..a74a123aef 100644 --- a/test/cpp/end2end/BUILD +++ b/test/cpp/end2end/BUILD @@ -156,6 +156,7 @@ cc_test( "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", + "//src/proto/grpc/health/v1:health_proto", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", -- cgit v1.2.3 From ae1e29eed96798cadfed15b2e1e63e92dcf6d36e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 19 Apr 2017 09:07:23 -0700 Subject: Get dep in the right place --- test/cpp/end2end/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/cpp') diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD index a74a123aef..f1212e15c7 100644 --- a/test/cpp/end2end/BUILD +++ b/test/cpp/end2end/BUILD @@ -51,6 +51,7 @@ cc_test( "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", + "//src/proto/grpc/health/v1:health_proto", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", @@ -156,7 +157,6 @@ cc_test( "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", - "//src/proto/grpc/health/v1:health_proto", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", -- cgit v1.2.3 From 41fdf7d6ade3987e44213e591a1c67fee81e12a2 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 13 Apr 2017 18:55:46 +0000 Subject: Better cost estimation --- test/cpp/qps/gen_build_yaml.py | 1 + tools/run_tests/generated/tests.json | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'test/cpp') diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py index 2f035abedd..805b0faeec 100755 --- a/test/cpp/qps/gen_build_yaml.py +++ b/test/cpp/qps/gen_build_yaml.py @@ -66,6 +66,7 @@ def _scenario_json_string(scenario_json, is_tsan): def threads_required(scenario_json, where, is_tsan): scenario_json = mutate_scenario(scenario_json, is_tsan) if scenario_json['%s_config' % where]['%s_type' % where] == 'ASYNC_%s' % where.upper(): + if scenario_json['client_config']['client_channels'] == 1: return 1 return scenario_json['%s_config' % where].get('async_%s_threads' % where, 0) return scenario_json['client_config']['outstanding_rpcs_per_channel'] * scenario_json['client_config']['client_channels'] diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 9b48d85970..a5bc8fa0ea 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -41374,7 +41374,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 100, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41476,7 +41476,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41528,7 +41528,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41953,7 +41953,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 100, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42055,7 +42055,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42107,7 +42107,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42580,7 +42580,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 100, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42730,7 +42730,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42806,7 +42806,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43435,7 +43435,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 100, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43585,7 +43585,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43661,7 +43661,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", -- cgit v1.2.3 From dbc12105a3e9266dde57647ccc6340ea9c50fd2c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 20 Apr 2017 17:08:39 +0000 Subject: Refine ping-pong cpu requirement estimations; sort tests by cpu cost to get better bin packing --- build.yaml | 6 ++-- test/cpp/qps/gen_build_yaml.py | 2 ++ tools/run_tests/generated/tests.json | 66 ++++++++++++++++++------------------ tools/run_tests/run_tests.py | 2 +- 4 files changed, 40 insertions(+), 36 deletions(-) (limited to 'test/cpp') diff --git a/build.yaml b/build.yaml index 8c27c8e3da..a2bbcaf41d 100644 --- a/build.yaml +++ b/build.yaml @@ -3638,6 +3638,7 @@ targets: - name: generic_end2end_test build: test language: c++ + cpu_cost: 0.1 src: - test/cpp/end2end/generic_end2end_test.cc deps: @@ -3743,6 +3744,7 @@ targets: - name: grpc_tool_test build: test language: c++ + cpu_cost: 0.2 src: - src/proto/grpc/testing/echo.proto - src/proto/grpc/testing/echo_messages.proto @@ -3771,9 +3773,9 @@ targets: - grpc++ - grpc - name: grpclb_test + cpu_cost: 0.1 build: test language: c++ - cpu_cost: 0.1 src: - src/proto/grpc/lb/v1/load_balancer.proto - test/cpp/grpclb/grpclb_test.cc @@ -4263,7 +4265,7 @@ targets: - gpr_test_util - gpr - name: writes_per_rpc_test - cpu_cost: 0.5 + cpu_cost: 0.8 build: test language: c++ src: diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py index 805b0faeec..2edcb86a68 100755 --- a/test/cpp/qps/gen_build_yaml.py +++ b/test/cpp/qps/gen_build_yaml.py @@ -65,6 +65,8 @@ def _scenario_json_string(scenario_json, is_tsan): def threads_required(scenario_json, where, is_tsan): scenario_json = mutate_scenario(scenario_json, is_tsan) + if scenario_json['client_config']['outstanding_rpcs_per_channel'] == 1 and scenario_json['client_config']['client_channels'] == 1: + return 0.4 if scenario_json['%s_config' % where]['%s_type' % where] == 'ASYNC_%s' % where.upper(): if scenario_json['client_config']['client_channels'] == 1: return 1 return scenario_json['%s_config' % where].get('async_%s_threads' % where, 0) diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index a5bc8fa0ea..daa9f5b0e6 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -2613,7 +2613,7 @@ "posix", "windows" ], - "cpu_cost": 0.6, + "cpu_cost": 0.8, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -2964,7 +2964,7 @@ "mac", "posix" ], - "cpu_cost": 1.0, + "cpu_cost": 0.5, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -3225,7 +3225,7 @@ "posix", "windows" ], - "cpu_cost": 0.5, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -3381,7 +3381,7 @@ "posix", "windows" ], - "cpu_cost": 1.0, + "cpu_cost": 0.1, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -3832,7 +3832,7 @@ "mac", "posix" ], - "cpu_cost": 0.5, + "cpu_cost": 0.8, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -41274,7 +41274,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41476,7 +41476,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41528,7 +41528,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41553,7 +41553,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41603,7 +41603,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41653,7 +41653,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41753,7 +41753,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41853,7 +41853,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42055,7 +42055,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42107,7 +42107,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42132,7 +42132,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42182,7 +42182,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42232,7 +42232,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42332,7 +42332,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42432,7 +42432,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42730,7 +42730,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42806,7 +42806,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42843,7 +42843,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42917,7 +42917,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42991,7 +42991,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43139,7 +43139,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43287,7 +43287,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43585,7 +43585,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43661,7 +43661,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43698,7 +43698,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43772,7 +43772,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43846,7 +43846,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43994,7 +43994,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index cfa7071e00..32da7fb02a 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -1466,7 +1466,7 @@ def _build_and_run( # When running on travis, we want out test runs to be as similar as possible # for reproducibility purposes. if args.travis: - massaged_one_run = sorted(one_run, key=lambda x: x.shortname) + massaged_one_run = sorted(one_run, key=lambda x: (x.cpu_cost, x.shortname)) else: # whereas otherwise, we want to shuffle things up to give all tests a # chance to run. -- cgit v1.2.3 From 0d4628479995be4e310f55683f1ebaae2a879e4d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 24 Apr 2017 08:24:21 -0700 Subject: Rollback some changes --- build.yaml | 2 +- test/cpp/qps/gen_build_yaml.py | 2 -- tools/run_tests/generated/tests.json | 58 ++++++++++++++++++------------------ 3 files changed, 30 insertions(+), 32 deletions(-) (limited to 'test/cpp') diff --git a/build.yaml b/build.yaml index 58a474aabf..f2af370522 100644 --- a/build.yaml +++ b/build.yaml @@ -3806,7 +3806,7 @@ targets: - grpc++ - grpc - name: grpclb_test - gtest: false + cpu_cost: 0.1 build: test language: c++ src: diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py index 2edcb86a68..805b0faeec 100755 --- a/test/cpp/qps/gen_build_yaml.py +++ b/test/cpp/qps/gen_build_yaml.py @@ -65,8 +65,6 @@ def _scenario_json_string(scenario_json, is_tsan): def threads_required(scenario_json, where, is_tsan): scenario_json = mutate_scenario(scenario_json, is_tsan) - if scenario_json['client_config']['outstanding_rpcs_per_channel'] == 1 and scenario_json['client_config']['client_channels'] == 1: - return 0.4 if scenario_json['%s_config' % where]['%s_type' % where] == 'ASYNC_%s' % where.upper(): if scenario_json['client_config']['client_channels'] == 1: return 1 return scenario_json['%s_config' % where].get('async_%s_threads' % where, 0) diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 203f51b6b8..cb918a0830 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3403,7 +3403,7 @@ "posix", "windows" ], - "cpu_cost": 1.0, + "cpu_cost": 0.1, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -41250,7 +41250,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41452,7 +41452,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41504,7 +41504,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41529,7 +41529,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41579,7 +41579,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41629,7 +41629,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41729,7 +41729,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41829,7 +41829,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42031,7 +42031,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42083,7 +42083,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42108,7 +42108,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42158,7 +42158,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42208,7 +42208,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42308,7 +42308,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42408,7 +42408,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42714,7 +42714,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42792,7 +42792,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42830,7 +42830,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42906,7 +42906,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42982,7 +42982,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43134,7 +43134,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43286,7 +43286,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43592,7 +43592,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43670,7 +43670,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43708,7 +43708,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43784,7 +43784,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43860,7 +43860,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -44012,7 +44012,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", -- cgit v1.2.3 From c6f6663fb7b8c4b1614b6f881abf966d48cb87c4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 24 Apr 2017 08:29:39 -0700 Subject: Rollback some changes --- build.yaml | 2 +- test/cpp/qps/gen_build_yaml.py | 1 - tools/run_tests/generated/tests.json | 26 +++++++++++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) (limited to 'test/cpp') diff --git a/build.yaml b/build.yaml index f2af370522..58a474aabf 100644 --- a/build.yaml +++ b/build.yaml @@ -3806,7 +3806,7 @@ targets: - grpc++ - grpc - name: grpclb_test - cpu_cost: 0.1 + gtest: false build: test language: c++ src: diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py index 805b0faeec..2f035abedd 100755 --- a/test/cpp/qps/gen_build_yaml.py +++ b/test/cpp/qps/gen_build_yaml.py @@ -66,7 +66,6 @@ def _scenario_json_string(scenario_json, is_tsan): def threads_required(scenario_json, where, is_tsan): scenario_json = mutate_scenario(scenario_json, is_tsan) if scenario_json['%s_config' % where]['%s_type' % where] == 'ASYNC_%s' % where.upper(): - if scenario_json['client_config']['client_channels'] == 1: return 1 return scenario_json['%s_config' % where].get('async_%s_threads' % where, 0) return scenario_json['client_config']['outstanding_rpcs_per_channel'] * scenario_json['client_config']['client_channels'] diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index cb918a0830..120a84e8a4 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3403,7 +3403,7 @@ "posix", "windows" ], - "cpu_cost": 0.1, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -41350,7 +41350,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 100, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41452,7 +41452,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41504,7 +41504,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41929,7 +41929,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 100, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42031,7 +42031,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42083,7 +42083,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42560,7 +42560,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 100, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42714,7 +42714,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42792,7 +42792,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43438,7 +43438,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 100, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43592,7 +43592,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43670,7 +43670,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", -- cgit v1.2.3 From 9fd7cf5dc3fca5a07df03b2dda08519a2e6b308a Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 25 Apr 2017 08:34:14 -0700 Subject: Recycle ports --- test/cpp/microbenchmarks/fullstack_fixtures.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'test/cpp') diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index f129ede26a..98aca1c346 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -113,13 +113,17 @@ class TCP : public FullstackFixture { public: TCP(Service* service, const FixtureConfiguration& fixture_configuration = FixtureConfiguration()) - : FullstackFixture(service, fixture_configuration, MakeAddress()) {} + : FullstackFixture(service, fixture_configuration, MakeAddress(&port_)) {} + + ~TCP() { grpc_recycle_unused_port(port_); } private: - static grpc::string MakeAddress() { - int port = grpc_pick_unused_port_or_die(); + int port_; + + static grpc::string MakeAddress(int* port) { + *port = grpc_pick_unused_port_or_die(); std::stringstream addr; - addr << "localhost:" << port; + addr << "localhost:" << *port; return addr.str(); } }; @@ -128,14 +132,18 @@ class UDS : public FullstackFixture { public: UDS(Service* service, const FixtureConfiguration& fixture_configuration = FixtureConfiguration()) - : FullstackFixture(service, fixture_configuration, MakeAddress()) {} + : FullstackFixture(service, fixture_configuration, MakeAddress(&port_)) {} + + ~UDS() { grpc_recycle_unused_port(port_); } private: - static grpc::string MakeAddress() { - int port = grpc_pick_unused_port_or_die(); // just for a unique id - not a - // real port + int port_; + + static grpc::string MakeAddress(int* port) { + *port = grpc_pick_unused_port_or_die(); // just for a unique id - not a + // real port std::stringstream addr; - addr << "unix:/tmp/bm_fullstack." << port; + addr << "unix:/tmp/bm_fullstack." << *port; return addr.str(); } }; -- cgit v1.2.3