[promises] Cleanup: Always assert that contexts are non-null (#31397)

pull/31298/head^2
AJ Heller 2 years ago committed by GitHub
parent fe3a482acc
commit be19b174f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/core/lib/promise/context.h
  2. 4
      test/core/promise/context_test.cc

@ -73,7 +73,7 @@ bool HasContext() {
return promise_detail::Context<T>::get() != nullptr; return promise_detail::Context<T>::get() != nullptr;
} }
// Retrieve the current value of a context. // Retrieve the current value of a context, or abort if the value is unset.
template <typename T> template <typename T>
T* GetContext() { T* GetContext() {
auto* p = promise_detail::Context<T>::get(); auto* p = promise_detail::Context<T>::get();

@ -29,7 +29,7 @@ TEST(Context, WithContext) {
EXPECT_FALSE(HasContext<TestContext>()); EXPECT_FALSE(HasContext<TestContext>());
TestContext test; TestContext test;
EXPECT_FALSE(HasContext<TestContext>()); EXPECT_FALSE(HasContext<TestContext>());
EXPECT_EQ(test.done, false); EXPECT_FALSE(test.done);
WithContext( WithContext(
[]() { []() {
EXPECT_TRUE(HasContext<TestContext>()); EXPECT_TRUE(HasContext<TestContext>());
@ -37,7 +37,7 @@ TEST(Context, WithContext) {
}, },
&test)(); &test)();
EXPECT_FALSE(HasContext<TestContext>()); EXPECT_FALSE(HasContext<TestContext>());
EXPECT_EQ(test.done, true); EXPECT_TRUE(test.done);
} }
} // namespace grpc_core } // namespace grpc_core

Loading…
Cancel
Save