diff --git a/src/core/iomgr/pollset_posix.h b/src/core/iomgr/pollset_posix.h index b34bb094268..5868b3fa21c 100644 --- a/src/core/iomgr/pollset_posix.h +++ b/src/core/iomgr/pollset_posix.h @@ -142,6 +142,10 @@ int grpc_pollset_has_workers(grpc_pollset *pollset); void grpc_remove_fd_from_all_epoll_sets(int fd); /* override to allow tests to hook poll() usage */ +/* NOTE: Any changes to grpc_poll_function must take place when the gRPC + is certainly not doing any polling anywhere. + Otherwise, there might be a race between changing the variable and actually + doing a polling operation */ typedef int (*grpc_poll_function_type)(struct pollfd *, nfds_t, int); extern grpc_poll_function_type grpc_poll_function; extern grpc_wakeup_fd grpc_global_wakeup_fd; diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index a194c615cdf..78417fc6d0b 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -86,21 +86,21 @@ class PollOverride { grpc_poll_function_type prev_; }; -class PollingCheckRegion : public PollOverride { +class PollingOverrider : public PollOverride { public: - explicit PollingCheckRegion(bool allow_blocking) + explicit PollingOverrider(bool allow_blocking) : PollOverride(allow_blocking ? poll : assert_non_blocking_poll) {} }; #else -class PollingCheckRegion { +class PollingOverrider { public: - explicit PollingCheckRegion(bool allow_blocking) {} + explicit PollingOverrider(bool allow_blocking) {} }; #endif -class Verifier : public PollingCheckRegion { +class Verifier { public: - explicit Verifier(bool spin) : PollingCheckRegion(!spin), spin_(spin) {} + explicit Verifier(bool spin) : spin_(spin) {} Verifier& Expect(int i, bool expect_ok) { expectations_[tag(i)] = expect_ok; return *this; @@ -180,7 +180,7 @@ class Verifier : public PollingCheckRegion { class AsyncEnd2endTest : public ::testing::TestWithParam { protected: - AsyncEnd2endTest() {} + AsyncEnd2endTest(): poll_override_(GetParam()) {} void SetUp() GRPC_OVERRIDE { int port = grpc_pick_unused_port_or_die(); @@ -249,6 +249,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam { std::unique_ptr server_; grpc::testing::EchoTestService::AsyncService service_; std::ostringstream server_address_; + + PollingOverrider poll_override_; }; TEST_P(AsyncEnd2endTest, SimpleRpc) {