proxygen
ContextTest.cpp File Reference
#include <folly/futures/Future.h>
#include <folly/portability/GTest.h>
#include <memory>

Go to the source code of this file.

Classes

class  TestData
 

Functions

 TEST (Context, basic)
 

Function Documentation

TEST ( Context  ,
basic   
)

Definition at line 36 of file ContextTest.cpp.

References a, folly::data(), EXPECT_EQ, EXPECT_TRUE, folly::RequestContext::get(), folly::RequestContext::getContextData(), folly::Promise< T >::getFuture(), folly::RequestContext::setContext(), folly::RequestContext::setContextData(), and folly::Promise< T >::setValue().

36  {
37  // Start a new context
39 
40  EXPECT_EQ(nullptr, RequestContext::get()->getContextData("test"));
41 
42  // Set some test data
43  RequestContext::get()->setContextData("test", std::make_unique<TestData>(10));
44 
45  // Start a future
46  Promise<Unit> p;
47  auto future = p.getFuture().thenValue([&](auto&&) {
48  // Check that the context followed the future
49  EXPECT_TRUE(RequestContext::get() != nullptr);
50  auto a =
51  dynamic_cast<TestData*>(RequestContext::get()->getContextData("test"));
52  auto data = a->data_;
53  EXPECT_EQ(10, data);
54  });
55 
56  // Clear the context
57  RequestContext::setContext(nullptr);
58 
59  EXPECT_EQ(nullptr, RequestContext::get()->getContextData("test"));
60 
61  // Fulfill the promise
62  p.setValue();
63 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Future< T > getFuture()
Definition: Promise-inl.h:97
char a
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Definition: Promise.h:326
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
Definition: submit.h:391
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43