diff --git a/src/core/lib/event_engine/promise.h b/src/core/lib/event_engine/promise.h index 6ca9fb04dae..c92c95d0f1d 100644 --- a/src/core/lib/event_engine/promise.h +++ b/src/core/lib/event_engine/promise.h @@ -15,8 +15,6 @@ #define GRPC_CORE_LIB_EVENT_ENGINE_PROMISE_H #include -#include "absl/time/time.h" - #include #include "src/core/lib/gprpp/sync.h" @@ -27,8 +25,8 @@ namespace experimental { /// A minimal promise implementation. /// /// This is light-duty, syntactical sugar around cv wait & signal, which is -/// useful in some cases. A more robust implementation is being worked on -/// separately. +/// useful in some cases. +/// TODO(ctiller): Find a new name for this type. template class Promise { public: @@ -38,13 +36,10 @@ class Promise { explicit Promise(T&& val) : val_(val) {} // The getter will wait until the setter has been called, and will return the // value passed during Set. - T& Get() { return WaitWithTimeout(absl::Hours(1)); } - // The getter will wait with timeout until the setter has been called, and - // will return the value passed during Set. - T& WaitWithTimeout(absl::Duration d) { + T& Get() { grpc_core::MutexLock lock(&mu_); - if (!set_) { - cv_.WaitWithTimeout(&mu_, d); + while (!set_) { + cv_.Wait(&mu_); } return val_; } diff --git a/test/core/event_engine/common_closures_test.cc b/test/core/event_engine/common_closures_test.cc index 34f10b9befd..e9a9ada29c1 100644 --- a/test/core/event_engine/common_closures_test.cc +++ b/test/core/event_engine/common_closures_test.cc @@ -31,7 +31,7 @@ TEST_F(AnyInvocableClosureTest, CallsItsFunction) { Promise promise; AnyInvocableClosure closure([&promise] { promise.Set(true); }); closure.Run(); - ASSERT_TRUE(promise.WaitWithTimeout(absl::Seconds(3))); + ASSERT_TRUE(promise.Get()); } class SelfDeletingClosureTest : public testing::Test {}; @@ -41,7 +41,7 @@ TEST_F(SelfDeletingClosureTest, CallsItsFunction) { auto* closure = SelfDeletingClosure::Create([&promise] { promise.Set(true); }); closure->Run(); - ASSERT_TRUE(promise.WaitWithTimeout(absl::Seconds(3))); + ASSERT_TRUE(promise.Get()); // ASAN should catch if this closure is not deleted } @@ -52,8 +52,8 @@ TEST_F(SelfDeletingClosureTest, CallsItsFunctionAndIsDestroyed) { SelfDeletingClosure::Create([&fn_called] { fn_called.Set(true); }, [&destroyed] { destroyed.Set(true); }); closure->Run(); - ASSERT_TRUE(fn_called.WaitWithTimeout(absl::Seconds(3))); - ASSERT_TRUE(destroyed.WaitWithTimeout(absl::Seconds(3))); + ASSERT_TRUE(fn_called.Get()); + ASSERT_TRUE(destroyed.Get()); } int main(int argc, char** argv) { diff --git a/test/core/event_engine/posix/event_poller_posix_test.cc b/test/core/event_engine/posix/event_poller_posix_test.cc index 300a5b84c1b..77a6338bbd0 100644 --- a/test/core/event_engine/posix/event_poller_posix_test.cc +++ b/test/core/event_engine/posix/event_poller_posix_test.cc @@ -680,7 +680,7 @@ class Worker : public grpc_core::DualRefCounted { } void Wait() { - EXPECT_TRUE(promise.WaitWithTimeout(absl::Seconds(60))); + EXPECT_TRUE(promise.Get()); WeakUnref(); } diff --git a/test/core/event_engine/windows/iocp_test.cc b/test/core/event_engine/windows/iocp_test.cc index 8718fca2d1a..13f2c308ff8 100644 --- a/test/core/event_engine/windows/iocp_test.cc +++ b/test/core/event_engine/windows/iocp_test.cc @@ -126,8 +126,8 @@ TEST_F(IOCPTest, ClientReceivesNotificationOfServerSend) { ASSERT_EQ(closures.size(), 1); executor.Run(closures[0]); // wait for the callbacks to run - ASSERT_TRUE(read_called.WaitWithTimeout(absl::Seconds(10))); - ASSERT_TRUE(write_called.WaitWithTimeout(absl::Seconds(10))); + ASSERT_TRUE(read_called.Get()); + ASSERT_TRUE(write_called.Get()); delete on_read; delete on_write; @@ -193,7 +193,7 @@ TEST_F(IOCPTest, IocpWorkTimeoutDueToNoNotificationRegistered) { // register the closure, which should trigger it immediately. wrapped_client_socket->NotifyOnRead(on_read); // wait for the callbacks to run - ASSERT_TRUE(read_called.WaitWithTimeout(absl::Seconds(10))); + ASSERT_TRUE(read_called.Get()); delete on_read; wrapped_client_socket->MaybeShutdown(absl::OkStatus()); @@ -215,7 +215,7 @@ TEST_F(IOCPTest, KickWorks) { iocp.Kick(); }); // wait for the callbacks to run - ASSERT_TRUE(kicked.WaitWithTimeout(absl::Seconds(10))); + ASSERT_TRUE(kicked.Get()); } TEST_F(IOCPTest, KickThenShutdownCasusesNextWorkerToBeKicked) {