Merge github.com:grpc/grpc into one-pass

Conflicts:
	Makefile
pull/1369/head
Craig Tiller 10 years ago
commit 7551fa6149
  1. 6
      BUILD
  2. 519
      Makefile
  3. 10
      build.json
  4. 4
      examples/pubsub/main.cc
  5. 2
      examples/pubsub/publisher_test.cc
  6. 2
      examples/pubsub/subscriber_test.cc
  7. 23
      include/grpc++/client_context.h
  8. 18
      include/grpc++/completion_queue.h
  9. 22
      include/grpc++/credentials.h
  10. 21
      include/grpc++/impl/grpc_library.h
  11. 4
      include/grpc++/server.h
  12. 13
      include/grpc++/server_context.h
  13. 2
      include/grpc++/stream.h
  14. 106
      include/grpc++/time.h
  15. 5
      src/cpp/client/channel.cc
  16. 4
      src/cpp/client/channel.h
  17. 15
      src/cpp/client/client_context.cc
  18. 12
      src/cpp/client/secure_credentials.cc
  19. 12
      src/cpp/common/completion_queue.cc
  20. 4
      src/cpp/server/server.cc
  21. 8
      src/cpp/server/server_context.cc
  22. 7
      src/cpp/util/time.cc
  23. 21
      templates/Makefile.template
  24. 114
      test/core/end2end/gen_build_json.py
  25. 4
      test/cpp/client/credentials_test.cc
  26. 10
      test/cpp/end2end/async_end2end_test.cc
  27. 43
      test/cpp/end2end/end2end_test.cc
  28. 8
      test/cpp/end2end/generic_end2end_test.cc
  29. 4
      test/cpp/interop/client.cc
  30. 6
      test/cpp/interop/client_helper.cc
  31. 2
      test/cpp/interop/server.cc
  32. 2
      test/cpp/qps/qps_driver.cc
  33. 3
      test/cpp/qps/smoke_test.cc
  34. 4
      test/cpp/qps/worker.cc
  35. 5
      test/cpp/util/cli_call_test.cc
  36. 4
      test/cpp/util/grpc_cli.cc
  37. 5
      test/cpp/util/time_test.cc
  38. 34
      tools/run_tests/tests.json
  39. 3
      vsprojects/grpc++/grpc++.vcxproj
  40. 9
      vsprojects/grpc++/grpc++.vcxproj.filters

