proxygen
TimeoutTest Class Reference
Inheritance diagram for TimeoutTest:
testing::Test

Public Member Functions

void SetUp () override
 
void loop ()
 
void setClock (milliseconds ms)
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 
virtual ~Test ()
 
virtual ~Test ()
 

Protected Attributes

MockTimeoutManager timeoutManager_
 
MockTimeoutClock timeoutClock_
 
boost::container::flat_multimap< milliseconds, AsyncTimeout * > timeouts_
 

Additional Inherited Members

- Public Types inherited from testing::Test
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
- Static Public Member Functions inherited from testing::Test
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void TearDown ()
 

Detailed Description

Definition at line 87 of file AsyncTimeoutSetTest.cpp.

Member Function Documentation

void TimeoutTest::loop ( )
inline

Definition at line 117 of file AsyncTimeoutSetTest.cpp.

References folly::pushmi::detail::t.

117  {
118  for (auto t = timeoutClock_.millisecondsSinceEpoch() + milliseconds(1);
119  !timeouts_.empty(); t++) {
120  setClock(t);
121  }
122  }
boost::container::flat_multimap< milliseconds, AsyncTimeout * > timeouts_
MockTimeoutClock timeoutClock_
virtual std::chrono::milliseconds millisecondsSinceEpoch()=0
void setClock(milliseconds ms)
void TimeoutTest::setClock ( milliseconds  ms)
inline

Definition at line 124 of file AsyncTimeoutSetTest.cpp.

References folly::event_ref_flags(), EXPECT_CALL, folly::AsyncTimeout::getEvent(), proxygen::millisecondsSinceEpoch(), testing::Return(), and folly::AsyncTimeout::timeoutExpired().

124  {
126  .WillRepeatedly(Return(ms));
127 
128  while (!timeouts_.empty() &&
129  timeoutClock_.millisecondsSinceEpoch() >= timeouts_.begin()->first) {
130  AsyncTimeout* timeout = timeouts_.begin()->second;
131  timeouts_.erase(timeouts_.begin());
132  folly::event_ref_flags(timeout->getEvent()) &= ~EVLIST_TIMEOUT;
133  timeout->timeoutExpired();
134  }
135  }
boost::container::flat_multimap< milliseconds, AsyncTimeout * > timeouts_
MockTimeoutClock timeoutClock_
struct event * getEvent()
Definition: AsyncTimeout.h:150
auto event_ref_flags(struct event *ev) -> decltype(std::ref(ev->ev_flags))
Definition: EventUtil.h:41
virtual std::chrono::milliseconds millisecondsSinceEpoch()=0
virtual void timeoutExpired() noexcept=0
#define EXPECT_CALL(obj, call)
std::chrono::milliseconds millisecondsSinceEpoch()
Definition: Time.h:56
internal::ReturnAction< R > Return(R value)
void TimeoutTest::SetUp ( )
inlineoverridevirtual

Reimplemented from testing::Test.

Definition at line 90 of file AsyncTimeoutSetTest.cpp.

References testing::_, folly::event_ref_flags(), EXPECT_CALL, folly::AsyncTimeout::getEvent(), testing::Invoke(), testing::Return(), TestTimeout::setTimeoutClock(), and folly::pushmi::detail::t.

90  {
92  setClock(milliseconds(0));
93 
94  EXPECT_CALL(timeoutManager_, attachTimeoutManager(_, _))
95  .WillRepeatedly(Return());
96 
97  EXPECT_CALL(timeoutManager_, scheduleTimeout(_, _))
98  .WillRepeatedly(Invoke([this] (AsyncTimeout* p, milliseconds t) {
100  folly::event_ref_flags(p->getEvent()) |= EVLIST_TIMEOUT;
102  p);
103  return true;
104  }));
105 
106  EXPECT_CALL(timeoutManager_, cancelTimeout(_))
107  .WillRepeatedly(Invoke([this] (AsyncTimeout* p) {
108  for (auto it = timeouts_.begin(); it != timeouts_.end(); it++) {
109  if (it->second == p) {
110  timeouts_.erase(it);
111  break;
112  }
113  }
114  }));
115  }
boost::container::flat_multimap< milliseconds, AsyncTimeout * > timeouts_
MockTimeoutClock timeoutClock_
struct event * getEvent()
Definition: AsyncTimeout.h:150
auto event_ref_flags(struct event *ev) -> decltype(std::ref(ev->ev_flags))
Definition: EventUtil.h:41
virtual std::chrono::milliseconds millisecondsSinceEpoch()=0
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
void setClock(milliseconds ms)
static void setTimeoutClock(MockTimeoutClock &clock)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
MockTimeoutManager timeoutManager_
virtual void cancelTimeout(AsyncTimeout *obj)=0
internal::ReturnAction< R > Return(R value)

Member Data Documentation

MockTimeoutClock TimeoutTest::timeoutClock_
protected

Definition at line 139 of file AsyncTimeoutSetTest.cpp.

MockTimeoutManager TimeoutTest::timeoutManager_
protected

Definition at line 138 of file AsyncTimeoutSetTest.cpp.

boost::container::flat_multimap<milliseconds, AsyncTimeout*> TimeoutTest::timeouts_
protected

Definition at line 140 of file AsyncTimeoutSetTest.cpp.


The documentation for this class was generated from the following file: