Commit 7bf08cd2 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

put local classes in EventBaseTest.cpp inside an unnamed namespace

Summary: Put file-local classes and helper functions into an unnamed namespace.

Reviewed By: yfeldblum

Differential Revision: D15528323

fbshipit-source-id: 9e90aafe4382d9ba237823fea1e68dbea7fa1f2f
parent 13ae097b
...@@ -53,6 +53,8 @@ using namespace folly; ...@@ -53,6 +53,8 @@ using namespace folly;
// Tests for read and write events // Tests for read and write events
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
namespace {
enum { BUF_SIZE = 4096 }; enum { BUF_SIZE = 4096 };
ssize_t writeToFD(int fd, size_t length) { ssize_t writeToFD(int fd, size_t length) {
...@@ -182,6 +184,8 @@ class TestHandler : public EventHandler { ...@@ -182,6 +184,8 @@ class TestHandler : public EventHandler {
int fd_; int fd_;
}; };
} // namespace
/** /**
* Test a READ event * Test a READ event
*/ */
...@@ -646,6 +650,7 @@ TEST(EventBaseTest, ReadWritePersist) { ...@@ -646,6 +650,7 @@ TEST(EventBaseTest, ReadWritePersist) {
ASSERT_EQ(bytesRemaining, events[5].length); ASSERT_EQ(bytesRemaining, events[5].length);
} }
namespace {
class PartialReadHandler : public TestHandler { class PartialReadHandler : public TestHandler {
public: public:
PartialReadHandler(EventBase* eventBase, int fd, size_t readLength) PartialReadHandler(EventBase* eventBase, int fd, size_t readLength)
...@@ -661,6 +666,7 @@ class PartialReadHandler : public TestHandler { ...@@ -661,6 +666,7 @@ class PartialReadHandler : public TestHandler {
int fd_; int fd_;
size_t readLength_; size_t readLength_;
}; };
} // namespace
/** /**
* Test reading only part of the available data when a read event is fired. * Test reading only part of the available data when a read event is fired.
...@@ -710,6 +716,7 @@ TEST(EventBaseTest, ReadPartial) { ...@@ -710,6 +716,7 @@ TEST(EventBaseTest, ReadPartial) {
ASSERT_EQ(handler.log[3].bytesWritten, 0); ASSERT_EQ(handler.log[3].bytesWritten, 0);
} }
namespace {
class PartialWriteHandler : public TestHandler { class PartialWriteHandler : public TestHandler {
public: public:
PartialWriteHandler(EventBase* eventBase, int fd, size_t writeLength) PartialWriteHandler(EventBase* eventBase, int fd, size_t writeLength)
...@@ -725,6 +732,7 @@ class PartialWriteHandler : public TestHandler { ...@@ -725,6 +732,7 @@ class PartialWriteHandler : public TestHandler {
int fd_; int fd_;
size_t writeLength_; size_t writeLength_;
}; };
} // namespace
/** /**
* Test writing without completely filling up the write buffer when the fd * Test writing without completely filling up the write buffer when the fd
...@@ -895,6 +903,7 @@ TEST(EventBaseTest, RunAfterDelayDestruction) { ...@@ -895,6 +903,7 @@ TEST(EventBaseTest, RunAfterDelayDestruction) {
// memory is leaked. // memory is leaked.
} }
namespace {
class TestTimeout : public AsyncTimeout { class TestTimeout : public AsyncTimeout {
public: public:
explicit TestTimeout(EventBase* eventBase) explicit TestTimeout(EventBase* eventBase)
...@@ -906,6 +915,7 @@ class TestTimeout : public AsyncTimeout { ...@@ -906,6 +915,7 @@ class TestTimeout : public AsyncTimeout {
TimePoint timestamp; TimePoint timestamp;
}; };
} // namespace
TEST(EventBaseTest, BasicTimeouts) { TEST(EventBaseTest, BasicTimeouts) {
EventBase eb; EventBase eb;
...@@ -927,6 +937,7 @@ TEST(EventBaseTest, BasicTimeouts) { ...@@ -927,6 +937,7 @@ TEST(EventBaseTest, BasicTimeouts) {
T_CHECK_TIMEOUT(start, end, milliseconds(40)); T_CHECK_TIMEOUT(start, end, milliseconds(40));
} }
namespace {
class ReschedulingTimeout : public AsyncTimeout { class ReschedulingTimeout : public AsyncTimeout {
public: public:
ReschedulingTimeout(EventBase* evb, const vector<uint32_t>& timeouts) ReschedulingTimeout(EventBase* evb, const vector<uint32_t>& timeouts)
...@@ -955,6 +966,7 @@ class ReschedulingTimeout : public AsyncTimeout { ...@@ -955,6 +966,7 @@ class ReschedulingTimeout : public AsyncTimeout {
vector<uint32_t> timeouts_; vector<uint32_t> timeouts_;
vector<uint32_t>::const_iterator iterator_; vector<uint32_t>::const_iterator iterator_;
}; };
} // namespace
/** /**
* Test rescheduling the same timeout multiple times * Test rescheduling the same timeout multiple times
...@@ -1138,6 +1150,8 @@ TEST(EventBaseTest, ScheduledFnAt) { ...@@ -1138,6 +1150,8 @@ TEST(EventBaseTest, ScheduledFnAt) {
// Test for runInThreadTestFunc() // Test for runInThreadTestFunc()
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
namespace {
struct RunInThreadData { struct RunInThreadData {
RunInThreadData(int numThreads, int opsPerThread_) RunInThreadData(int numThreads, int opsPerThread_)
: opsPerThread(opsPerThread_), opsToGo(numThreads * opsPerThread) {} : opsPerThread(opsPerThread_), opsToGo(numThreads * opsPerThread) {}
...@@ -1169,6 +1183,8 @@ void runInThreadTestFunc(RunInThreadArg* arg) { ...@@ -1169,6 +1183,8 @@ void runInThreadTestFunc(RunInThreadArg* arg) {
} }
} }
} // namespace
TEST(EventBaseTest, RunInThread) { TEST(EventBaseTest, RunInThread) {
constexpr uint32_t numThreads = 50; constexpr uint32_t numThreads = 50;
constexpr uint32_t opsPerThread = 100; constexpr uint32_t opsPerThread = 100;
...@@ -1309,6 +1325,7 @@ TEST(EventBaseTest, RunImmediatelyOrRunInEventBaseThreadNotLooping) { ...@@ -1309,6 +1325,7 @@ TEST(EventBaseTest, RunImmediatelyOrRunInEventBaseThreadNotLooping) {
// Tests for runInLoop() // Tests for runInLoop()
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
namespace {
class CountedLoopCallback : public EventBase::LoopCallback { class CountedLoopCallback : public EventBase::LoopCallback {
public: public:
CountedLoopCallback( CountedLoopCallback(
...@@ -1335,6 +1352,7 @@ class CountedLoopCallback : public EventBase::LoopCallback { ...@@ -1335,6 +1352,7 @@ class CountedLoopCallback : public EventBase::LoopCallback {
unsigned int count_; unsigned int count_;
std::function<void()> action_; std::function<void()> action_;
}; };
} // namespace
// Test that EventBase::loop() doesn't exit while there are // Test that EventBase::loop() doesn't exit while there are
// still LoopCallbacks remaining to be invoked. // still LoopCallbacks remaining to be invoked.
...@@ -1481,6 +1499,7 @@ TEST(EventBaseTest, CancelRunInLoop) { ...@@ -1481,6 +1499,7 @@ TEST(EventBaseTest, CancelRunInLoop) {
ASSERT_EQ(c2.getCount(), 11); ASSERT_EQ(c2.getCount(), 11);
} }
namespace {
class TerminateTestCallback : public EventBase::LoopCallback, class TerminateTestCallback : public EventBase::LoopCallback,
public EventHandler { public EventHandler {
public: public:
...@@ -1537,6 +1556,7 @@ class TerminateTestCallback : public EventBase::LoopCallback, ...@@ -1537,6 +1556,7 @@ class TerminateTestCallback : public EventBase::LoopCallback,
uint32_t eventInvocations_; uint32_t eventInvocations_;
uint32_t maxEventInvocations_; uint32_t maxEventInvocations_;
}; };
} // namespace
/** /**
* Test that EventBase::loop() correctly detects when there are no more events * Test that EventBase::loop() correctly detects when there are no more events
...@@ -1629,6 +1649,7 @@ TEST(EventBaseTest, AlwaysEnqueueCallbackOrderTest) { ...@@ -1629,6 +1649,7 @@ TEST(EventBaseTest, AlwaysEnqueueCallbackOrderTest) {
// Tests for latency calculations // Tests for latency calculations
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
namespace {
class IdleTimeTimeoutSeries : public AsyncTimeout { class IdleTimeTimeoutSeries : public AsyncTimeout {
public: public:
explicit IdleTimeTimeoutSeries( explicit IdleTimeTimeoutSeries(
...@@ -1663,6 +1684,7 @@ class IdleTimeTimeoutSeries : public AsyncTimeout { ...@@ -1663,6 +1684,7 @@ class IdleTimeTimeoutSeries : public AsyncTimeout {
int timeouts_; int timeouts_;
std::deque<std::size_t>& timeout_; std::deque<std::size_t>& timeout_;
}; };
} // namespace
/** /**
* Verify that idle time is correctly accounted for when decaying our loop * Verify that idle time is correctly accounted for when decaying our loop
...@@ -1801,6 +1823,7 @@ TEST(EventBaseTest, RunBeforeLoopWait) { ...@@ -1801,6 +1823,7 @@ TEST(EventBaseTest, RunBeforeLoopWait) {
ASSERT_EQ(cb.getCount(), 0); ASSERT_EQ(cb.getCount(), 0);
} }
namespace {
class PipeHandler : public EventHandler { class PipeHandler : public EventHandler {
public: public:
PipeHandler(EventBase* eventBase, int fd) PipeHandler(EventBase* eventBase, int fd)
...@@ -1810,6 +1833,7 @@ class PipeHandler : public EventHandler { ...@@ -1810,6 +1833,7 @@ class PipeHandler : public EventHandler {
abort(); abort();
} }
}; };
} // namespace
TEST(EventBaseTest, StopBeforeLoop) { TEST(EventBaseTest, StopBeforeLoop) {
EventBase evb; EventBase evb;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment