Commit 339239f3 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Move SerialExecutor test helper types

Summary: [Folly] Move `SerialExecutor` test-specific helper types into the tests which need them.

Reviewed By: andriigrynenko

Differential Revision: D15587721

fbshipit-source-id: 603e5381b2e00b4317f7e9836c6102238158c5d0
parent 48926dfb
...@@ -32,9 +32,12 @@ void burnMs(uint64_t ms) { ...@@ -32,9 +32,12 @@ void burnMs(uint64_t ms) {
} }
} // namespace } // namespace
class SerialExecutorContextData : public folly::RequestData { void simpleTest(std::shared_ptr<folly::Executor> const& parent) {
class SerialExecutorContextData : public folly::RequestData {
public: public:
static const std::string kCtxKey; static std::string kCtxKey() {
return typeid(SerialExecutorContextData).name();
}
explicit SerialExecutorContextData(int id) : id_(id) {} explicit SerialExecutorContextData(int id) : id_(id) {}
bool hasCallback() override { bool hasCallback() override {
return false; return false;
...@@ -45,10 +48,8 @@ class SerialExecutorContextData : public folly::RequestData { ...@@ -45,10 +48,8 @@ class SerialExecutorContextData : public folly::RequestData {
private: private:
const int id_; const int id_;
}; };
const std::string SerialExecutorContextData::kCtxKey =
"SerialExecutorContextDataKey";
void SimpleTest(std::shared_ptr<folly::Executor> const& parent) {
auto executor = auto executor =
SerialExecutor::create(folly::getKeepAliveToken(parent.get())); SerialExecutor::create(folly::getKeepAliveToken(parent.get()));
...@@ -58,7 +59,7 @@ void SimpleTest(std::shared_ptr<folly::Executor> const& parent) { ...@@ -58,7 +59,7 @@ void SimpleTest(std::shared_ptr<folly::Executor> const& parent) {
for (int i = 0; i < 20; ++i) { for (int i = 0; i < 20; ++i) {
auto ctx = std::make_shared<folly::RequestContext>(); auto ctx = std::make_shared<folly::RequestContext>();
ctx->setContextData( ctx->setContextData(
SerialExecutorContextData::kCtxKey, SerialExecutorContextData::kCtxKey(),
std::make_unique<SerialExecutorContextData>(i)); std::make_unique<SerialExecutorContextData>(i));
folly::RequestContextScopeGuard ctxGuard(ctx); folly::RequestContextScopeGuard ctxGuard(ctx);
executor->add([i, &values] { executor->add([i, &values] {
...@@ -66,7 +67,7 @@ void SimpleTest(std::shared_ptr<folly::Executor> const& parent) { ...@@ -66,7 +67,7 @@ void SimpleTest(std::shared_ptr<folly::Executor> const& parent) {
i, i,
dynamic_cast<SerialExecutorContextData*>( dynamic_cast<SerialExecutorContextData*>(
folly::RequestContext::get()->getContextData( folly::RequestContext::get()->getContextData(
SerialExecutorContextData::kCtxKey)) SerialExecutorContextData::kCtxKey()))
->getId()); ->getId());
// make this extra vulnerable to concurrent execution // make this extra vulnerable to concurrent execution
values.push_back(0); values.push_back(0);
...@@ -85,10 +86,10 @@ void SimpleTest(std::shared_ptr<folly::Executor> const& parent) { ...@@ -85,10 +86,10 @@ void SimpleTest(std::shared_ptr<folly::Executor> const& parent) {
} }
TEST(SerialExecutor, Simple) { TEST(SerialExecutor, Simple) {
SimpleTest(std::make_shared<folly::CPUThreadPoolExecutor>(4)); simpleTest(std::make_shared<folly::CPUThreadPoolExecutor>(4));
} }
TEST(SerialExecutor, SimpleInline) { TEST(SerialExecutor, SimpleInline) {
SimpleTest(std::make_shared<folly::InlineExecutor>()); simpleTest(std::make_shared<folly::InlineExecutor>());
} }
// The Afterlife test only works with an asynchronous executor (not the // The Afterlife test only works with an asynchronous executor (not the
......
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