@ -575,7 +575,6 @@ cc_library(
"src/cpp/client/channel.h", "src/cpp/client/channel.h",
"src/cpp/proto/proto_utils.h", "src/cpp/proto/proto_utils.h",
"src/cpp/server/thread_pool.h", "src/cpp/server/thread_pool.h",
"src/cpp/util/time.h",
"src/cpp/client/secure_credentials.cc", "src/cpp/client/secure_credentials.cc",
"src/cpp/server/secure_server_credentials.cc", "src/cpp/server/secure_server_credentials.cc",
"src/cpp/client/channel.cc", "src/cpp/client/channel.cc",
@ -617,6 +616,7 @@ cc_library(
"include/grpc++/generic_stub.h", "include/grpc++/generic_stub.h",
"include/grpc++/impl/call.h", "include/grpc++/impl/call.h",
"include/grpc++/impl/client_unary_call.h", "include/grpc++/impl/client_unary_call.h",
"include/grpc++/impl/grpc_library.h",
"include/grpc++/impl/internal_stub.h", "include/grpc++/impl/internal_stub.h",
"include/grpc++/impl/rpc_method.h", "include/grpc++/impl/rpc_method.h",
"include/grpc++/impl/rpc_service_method.h", "include/grpc++/impl/rpc_service_method.h",
@ -636,6 +636,7 @@ cc_library(
"include/grpc++/status_code_enum.h", "include/grpc++/status_code_enum.h",
"include/grpc++/stream.h", "include/grpc++/stream.h",
"include/grpc++/thread_pool_interface.h", "include/grpc++/thread_pool_interface.h",
"include/grpc++/time.h",
], ],
includes = [ includes = [
"include", "include",
@ -655,7 +656,6 @@ cc_library(
"src/cpp/client/channel.h", "src/cpp/client/channel.h",
"src/cpp/proto/proto_utils.h", "src/cpp/proto/proto_utils.h",
"src/cpp/server/thread_pool.h", "src/cpp/server/thread_pool.h",
"src/cpp/util/time.h",
"src/cpp/client/channel.cc", "src/cpp/client/channel.cc",
"src/cpp/client/channel_arguments.cc", "src/cpp/client/channel_arguments.cc",
"src/cpp/client/client_context.cc", "src/cpp/client/client_context.cc",
@ -695,6 +695,7 @@ cc_library(
"include/grpc++/generic_stub.h", "include/grpc++/generic_stub.h",
"include/grpc++/impl/call.h", "include/grpc++/impl/call.h",
"include/grpc++/impl/client_unary_call.h", "include/grpc++/impl/client_unary_call.h",
"include/grpc++/impl/grpc_library.h",
"include/grpc++/impl/internal_stub.h", "include/grpc++/impl/internal_stub.h",
"include/grpc++/impl/rpc_method.h", "include/grpc++/impl/rpc_method.h",
"include/grpc++/impl/rpc_service_method.h", "include/grpc++/impl/rpc_service_method.h",
@ -714,6 +715,7 @@ cc_library(
"include/grpc++/status_code_enum.h", "include/grpc++/status_code_enum.h",
"include/grpc++/stream.h", "include/grpc++/stream.h",
"include/grpc++/thread_pool_interface.h", "include/grpc++/thread_pool_interface.h",
"include/grpc++/time.h",
], ],
includes = [ includes = [
"include", "include",

File diff suppressed because it is too large Load Diff

@ -28,6 +28,7 @@
"include/grpc++/generic_stub.h", "include/grpc++/generic_stub.h",
"include/grpc++/impl/call.h", "include/grpc++/impl/call.h",
"include/grpc++/impl/client_unary_call.h", "include/grpc++/impl/client_unary_call.h",
"include/grpc++/impl/grpc_library.h",
"include/grpc++/impl/internal_stub.h", "include/grpc++/impl/internal_stub.h",
"include/grpc++/impl/rpc_method.h", "include/grpc++/impl/rpc_method.h",
"include/grpc++/impl/rpc_service_method.h", "include/grpc++/impl/rpc_service_method.h",
@ -46,13 +47,13 @@
"include/grpc++/status.h", "include/grpc++/status.h",
"include/grpc++/status_code_enum.h", "include/grpc++/status_code_enum.h",
"include/grpc++/stream.h", "include/grpc++/stream.h",
"include/grpc++/thread_pool_interface.h" "include/grpc++/thread_pool_interface.h",
"include/grpc++/time.h"
], ],
"headers": [ "headers": [
"src/cpp/client/channel.h", "src/cpp/client/channel.h",
"src/cpp/proto/proto_utils.h", "src/cpp/proto/proto_utils.h",
"src/cpp/server/thread_pool.h", "src/cpp/server/thread_pool.h"
"src/cpp/util/time.h"
], ],
"src": [ "src": [
"src/cpp/client/channel.cc", "src/cpp/client/channel.cc",
@ -808,6 +809,7 @@
}, },
{ {
"name": "census_statistics_multiple_writers_test", "name": "census_statistics_multiple_writers_test",
"flaky": true,
"build": "test", "build": "test",
"language": "c", "language": "c",
"src": [ "src": [
@ -822,6 +824,7 @@
}, },
{ {
"name": "census_statistics_performance_test", "name": "census_statistics_performance_test",
"flaky": true,
"build": "test", "build": "test",
"language": "c", "language": "c",
"src": [ "src": [
@ -836,6 +839,7 @@
}, },
{ {
"name": "census_statistics_quick_test", "name": "census_statistics_quick_test",
"flaky": true,
"build": "test", "build": "test",
"language": "c", "language": "c",
"src": [ "src": [

@ -31,7 +31,6 @@
* *
*/ */
#include <chrono>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
@ -65,7 +64,6 @@ const char kMessageData[] = "Test Data";
} // namespace } // namespace
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_init();
grpc::testing::InitTest(&argc, &argv, true); grpc::testing::InitTest(&argc, &argv, true);
gpr_log(GPR_INFO, "Start PUBSUB client"); gpr_log(GPR_INFO, "Start PUBSUB client");
@ -146,7 +144,5 @@ int main(int argc, char** argv) {
subscriber.Shutdown(); subscriber.Shutdown();
publisher.Shutdown(); publisher.Shutdown();
channel.reset();
grpc_shutdown();
return 0; return 0;
} }

@ -148,10 +148,8 @@ TEST_F(PublisherTest, TestPublisher) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_test_init(argc, argv); grpc_test_init(argc, argv);
grpc_init();
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
gpr_log(GPR_INFO, "Start test ..."); gpr_log(GPR_INFO, "Start test ...");
int result = RUN_ALL_TESTS(); int result = RUN_ALL_TESTS();
grpc_shutdown();
return result; return result;
} }

@ -147,10 +147,8 @@ TEST_F(SubscriberTest, TestSubscriber) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_test_init(argc, argv); grpc_test_init(argc, argv);
grpc_init();
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
gpr_log(GPR_INFO, "Start test ..."); gpr_log(GPR_INFO, "Start test ...");
int result = RUN_ALL_TESTS(); int result = RUN_ALL_TESTS();
grpc_shutdown();
return result; return result;
} }

@ -34,15 +34,13 @@
#ifndef GRPCXX_CLIENT_CONTEXT_H #ifndef GRPCXX_CLIENT_CONTEXT_H
#define GRPCXX_CLIENT_CONTEXT_H #define GRPCXX_CLIENT_CONTEXT_H
#include <chrono>
#include <map> #include <map>
#include <string> #include <string>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include <grpc++/config.h> #include <grpc++/config.h>
#include <grpc++/time.h>
using std::chrono::system_clock;
struct grpc_call; struct grpc_call;
struct grpc_completion_queue; struct grpc_completion_queue;
@ -87,8 +85,19 @@ class ClientContext {
return trailing_metadata_; return trailing_metadata_;
} }
void set_absolute_deadline(const system_clock::time_point& deadline); template <typename T>
system_clock::time_point absolute_deadline(); void set_deadline(const T& deadline) {
TimePoint<T> deadline_tp(deadline);
deadline_ = deadline_tp.raw_time();
}
#ifndef GRPC_CXX0X_NO_CHRONO
std::chrono::system_clock::time_point deadline() {
return Timespec2Timepoint(deadline_);
}
#endif // !GRPC_CXX0X_NO_CHRONO
gpr_timespec raw_deadline() { return deadline_; }
void set_authority(const grpc::string& authority) { authority_ = authority; } void set_authority(const grpc::string& authority) { authority_ = authority; }
@ -125,14 +134,12 @@ class ClientContext {
grpc_completion_queue* cq() { return cq_; } grpc_completion_queue* cq() { return cq_; }
void set_cq(grpc_completion_queue* cq) { cq_ = cq; } void set_cq(grpc_completion_queue* cq) { cq_ = cq; }
gpr_timespec RawDeadline() { return absolute_deadline_; }
grpc::string authority() { return authority_; } grpc::string authority() { return authority_; }
bool initial_metadata_received_; bool initial_metadata_received_;
grpc_call* call_; grpc_call* call_;
grpc_completion_queue* cq_; grpc_completion_queue* cq_;
gpr_timespec absolute_deadline_; gpr_timespec deadline_;
grpc::string authority_; grpc::string authority_;
std::multimap<grpc::string, grpc::string> send_initial_metadata_; std::multimap<grpc::string, grpc::string> send_initial_metadata_;
std::multimap<grpc::string, grpc::string> recv_initial_metadata_; std::multimap<grpc::string, grpc::string> recv_initial_metadata_;

@ -34,9 +34,10 @@
#ifndef GRPCXX_COMPLETION_QUEUE_H #ifndef GRPCXX_COMPLETION_QUEUE_H
#define GRPCXX_COMPLETION_QUEUE_H #define GRPCXX_COMPLETION_QUEUE_H
#include <chrono>
#include <grpc++/impl/client_unary_call.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include <grpc++/impl/client_unary_call.h>
#include <grpc++/impl/grpc_library.h>
#include <grpc++/time.h>
struct grpc_completion_queue; struct grpc_completion_queue;
@ -71,21 +72,24 @@ class CompletionQueueTag {
}; };
// grpc_completion_queue wrapper class // grpc_completion_queue wrapper class
class CompletionQueue { class CompletionQueue : public GrpcLibrary {
public: public:
CompletionQueue(); CompletionQueue();
explicit CompletionQueue(grpc_completion_queue* take); explicit CompletionQueue(grpc_completion_queue* take);
~CompletionQueue(); ~CompletionQueue() GRPC_OVERRIDE;
// Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT // Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT
enum NextStatus { SHUTDOWN, GOT_EVENT, TIMEOUT }; enum NextStatus { SHUTDOWN, GOT_EVENT, TIMEOUT };
// Nonblocking (until deadline) read from queue. // Nonblocking (until deadline) read from queue.
// Cannot rely on result of tag or ok if return is TIMEOUT // Cannot rely on result of tag or ok if return is TIMEOUT
NextStatus AsyncNext(void** tag, bool* ok, template<typename T>
std::chrono::system_clock::time_point deadline); NextStatus AsyncNext(void** tag, bool* ok, const T& deadline) {
TimePoint<T> deadline_tp(deadline);
return AsyncNextInternal(tag, ok, deadline_tp.raw_time());
}
// Blocking (until deadline) read from queue. // Blocking read from queue.
// Returns false if the queue is ready for destruction, true if event // Returns false if the queue is ready for destruction, true if event
bool Next(void** tag, bool* ok) { bool Next(void** tag, bool* ok) {

@ -34,19 +34,19 @@
#ifndef GRPCXX_CREDENTIALS_H #ifndef GRPCXX_CREDENTIALS_H
#define GRPCXX_CREDENTIALS_H #define GRPCXX_CREDENTIALS_H
#include <chrono>
#include <memory> #include <memory>
#include <grpc++/config.h> #include <grpc++/config.h>
#include <grpc++/impl/grpc_library.h>
namespace grpc { namespace grpc {
class ChannelArguments; class ChannelArguments;
class ChannelInterface; class ChannelInterface;
class SecureCredentials; class SecureCredentials;
class Credentials { class Credentials : public GrpcLibrary {
public: public:
virtual ~Credentials(); ~Credentials() GRPC_OVERRIDE;
protected: protected:
friend std::unique_ptr<Credentials> CompositeCredentials( friend std::unique_ptr<Credentials> CompositeCredentials(
@ -98,20 +98,20 @@ std::unique_ptr<Credentials> ComputeEngineCredentials();
// Builds service account credentials. // Builds service account credentials.
// json_key is the JSON key string containing the client's private key. // json_key is the JSON key string containing the client's private key.
// scope is a space-delimited list of the requested permissions. // scope is a space-delimited list of the requested permissions.
// token_lifetime is the lifetime of each token acquired through this service // token_lifetime_seconds is the lifetime in seconds of each token acquired
// account credentials. It should be positive and should not exceed // through this service account credentials. It should be positive and should
// grpc_max_auth_token_lifetime or will be cropped to this value. // not exceed grpc_max_auth_token_lifetime or will be cropped to this value.
std::unique_ptr<Credentials> ServiceAccountCredentials( std::unique_ptr<Credentials> ServiceAccountCredentials(
const grpc::string& json_key, const grpc::string& scope, const grpc::string& json_key, const grpc::string& scope,
std::chrono::seconds token_lifetime); long token_lifetime_seconds);
// Builds JWT credentials. // Builds JWT credentials.
// json_key is the JSON key string containing the client's private key. // json_key is the JSON key string containing the client's private key.
// token_lifetime is the lifetime of each Json Web Token (JWT) created with // token_lifetime_seconds is the lifetime in seconds of each Json Web Token
// this credentials. It should not exceed grpc_max_auth_token_lifetime or // (JWT) created with this credentials. It should not exceed
// will be cropped to this value. // grpc_max_auth_token_lifetime or will be cropped to this value.
std::unique_ptr<Credentials> JWTCredentials( std::unique_ptr<Credentials> JWTCredentials(
const grpc::string& json_key, std::chrono::seconds token_lifetime); const grpc::string& json_key, long token_lifetime_seconds);
// Builds refresh token credentials. // Builds refresh token credentials.
// json_refresh_token is the JSON string containing the refresh token along // json_refresh_token is the JSON string containing the refresh token along

@ -31,21 +31,20 @@
* *
*/ */
#ifndef GRPC_INTERNAL_CPP_UTIL_TIME_H #ifndef GRPCXX_IMPL_GRPC_LIBRARY_H
#define GRPC_INTERNAL_CPP_UTIL_TIME_H #define GRPCXX_IMPL_GRPC_LIBRARY_H
#include <chrono> #include <grpc/grpc.h>
#include <grpc/support/time.h>
namespace grpc { namespace grpc {
// from and to should be absolute time. class GrpcLibrary {
void Timepoint2Timespec(const std::chrono::system_clock::time_point& from, public:
gpr_timespec* to); GrpcLibrary() { grpc_init(); }
virtual ~GrpcLibrary() { grpc_shutdown(); }
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t); };
} // namespace grpc } // namespace grpc
#endif // GRPC_INTERNAL_CPP_UTIL_TIME_H
#endif // GRPCXX_IMPL_GRPC_LIBRARY_H

@ -40,6 +40,7 @@
#include <grpc++/completion_queue.h> #include <grpc++/completion_queue.h>
#include <grpc++/config.h> #include <grpc++/config.h>
#include <grpc++/impl/call.h> #include <grpc++/impl/call.h>
#include <grpc++/impl/grpc_library.h>
#include <grpc++/impl/service_type.h> #include <grpc++/impl/service_type.h>
#include <grpc++/impl/sync.h> #include <grpc++/impl/sync.h>
#include <grpc++/status.h> #include <grpc++/status.h>
@ -56,7 +57,8 @@ class ServerCredentials;
class ThreadPoolInterface; class ThreadPoolInterface;
// Currently it only supports handling rpcs in a single thread. // Currently it only supports handling rpcs in a single thread.
class Server GRPC_FINAL : private CallHook, class Server GRPC_FINAL : public GrpcLibrary,
private CallHook,
private AsynchronousService::DispatchImpl { private AsynchronousService::DispatchImpl {
public: public:
~Server(); ~Server();

@ -34,10 +34,11 @@
#ifndef GRPCXX_SERVER_CONTEXT_H #ifndef GRPCXX_SERVER_CONTEXT_H
#define GRPCXX_SERVER_CONTEXT_H #define GRPCXX_SERVER_CONTEXT_H
#include <chrono>
#include <map> #include <map>
#include <grpc/support/time.h>
#include <grpc++/config.h> #include <grpc++/config.h>
#include <grpc++/time.h>
struct gpr_timespec; struct gpr_timespec;
struct grpc_metadata; struct grpc_metadata;
@ -71,9 +72,13 @@ class ServerContext {
ServerContext(); // for async calls ServerContext(); // for async calls
~ServerContext(); ~ServerContext();
std::chrono::system_clock::time_point absolute_deadline() { #ifndef GRPC_CXX0X_NO_CHRONO
return deadline_; std::chrono::system_clock::time_point deadline() {
return Timespec2Timepoint(deadline_);
} }
#endif // !GRPC_CXX0X_NO_CHRONO
gpr_timespec raw_deadline() { return deadline_; }
void AddInitialMetadata(const grpc::string& key, const grpc::string& value); void AddInitialMetadata(const grpc::string& key, const grpc::string& value);
void AddTrailingMetadata(const grpc::string& key, const grpc::string& value); void AddTrailingMetadata(const grpc::string& key, const grpc::string& value);
@ -110,7 +115,7 @@ class ServerContext {
CompletionOp* completion_op_; CompletionOp* completion_op_;
std::chrono::system_clock::time_point deadline_; gpr_timespec deadline_;
grpc_call* call_; grpc_call* call_;
CompletionQueue* cq_; CompletionQueue* cq_;
bool sent_initial_metadata_; bool sent_initial_metadata_;

@ -173,7 +173,7 @@ class ClientWriter GRPC_FINAL : public ClientStreamingInterface,
buf.AddRecvMessage(response_); buf.AddRecvMessage(response_);
buf.AddClientRecvStatus(context_, &status); buf.AddClientRecvStatus(context_, &status);
call_.PerformOps(&buf); call_.PerformOps(&buf);
GPR_ASSERT(cq_.Pluck(&buf) && buf.got_message); GPR_ASSERT(cq_.Pluck(&buf));
return status; return status;
} }

@ -0,0 +1,106 @@
/*
*
* Copyright 2015, 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.
*
*/
#ifndef GRPCXX_TIME_H
#define GRPCXX_TIME_H
#include <grpc++/config.h>
namespace grpc {
/* If you are trying to use CompletionQueue::AsyncNext with a time class that
isn't either gpr_timespec or std::chrono::system_clock::time_point, you
will most likely be looking at this comment as your compiler will have
fired an error below. In order to fix this issue, you have two potential
solutions:
1. Use gpr_timespec or std::chrono::system_clock::time_point instead
2. Specialize the TimePoint class with whichever time class that you
want to use here. See below for two examples of how to do this.
*/
template <typename T>
class TimePoint {
public:
TimePoint(const T& time) {
you_need_a_specialization_of_TimePoint();
}
gpr_timespec raw_time() {
gpr_timespec t;
return t;
}
private:
void you_need_a_specialization_of_TimePoint();
};
template<>
class TimePoint<gpr_timespec> {
public:
TimePoint(const gpr_timespec& time) : time_(time) { }
gpr_timespec raw_time() { return time_; }
private:
gpr_timespec time_;
};
} // namespace grpc
#ifndef GRPC_CXX0X_NO_CHRONO
#include <chrono>
#include <grpc/support/time.h>
namespace grpc {
// from and to should be absolute time.
void Timepoint2Timespec(const std::chrono::system_clock::time_point& from,
gpr_timespec* to);
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t);
template <>
class TimePoint<std::chrono::system_clock::time_point> {
public:
TimePoint(const std::chrono::system_clock::time_point& time) {
Timepoint2Timespec(time, &time_);
}
gpr_timespec raw_time() const { return time_; }
private:
gpr_timespec time_;
};
} // namespace grpc
#endif // !GRPC_CXX0X_NO_CHRONO
#endif // GRPCXX_TIME_H

@ -33,7 +33,6 @@
#include "src/cpp/client/channel.h" #include "src/cpp/client/channel.h"
#include <chrono>
#include <memory> #include <memory>
#include <grpc/grpc.h> #include <grpc/grpc.h>
@ -65,12 +64,12 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context,
method.channel_tag() method.channel_tag()
? grpc_channel_create_registered_call(c_channel_, cq->cq(), ? grpc_channel_create_registered_call(c_channel_, cq->cq(),
method.channel_tag(), method.channel_tag(),
context->RawDeadline()) context->raw_deadline())
: grpc_channel_create_call(c_channel_, cq->cq(), method.name(), : grpc_channel_create_call(c_channel_, cq->cq(), method.name(),
context->authority().empty() context->authority().empty()
? target_.c_str() ? target_.c_str()
: context->authority().c_str(), : context->authority().c_str(),
context->RawDeadline()); context->raw_deadline());
GRPC_TIMER_MARK(CALL_CREATED, c_call); GRPC_TIMER_MARK(CALL_CREATED, c_call);
context->set_call(c_call); context->set_call(c_call);
return Call(c_call, this, cq); return Call(c_call, this, cq);

@ -38,6 +38,7 @@
#include <grpc++/channel_interface.h> #include <grpc++/channel_interface.h>
#include <grpc++/config.h> #include <grpc++/config.h>
#include <grpc++/impl/grpc_library.h>
struct grpc_channel; struct grpc_channel;
@ -49,7 +50,8 @@ class CompletionQueue;
class Credentials; class Credentials;
class StreamContextInterface; class StreamContextInterface;
class Channel GRPC_FINAL : public ChannelInterface { class Channel GRPC_FINAL : public GrpcLibrary,
public ChannelInterface {
public: public:
Channel(const grpc::string& target, grpc_channel* c_channel); Channel(const grpc::string& target, grpc_channel* c_channel);
~Channel() GRPC_OVERRIDE; ~Channel() GRPC_OVERRIDE;

@ -34,9 +34,7 @@
#include <grpc++/client_context.h> #include <grpc++/client_context.h>
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include "src/cpp/util/time.h" #include <grpc++/time.h>
using std::chrono::system_clock;
namespace grpc { namespace grpc {
@ -44,7 +42,7 @@ ClientContext::ClientContext()
: initial_metadata_received_(false), : initial_metadata_received_(false),
call_(nullptr), call_(nullptr),
cq_(nullptr), cq_(nullptr),
absolute_deadline_(gpr_inf_future) {} deadline_(gpr_inf_future) {}
ClientContext::~ClientContext() { ClientContext::~ClientContext() {
if (call_) { if (call_) {
@ -64,15 +62,6 @@ ClientContext::~ClientContext() {
} }
} }
void ClientContext::set_absolute_deadline(
const system_clock::time_point& deadline) {
Timepoint2Timespec(deadline, &absolute_deadline_);
}
system_clock::time_point ClientContext::absolute_deadline() {
return Timespec2Timepoint(absolute_deadline_);
}
void ClientContext::AddMetadata(const grpc::string& meta_key, void ClientContext::AddMetadata(const grpc::string& meta_key,
const grpc::string& meta_value) { const grpc::string& meta_value) {
send_initial_metadata_.insert(std::make_pair(meta_key, meta_value)); send_initial_metadata_.insert(std::make_pair(meta_key, meta_value));

@ -81,27 +81,27 @@ std::unique_ptr<Credentials> ComputeEngineCredentials() {
// Builds service account credentials. // Builds service account credentials.
std::unique_ptr<Credentials> ServiceAccountCredentials( std::unique_ptr<Credentials> ServiceAccountCredentials(
const grpc::string& json_key, const grpc::string& scope, const grpc::string& json_key, const grpc::string& scope,
std::chrono::seconds token_lifetime) { long token_lifetime_seconds) {
if (token_lifetime.count() <= 0) { if (token_lifetime_seconds <= 0) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Trying to create ServiceAccountCredentials " "Trying to create ServiceAccountCredentials "
"with non-positive lifetime"); "with non-positive lifetime");
return WrapCredentials(nullptr); return WrapCredentials(nullptr);
} }
gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count()); gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds);
return WrapCredentials(grpc_service_account_credentials_create( return WrapCredentials(grpc_service_account_credentials_create(
json_key.c_str(), scope.c_str(), lifetime)); json_key.c_str(), scope.c_str(), lifetime));
} }
// Builds JWT credentials. // Builds JWT credentials.
std::unique_ptr<Credentials> JWTCredentials( std::unique_ptr<Credentials> JWTCredentials(
const grpc::string& json_key, std::chrono::seconds token_lifetime) { const grpc::string& json_key, long token_lifetime_seconds) {
if (token_lifetime.count() <= 0) { if (token_lifetime_seconds <= 0) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Trying to create JWTCredentials with non-positive lifetime"); "Trying to create JWTCredentials with non-positive lifetime");
return WrapCredentials(nullptr); return WrapCredentials(nullptr);
} }
gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count()); gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds);
return WrapCredentials( return WrapCredentials(
grpc_jwt_credentials_create(json_key.c_str(), lifetime)); grpc_jwt_credentials_create(json_key.c_str(), lifetime));
} }

@ -36,7 +36,7 @@
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/cpp/util/time.h" #include <grpc++/time.h>
namespace grpc { namespace grpc {
@ -77,13 +77,6 @@ CompletionQueue::NextStatus CompletionQueue::AsyncNextInternal(
} }
} }
CompletionQueue::NextStatus CompletionQueue::AsyncNext(
void** tag, bool* ok, std::chrono::system_clock::time_point deadline) {
gpr_timespec gpr_deadline;
Timepoint2Timespec(deadline, &gpr_deadline);
return AsyncNextInternal(tag, ok, gpr_deadline);
}
bool CompletionQueue::Pluck(CompletionQueueTag* tag) { bool CompletionQueue::Pluck(CompletionQueueTag* tag) {
std::unique_ptr<grpc_event, EventDeleter> ev; std::unique_ptr<grpc_event, EventDeleter> ev;
@ -92,7 +85,8 @@ bool CompletionQueue::Pluck(CompletionQueueTag* tag) {
void* ignored = tag; void* ignored = tag;
GPR_ASSERT(tag->FinalizeResult(&ignored, &ok)); GPR_ASSERT(tag->FinalizeResult(&ignored, &ok));
GPR_ASSERT(ignored == tag); GPR_ASSERT(ignored == tag);
return ok; // Ignore mutations by FinalizeResult: Pluck returns the C API status
return ev->data.op_complete == GRPC_OP_OK;
} }
void CompletionQueue::TryPluck(CompletionQueueTag* tag) { void CompletionQueue::TryPluck(CompletionQueueTag* tag) {

@ -45,10 +45,10 @@
#include <grpc++/server_context.h> #include <grpc++/server_context.h>
#include <grpc++/server_credentials.h> #include <grpc++/server_credentials.h>
#include <grpc++/thread_pool_interface.h> #include <grpc++/thread_pool_interface.h>
#include <grpc++/time.h>
#include "src/core/profiling/timers.h" #include "src/core/profiling/timers.h"
#include "src/cpp/proto/proto_utils.h" #include "src/cpp/proto/proto_utils.h"
#include "src/cpp/util/time.h"
namespace grpc { namespace grpc {
@ -353,7 +353,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag {
ServerContext* ctx = ctx_ ? ctx_ : generic_ctx_; ServerContext* ctx = ctx_ ? ctx_ : generic_ctx_;
GPR_ASSERT(ctx); GPR_ASSERT(ctx);
if (*status) { if (*status) {
ctx->deadline_ = Timespec2Timepoint(call_details_.deadline); ctx->deadline_ = call_details_.deadline;
for (size_t i = 0; i < array_.count; i++) { for (size_t i = 0; i < array_.count; i++) {
ctx->client_metadata_.insert(std::make_pair( ctx->client_metadata_.insert(std::make_pair(
grpc::string(array_.metadata[i].key), grpc::string(array_.metadata[i].key),

@ -33,11 +33,11 @@
#include <grpc++/server_context.h> #include <grpc++/server_context.h>
#include <grpc++/impl/call.h>
#include <grpc++/impl/sync.h>
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/cpp/util/time.h" #include <grpc++/impl/call.h>
#include <grpc++/impl/sync.h>
#include <grpc++/time.h>
namespace grpc { namespace grpc {
@ -99,7 +99,7 @@ ServerContext::ServerContext()
ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata,
size_t metadata_count) size_t metadata_count)
: completion_op_(nullptr), : completion_op_(nullptr),
deadline_(Timespec2Timepoint(deadline)), deadline_(deadline),
call_(nullptr), call_(nullptr),
cq_(nullptr), cq_(nullptr),
sent_initial_metadata_(false) { sent_initial_metadata_(false) {

@ -31,9 +31,12 @@
* *
*/ */
#include "src/cpp/util/time.h" #include <grpc++/config.h>
#ifndef GRPC_CXX0X_NO_CHRONO
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include <grpc++/time.h>
using std::chrono::duration_cast; using std::chrono::duration_cast;
using std::chrono::nanoseconds; using std::chrono::nanoseconds;
@ -68,3 +71,5 @@ system_clock::time_point Timespec2Timepoint(gpr_timespec t) {
} }
} // namespace grpc } // namespace grpc
#endif // !GRPC_CXX0X_NO_CHRONO

@ -362,8 +362,8 @@ OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/ope
ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS) ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS) PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS) PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
PROTOC_CMD = which protoc > /dev/null PROTOC_CHECK_CMD = which protoc > /dev/null
PROTOC_CHECK_CMD = protoc --version | grep -q libprotoc.3 PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
ifeq ($(OPENSSL_REQUIRES_DL),true) ifeq ($(OPENSSL_REQUIRES_DL),true)
OPENSSL_ALPN_CHECK_CMD += -ldl OPENSSL_ALPN_CHECK_CMD += -ldl
@ -389,9 +389,9 @@ HAS_SYSTEM_ZLIB = false
HAS_SYSTEM_PROTOBUF = false HAS_SYSTEM_PROTOBUF = false
endif endif
HAS_PROTOC = $(shell $(PROTOC_CMD) 2> /dev/null && echo true || echo false) HAS_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
ifeq ($(HAS_PROTOC),true) ifeq ($(HAS_PROTOC),true)
HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
else else
HAS_VALID_PROTOC = false HAS_VALID_PROTOC = false
endif endif
@ -587,7 +587,7 @@ run_dep_checks:
$(ZLIB_CHECK_CMD) || true $(ZLIB_CHECK_CMD) || true
$(PERFTOOLS_CHECK_CMD) || true $(PERFTOOLS_CHECK_CMD) || true
$(PROTOBUF_CHECK_CMD) || true $(PROTOBUF_CHECK_CMD) || true
$(PROTOC_CHECK_CMD) || true $(PROTOC_CHECK_VERSION_CMD) || true
$(LIBDIR)/$(CONFIG)/zlib/libz.a: $(LIBDIR)/$(CONFIG)/zlib/libz.a:
$(E) "[MAKE] Building zlib" $(E) "[MAKE] Building zlib"
@ -1208,17 +1208,10 @@ endif
% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check': % if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
endif endif
% endif % endif
% for src in lib.src: % for src in lib.src:
% if not proto_re.match(src): % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \ $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
% for src2 in lib.src:
% if proto_re.match(src2):
${proto_to_cc(src2)}\
% endif % endif
% endfor
% endif
% endfor % endfor
</%def> </%def>

@ -46,60 +46,60 @@ END2END_FIXTURES = {
'chttp2_socket_pair_one_byte_at_a_time': False, 'chttp2_socket_pair_one_byte_at_a_time': False,
} }
# maps tests names to whether they run fine or not (aka, not flaky)
END2END_TESTS = {
'bad_hostname': True,
'cancel_after_accept': False,
'cancel_after_accept_and_writes_closed': True,
'cancel_after_invoke': True,
'cancel_before_invoke': True,
'cancel_in_a_vacuum': True,
'census_simple_request': True,
'disappearing_server': True,
'early_server_shutdown_finishes_inflight_calls': True,
'early_server_shutdown_finishes_tags': True,
'empty_batch': True,
'graceful_server_shutdown': True,
'invoke_large_request': False,
'max_concurrent_streams': True,
'no_op': True,
'ping_pong_streaming': True,
'request_response_with_binary_metadata_and_payload': True,
'request_response_with_metadata_and_payload': True,
'request_response_with_payload': True,
'request_with_large_metadata': True,
'request_with_payload': True,
'simple_delayed_request': True,
'simple_request': True,
'registered_call': True,
'thread_stress': True,
'writes_done_hangs_with_pending_read': True,
END2END_TESTS = [ 'cancel_after_accept_legacy': False,
'bad_hostname', 'cancel_after_accept_and_writes_closed_legacy': True,
'cancel_after_accept', 'cancel_after_invoke_legacy': True,
'cancel_after_accept_and_writes_closed', 'cancel_before_invoke_legacy': True,
'cancel_after_invoke', 'cancel_in_a_vacuum_legacy': True,
'cancel_before_invoke', 'census_simple_request_legacy': True,
'cancel_in_a_vacuum', 'disappearing_server_legacy': True,
'census_simple_request', 'early_server_shutdown_finishes_inflight_calls_legacy': True,
'disappearing_server', 'early_server_shutdown_finishes_tags_legacy': True,
'early_server_shutdown_finishes_inflight_calls', 'graceful_server_shutdown_legacy': True,
'early_server_shutdown_finishes_tags', 'invoke_large_request_legacy': False,
'empty_batch', 'max_concurrent_streams_legacy': True,
'graceful_server_shutdown', 'no_op_legacy': True,
'invoke_large_request', 'ping_pong_streaming_legacy': True,
'max_concurrent_streams', 'request_response_with_binary_metadata_and_payload_legacy': True,
'no_op', 'request_response_with_metadata_and_payload_legacy': True,
'ping_pong_streaming', 'request_response_with_payload_legacy': True,
'request_response_with_binary_metadata_and_payload', 'request_response_with_trailing_metadata_and_payload_legacy': True,
'request_response_with_metadata_and_payload', 'request_with_large_metadata_legacy': True,
'request_response_with_payload', 'request_with_payload_legacy': True,
'request_with_large_metadata', 'simple_delayed_request_legacy': True,
'request_with_payload', 'simple_request_legacy': True,
'simple_delayed_request', 'thread_stress_legacy': True,
'simple_request', 'writes_done_hangs_with_pending_read_legacy': True,
'registered_call', }
'thread_stress',
'writes_done_hangs_with_pending_read',
'cancel_after_accept_legacy',
'cancel_after_accept_and_writes_closed_legacy',
'cancel_after_invoke_legacy',
'cancel_before_invoke_legacy',
'cancel_in_a_vacuum_legacy',
'census_simple_request_legacy',
'disappearing_server_legacy',
'early_server_shutdown_finishes_inflight_calls_legacy',
'early_server_shutdown_finishes_tags_legacy',
'graceful_server_shutdown_legacy',
'invoke_large_request_legacy',
'max_concurrent_streams_legacy',
'no_op_legacy',
'ping_pong_streaming_legacy',
'request_response_with_binary_metadata_and_payload_legacy',
'request_response_with_metadata_and_payload_legacy',
'request_response_with_payload_legacy',
'request_response_with_trailing_metadata_and_payload_legacy',
'request_with_large_metadata_legacy',
'request_with_payload_legacy',
'simple_delayed_request_legacy',
'simple_request_legacy',
'thread_stress_legacy',
'writes_done_hangs_with_pending_read_legacy',
]
def main(): def main():
@ -122,7 +122,7 @@ def main():
'src': ['test/core/end2end/tests/%s.c' % t], 'src': ['test/core/end2end/tests/%s.c' % t],
'headers': ['test/core/end2end/tests/cancel_test_helpers.h'] 'headers': ['test/core/end2end/tests/cancel_test_helpers.h']
} }
for t in sorted(END2END_TESTS)] + [ for t in sorted(END2END_TESTS.keys())] + [
{ {
'name': 'end2end_certs', 'name': 'end2end_certs',
'build': 'private', 'build': 'private',
@ -140,7 +140,7 @@ def main():
'build': 'test', 'build': 'test',
'language': 'c', 'language': 'c',
'src': [], 'src': [],
'flaky': 'invoke_large_request' in t, 'flaky': not END2END_TESTS[t],
'deps': [ 'deps': [
'end2end_fixture_%s' % f, 'end2end_fixture_%s' % f,
'end2end_test_%s' % t, 'end2end_test_%s' % t,
@ -152,7 +152,7 @@ def main():
] ]
} }
for f in sorted(END2END_FIXTURES.keys()) for f in sorted(END2END_FIXTURES.keys())
for t in sorted(END2END_TESTS)] + [ for t in sorted(END2END_TESTS.keys())] + [
{ {
'name': '%s_%s_unsecure_test' % (f, t), 'name': '%s_%s_unsecure_test' % (f, t),
'build': 'test', 'build': 'test',
@ -170,7 +170,7 @@ def main():
] ]
} }
for f in sorted(END2END_FIXTURES.keys()) if not END2END_FIXTURES[f] for f in sorted(END2END_FIXTURES.keys()) if not END2END_FIXTURES[f]
for t in sorted(END2END_TESTS)]} for t in sorted(END2END_TESTS.keys())]}
print simplejson.dumps(json, sort_keys=True, indent=2 * ' ') print simplejson.dumps(json, sort_keys=True, indent=2 * ' ')

@ -47,7 +47,7 @@ class CredentialsTest : public ::testing::Test {
TEST_F(CredentialsTest, InvalidServiceAccountCreds) { TEST_F(CredentialsTest, InvalidServiceAccountCreds) {
std::unique_ptr<Credentials> bad1 = std::unique_ptr<Credentials> bad1 =
ServiceAccountCredentials("", "", std::chrono::seconds(1)); ServiceAccountCredentials("", "", 1);
EXPECT_EQ(nullptr, bad1.get()); EXPECT_EQ(nullptr, bad1.get());
} }
@ -56,8 +56,6 @@ TEST_F(CredentialsTest, InvalidServiceAccountCreds) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
grpc_init();
int ret = RUN_ALL_TESTS(); int ret = RUN_ALL_TESTS();
grpc_shutdown();
return ret; return ret;
} }

@ -31,13 +31,12 @@
* *
*/ */
#include <chrono>
#include <memory> #include <memory>
#include "test/core/util/port.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
#include "test/cpp/util/echo_duplicate.grpc.pb.h" #include "test/cpp/util/echo_duplicate.grpc.pb.h"
#include "test/cpp/util/echo.grpc.pb.h" #include "test/cpp/util/echo.grpc.pb.h"
#include "src/cpp/util/time.h"
#include <grpc++/async_unary_call.h> #include <grpc++/async_unary_call.h>
#include <grpc++/channel_arguments.h> #include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h> #include <grpc++/channel_interface.h>
@ -50,7 +49,7 @@
#include <grpc++/server_credentials.h> #include <grpc++/server_credentials.h>
#include <grpc++/status.h> #include <grpc++/status.h>
#include <grpc++/stream.h> #include <grpc++/stream.h>
#include "test/core/util/port.h" #include <grpc++/time.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <grpc/grpc.h> #include <grpc/grpc.h>
@ -595,9 +594,6 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_test_init(argc, argv); grpc_test_init(argc, argv);
grpc_init();
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS(); return RUN_ALL_TESTS();
grpc_shutdown();
return result;
} }

@ -31,13 +31,12 @@
* *
*/ */
#include <chrono>
#include <thread> #include <thread>
#include "test/core/util/port.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
#include "test/cpp/util/echo_duplicate.grpc.pb.h" #include "test/cpp/util/echo_duplicate.grpc.pb.h"
#include "test/cpp/util/echo.grpc.pb.h" #include "test/cpp/util/echo.grpc.pb.h"
#include "src/cpp/util/time.h"
#include "src/cpp/server/thread_pool.h" #include "src/cpp/server/thread_pool.h"
#include <grpc++/channel_arguments.h> #include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h> #include <grpc++/channel_interface.h>
@ -50,7 +49,7 @@
#include <grpc++/server_credentials.h> #include <grpc++/server_credentials.h>
#include <grpc++/status.h> #include <grpc++/status.h>
#include <grpc++/stream.h> #include <grpc++/stream.h>
#include "test/core/util/port.h" #include <grpc++/time.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <grpc/grpc.h> #include <grpc/grpc.h>
@ -72,8 +71,8 @@ void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request,
EchoResponse* response) { EchoResponse* response) {
if (request->has_param() && request->param().echo_deadline()) { if (request->has_param() && request->param().echo_deadline()) {
gpr_timespec deadline = gpr_inf_future; gpr_timespec deadline = gpr_inf_future;
if (context->absolute_deadline() != system_clock::time_point::max()) { if (context->deadline() != system_clock::time_point::max()) {
Timepoint2Timespec(context->absolute_deadline(), &deadline); Timepoint2Timespec(context->deadline(), &deadline);
} }
response->mutable_param()->set_request_deadline(deadline.tv_sec); response->mutable_param()->set_request_deadline(deadline.tv_sec);
} }
@ -245,7 +244,7 @@ TEST_F(End2endTest, RpcDeadlineExpires) {
ClientContext context; ClientContext context;
std::chrono::system_clock::time_point deadline = std::chrono::system_clock::time_point deadline =
std::chrono::system_clock::now() + std::chrono::microseconds(10); std::chrono::system_clock::now() + std::chrono::microseconds(10);
context.set_absolute_deadline(deadline); context.set_deadline(deadline);
Status s = stub_->Echo(&context, request, &response); Status s = stub_->Echo(&context, request, &response);
EXPECT_EQ(StatusCode::DEADLINE_EXCEEDED, s.code()); EXPECT_EQ(StatusCode::DEADLINE_EXCEEDED, s.code());
} }
@ -260,7 +259,7 @@ TEST_F(End2endTest, RpcLongDeadline) {
ClientContext context; ClientContext context;
std::chrono::system_clock::time_point deadline = std::chrono::system_clock::time_point deadline =
std::chrono::system_clock::now() + std::chrono::hours(1); std::chrono::system_clock::now() + std::chrono::hours(1);
context.set_absolute_deadline(deadline); context.set_deadline(deadline);
Status s = stub_->Echo(&context, request, &response); Status s = stub_->Echo(&context, request, &response);
EXPECT_EQ(response.message(), request.message()); EXPECT_EQ(response.message(), request.message());
EXPECT_TRUE(s.IsOk()); EXPECT_TRUE(s.IsOk());
@ -277,7 +276,7 @@ TEST_F(End2endTest, EchoDeadline) {
ClientContext context; ClientContext context;
std::chrono::system_clock::time_point deadline = std::chrono::system_clock::time_point deadline =
std::chrono::system_clock::now() + std::chrono::seconds(100); std::chrono::system_clock::now() + std::chrono::seconds(100);
context.set_absolute_deadline(deadline); context.set_deadline(deadline);
Status s = stub_->Echo(&context, request, &response); Status s = stub_->Echo(&context, request, &response);
EXPECT_EQ(response.message(), request.message()); EXPECT_EQ(response.message(), request.message());
EXPECT_TRUE(s.IsOk()); EXPECT_TRUE(s.IsOk());
@ -428,7 +427,7 @@ TEST_F(End2endTest, DiffPackageServices) {
// rpc and stream should fail on bad credentials. // rpc and stream should fail on bad credentials.
TEST_F(End2endTest, BadCredentials) { TEST_F(End2endTest, BadCredentials) {
std::unique_ptr<Credentials> bad_creds = std::unique_ptr<Credentials> bad_creds =
ServiceAccountCredentials("", "", std::chrono::seconds(1)); ServiceAccountCredentials("", "", 1);
EXPECT_EQ(nullptr, bad_creds.get()); EXPECT_EQ(nullptr, bad_creds.get());
std::shared_ptr<ChannelInterface> channel = std::shared_ptr<ChannelInterface> channel =
CreateChannel(server_address_.str(), bad_creds, ChannelArguments()); CreateChannel(server_address_.str(), bad_creds, ChannelArguments());
@ -491,6 +490,27 @@ TEST_F(End2endTest, ServerCancelsRpc) {
EXPECT_TRUE(s.details().empty()); EXPECT_TRUE(s.details().empty());
} }
// Client cancels request stream after sending two messages
TEST_F(End2endTest, ClientCancelsRequestStream) {
ResetStub();
EchoRequest request;
EchoResponse response;
ClientContext context;
request.set_message("hello");
auto stream = stub_->RequestStream(&context, &response);
EXPECT_TRUE(stream->Write(request));
EXPECT_TRUE(stream->Write(request));
context.TryCancel();
Status s = stream->Finish();
EXPECT_EQ(grpc::StatusCode::CANCELLED, s.code());
EXPECT_EQ(response.message(), "");
}
// Client cancels server stream after sending some messages // Client cancels server stream after sending some messages
TEST_F(End2endTest, ClientCancelsResponseStream) { TEST_F(End2endTest, ClientCancelsResponseStream) {
ResetStub(); ResetStub();
@ -562,9 +582,6 @@ TEST_F(End2endTest, ClientCancelsBidi) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_test_init(argc, argv); grpc_test_init(argc, argv);
grpc_init();
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS(); return RUN_ALL_TESTS();
grpc_shutdown();
return result;
} }

@ -31,11 +31,9 @@
* *
*/ */
#include <chrono>
#include <memory> #include <memory>
#include "src/cpp/proto/proto_utils.h" #include "src/cpp/proto/proto_utils.h"
#include "src/cpp/util/time.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
#include "test/cpp/util/echo.grpc.pb.h" #include "test/cpp/util/echo.grpc.pb.h"
@ -55,6 +53,7 @@
#include <grpc++/slice.h> #include <grpc++/slice.h>
#include <grpc++/status.h> #include <grpc++/status.h>
#include <grpc++/stream.h> #include <grpc++/stream.h>
#include <grpc++/time.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <grpc/grpc.h> #include <grpc/grpc.h>
@ -280,9 +279,6 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_test_init(argc, argv); grpc_test_init(argc, argv);
grpc_init();
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS(); return RUN_ALL_TESTS();
grpc_shutdown();
return result;
} }

@ -76,8 +76,6 @@ using grpc::testing::CreateChannelForTestCase;
using grpc::testing::GetServiceAccountJsonKey; using grpc::testing::GetServiceAccountJsonKey;
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_init();
grpc::testing::InitTest(&argc, &argv, true); grpc::testing::InitTest(&argc, &argv, true);
int ret = 0; int ret = 0;
@ -129,8 +127,6 @@ int main(int argc, char** argv) {
FLAGS_test_case.c_str()); FLAGS_test_case.c_str());
ret = 1; ret = 1;
} }
client.Reset(nullptr);
grpc_shutdown();
return ret; return ret;
} }

@ -85,8 +85,9 @@ std::shared_ptr<ChannelInterface> CreateChannelForTestCase(
std::unique_ptr<Credentials> creds; std::unique_ptr<Credentials> creds;
GPR_ASSERT(FLAGS_enable_ssl); GPR_ASSERT(FLAGS_enable_ssl);
grpc::string json_key = GetServiceAccountJsonKey(); grpc::string json_key = GetServiceAccountJsonKey();
std::chrono::seconds token_lifetime = std::chrono::hours(1);
creds = ServiceAccountCredentials(json_key, FLAGS_oauth_scope, creds = ServiceAccountCredentials(json_key, FLAGS_oauth_scope,
std::chrono::hours(1)); token_lifetime.count());
return CreateTestChannel(host_port, FLAGS_server_host_override, return CreateTestChannel(host_port, FLAGS_server_host_override,
FLAGS_enable_ssl, FLAGS_use_prod_roots, creds); FLAGS_enable_ssl, FLAGS_use_prod_roots, creds);
} else if (test_case == "compute_engine_creds") { } else if (test_case == "compute_engine_creds") {
@ -99,7 +100,8 @@ std::shared_ptr<ChannelInterface> CreateChannelForTestCase(
std::unique_ptr<Credentials> creds; std::unique_ptr<Credentials> creds;
GPR_ASSERT(FLAGS_enable_ssl); GPR_ASSERT(FLAGS_enable_ssl);
grpc::string json_key = GetServiceAccountJsonKey(); grpc::string json_key = GetServiceAccountJsonKey();
creds = JWTCredentials(json_key, std::chrono::hours(1)); std::chrono::seconds token_lifetime = std::chrono::hours(1);
creds = JWTCredentials(json_key, token_lifetime.count());
return CreateTestChannel(host_port, FLAGS_server_host_override, return CreateTestChannel(host_port, FLAGS_server_host_override,
FLAGS_enable_ssl, FLAGS_use_prod_roots, creds); FLAGS_enable_ssl, FLAGS_use_prod_roots, creds);
} else { } else {

@ -218,13 +218,11 @@ void RunServer() {
static void sigint_handler(int x) { got_sigint = true; } static void sigint_handler(int x) { got_sigint = true; }
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_init();
grpc::testing::InitTest(&argc, &argv, true); grpc::testing::InitTest(&argc, &argv, true);
signal(SIGINT, sigint_handler); signal(SIGINT, sigint_handler);
GPR_ASSERT(FLAGS_port != 0); GPR_ASSERT(FLAGS_port != 0);
RunServer(); RunServer();
grpc_shutdown();
return 0; return 0;
} }

@ -69,7 +69,6 @@ using grpc::testing::RpcType;
using grpc::testing::ResourceUsage; using grpc::testing::ResourceUsage;
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_init();
grpc::testing::InitTest(&argc, &argv, true); grpc::testing::InitTest(&argc, &argv, true);
RpcType rpc_type; RpcType rpc_type;
@ -104,6 +103,5 @@ int main(int argc, char** argv) {
ReportLatency(result); ReportLatency(result);
ReportTimes(result); ReportTimes(result);
grpc_shutdown();
return 0; return 0;
} }

@ -136,14 +136,11 @@ static void RunQPS() {
} // namespace grpc } // namespace grpc
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_init();
using namespace grpc::testing; using namespace grpc::testing;
RunSynchronousStreamingPingPong(); RunSynchronousStreamingPingPong();
RunSynchronousUnaryPingPong(); RunSynchronousUnaryPingPong();
RunAsyncUnaryPingPong(); RunAsyncUnaryPingPong();
RunQPS(); RunQPS();
grpc_shutdown();
return 0; return 0;
} }

@ -64,13 +64,11 @@ static void RunServer() {
} // namespace grpc } // namespace grpc
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_init();
grpc::testing::InitTest(&argc, &argv, true); grpc::testing::InitTest(&argc, &argv, true);
signal(SIGINT, sigint_handler); signal(SIGINT, sigint_handler);
grpc::testing::RunServer(); grpc::testing::RunServer();
grpc_shutdown();
return 0; return 0;
} }

@ -123,9 +123,6 @@ TEST_F(CliCallTest, SimpleRpc) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_test_init(argc, argv); grpc_test_init(argc, argv);
grpc_init();
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS(); return RUN_ALL_TESTS();
grpc_shutdown();
return result;
} }

@ -79,8 +79,6 @@ DEFINE_string(output_binary_file, "output.bin",
"Path to output file to write serialized response."); "Path to output file to write serialized response.");
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc_init();
grpc::testing::InitTest(&argc, &argv, true); grpc::testing::InitTest(&argc, &argv, true);
if (argc < 4 || grpc::string(argv[1]) != "call") { if (argc < 4 || grpc::string(argv[1]) != "call") {
@ -127,7 +125,5 @@ int main(int argc, char** argv) {
output_file << response; output_file << response;
} }
channel.reset();
grpc_shutdown();
return 0; return 0;
} }

@ -31,11 +31,8 @@
* *
*/ */
#include "src/cpp/util/time.h"
#include <chrono>
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include <grpc++/time.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
using std::chrono::duration_cast; using std::chrono::duration_cast;

@ -65,7 +65,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "census_statistics_multiple_writers_test", "name": "census_statistics_multiple_writers_test",
"platforms": [ "platforms": [
@ -74,7 +74,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "census_statistics_performance_test", "name": "census_statistics_performance_test",
"platforms": [ "platforms": [
@ -83,7 +83,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "census_statistics_quick_test", "name": "census_statistics_quick_test",
"platforms": [ "platforms": [
@ -703,7 +703,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_fake_security_cancel_after_accept_test", "name": "chttp2_fake_security_cancel_after_accept_test",
"platforms": [ "platforms": [
@ -730,7 +730,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_fake_security_cancel_after_accept_legacy_test", "name": "chttp2_fake_security_cancel_after_accept_legacy_test",
"platforms": [ "platforms": [
@ -1153,7 +1153,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_fullstack_cancel_after_accept_test", "name": "chttp2_fullstack_cancel_after_accept_test",
"platforms": [ "platforms": [
@ -1180,7 +1180,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_fullstack_cancel_after_accept_legacy_test", "name": "chttp2_fullstack_cancel_after_accept_legacy_test",
"platforms": [ "platforms": [
@ -1603,7 +1603,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_fullstack_uds_cancel_after_accept_test", "name": "chttp2_fullstack_uds_cancel_after_accept_test",
"platforms": [ "platforms": [
@ -1630,7 +1630,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_fullstack_uds_cancel_after_accept_legacy_test", "name": "chttp2_fullstack_uds_cancel_after_accept_legacy_test",
"platforms": [ "platforms": [
@ -2053,7 +2053,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_simple_ssl_fullstack_cancel_after_accept_test", "name": "chttp2_simple_ssl_fullstack_cancel_after_accept_test",
"platforms": [ "platforms": [
@ -2080,7 +2080,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_simple_ssl_fullstack_cancel_after_accept_legacy_test", "name": "chttp2_simple_ssl_fullstack_cancel_after_accept_legacy_test",
"platforms": [ "platforms": [
@ -2503,7 +2503,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_test", "name": "chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_test",
"platforms": [ "platforms": [
@ -2530,7 +2530,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_legacy_test", "name": "chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_legacy_test",
"platforms": [ "platforms": [
@ -2953,7 +2953,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_socket_pair_cancel_after_accept_test", "name": "chttp2_socket_pair_cancel_after_accept_test",
"platforms": [ "platforms": [
@ -2980,7 +2980,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_socket_pair_cancel_after_accept_legacy_test", "name": "chttp2_socket_pair_cancel_after_accept_legacy_test",
"platforms": [ "platforms": [
@ -3403,7 +3403,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_test", "name": "chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_test",
"platforms": [ "platforms": [
@ -3430,7 +3430,7 @@
] ]
}, },
{ {
"flaky": false, "flaky": true,
"language": "c", "language": "c",
"name": "chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_legacy_test", "name": "chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_legacy_test",
"platforms": [ "platforms": [

@ -96,6 +96,7 @@
<ClInclude Include="..\..\include\grpc++\generic_stub.h" /> <ClInclude Include="..\..\include\grpc++\generic_stub.h" />
<ClInclude Include="..\..\include\grpc++\impl\call.h" /> <ClInclude Include="..\..\include\grpc++\impl\call.h" />
<ClInclude Include="..\..\include\grpc++\impl\client_unary_call.h" /> <ClInclude Include="..\..\include\grpc++\impl\client_unary_call.h" />
<ClInclude Include="..\..\include\grpc++\impl\grpc_library.h" />
<ClInclude Include="..\..\include\grpc++\impl\internal_stub.h" /> <ClInclude Include="..\..\include\grpc++\impl\internal_stub.h" />
<ClInclude Include="..\..\include\grpc++\impl\rpc_method.h" /> <ClInclude Include="..\..\include\grpc++\impl\rpc_method.h" />
<ClInclude Include="..\..\include\grpc++\impl\rpc_service_method.h" /> <ClInclude Include="..\..\include\grpc++\impl\rpc_service_method.h" />
@ -115,6 +116,7 @@
<ClInclude Include="..\..\include\grpc++\status_code_enum.h" /> <ClInclude Include="..\..\include\grpc++\status_code_enum.h" />
<ClInclude Include="..\..\include\grpc++\stream.h" /> <ClInclude Include="..\..\include\grpc++\stream.h" />
<ClInclude Include="..\..\include\grpc++\thread_pool_interface.h" /> <ClInclude Include="..\..\include\grpc++\thread_pool_interface.h" />
<ClInclude Include="..\..\include\grpc++\time.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\src\cpp\client\secure_credentials.h" /> <ClInclude Include="..\..\src\cpp\client\secure_credentials.h" />
@ -122,7 +124,6 @@
<ClInclude Include="..\..\src\cpp\client\channel.h" /> <ClInclude Include="..\..\src\cpp\client\channel.h" />
<ClInclude Include="..\..\src\cpp\proto\proto_utils.h" /> <ClInclude Include="..\..\src\cpp\proto\proto_utils.h" />
<ClInclude Include="..\..\src\cpp\server\thread_pool.h" /> <ClInclude Include="..\..\src\cpp\server\thread_pool.h" />
<ClInclude Include="..\..\src\cpp\util\time.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\src\cpp\client\secure_credentials.cc"> <ClCompile Include="..\..\src\cpp\client\secure_credentials.cc">

@ -120,6 +120,9 @@
<ClInclude Include="..\..\include\grpc++\impl\client_unary_call.h"> <ClInclude Include="..\..\include\grpc++\impl\client_unary_call.h">
<Filter>include\grpc++\impl</Filter> <Filter>include\grpc++\impl</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\include\grpc++\impl\grpc_library.h">
<Filter>include\grpc++\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\include\grpc++\impl\internal_stub.h"> <ClInclude Include="..\..\include\grpc++\impl\internal_stub.h">
<Filter>include\grpc++\impl</Filter> <Filter>include\grpc++\impl</Filter>
</ClInclude> </ClInclude>
@ -177,6 +180,9 @@
<ClInclude Include="..\..\include\grpc++\thread_pool_interface.h"> <ClInclude Include="..\..\include\grpc++\thread_pool_interface.h">
<Filter>include\grpc++</Filter> <Filter>include\grpc++</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\include\grpc++\time.h">
<Filter>include\grpc++</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\src\cpp\client\secure_credentials.h"> <ClInclude Include="..\..\src\cpp\client\secure_credentials.h">
@ -194,9 +200,6 @@
<ClInclude Include="..\..\src\cpp\server\thread_pool.h"> <ClInclude Include="..\..\src\cpp\server\thread_pool.h">
<Filter>src\cpp\server</Filter> <Filter>src\cpp\server</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\cpp\util\time.h">
<Filter>src\cpp\util</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save