diff options
author | Vijay Pai <vpai@google.com> | 2016-02-16 13:48:05 -0800 |
---|---|---|
committer | Vijay Pai <vpai@google.com> | 2016-02-16 13:49:22 -0800 |
commit | b65eda4c8844f98dcf2d0616406b746ac08e861d (patch) | |
tree | af2aaafafb930905839dd99b44743f1eda648e9e /test/cpp/end2end | |
parent | 837c9bda1dd517893fbce4702ff469236fb4014f (diff) |
Make the poll override function assert on non-zero timeout if invoked
from the end2end test thread itself (done by adding a TLS on that thread)
Also clang-format
Diffstat (limited to 'test/cpp/end2end')
-rw-r--r-- | test/cpp/end2end/async_end2end_test.cc | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index aa99061fe9..a15cbd7ee2 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -43,6 +43,7 @@ #include <grpc/grpc.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> +#include <grpc/support/tls.h> #include <gtest/gtest.h> #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" @@ -59,6 +60,8 @@ using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; +GPR_TLS_DECL(g_is_async_end2end_test); + namespace grpc { namespace testing { @@ -67,10 +70,12 @@ namespace { void* tag(int i) { return (void*)(intptr_t)i; } #ifdef GPR_POSIX_SOCKET -static int non_blocking_poll(struct pollfd* pfds, nfds_t nfds, - int timeout) { - /* ignore timeout and always use timeout 0 */ - return poll(pfds, nfds, 0); +static int maybe_assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds, + int timeout) { + if (gpr_tls_get(&g_is_async_end2end_test)) { + GPR_ASSERT(timeout == 0); + } + return poll(pfds, nfds, timeout); } class PollOverride { @@ -89,7 +94,7 @@ class PollOverride { class PollingOverrider : public PollOverride { public: explicit PollingOverrider(bool allow_blocking) - : PollOverride(allow_blocking ? poll : non_blocking_poll) {} + : PollOverride(allow_blocking ? poll : maybe_assert_non_blocking_poll) {} }; #else class PollingOverrider { @@ -195,6 +200,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> { builder.RegisterService(&service_); cq_ = builder.AddCompletionQueue(); server_ = builder.BuildAndStart(); + + gpr_tls_set(&g_is_async_end2end_test, 1); } void TearDown() GRPC_OVERRIDE { @@ -205,6 +212,7 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> { while (cq_->Next(&ignored_tag, &ignored_ok)) ; poll_overrider_.reset(); + gpr_tls_set(&g_is_async_end2end_test, 0); } void ResetStub() { @@ -1169,6 +1177,9 @@ INSTANTIATE_TEST_CASE_P(AsyncEnd2endServerTryCancel, int main(int argc, char** argv) { grpc_test_init(argc, argv); + gpr_tls_init(&g_is_async_end2end_test); ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + int ret = RUN_ALL_TESTS(); + gpr_tls_destroy(&g_is_async_end2end_test); + return ret; } |