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,23 +32,24 @@ void burnMs(uint64_t ms) { ...@@ -32,23 +32,24 @@ void burnMs(uint64_t ms) {
} }
} // namespace } // namespace
class SerialExecutorContextData : public folly::RequestData { void simpleTest(std::shared_ptr<folly::Executor> const& parent) {
public: class SerialExecutorContextData : public folly::RequestData {
static const std::string kCtxKey; public:
explicit SerialExecutorContextData(int id) : id_(id) {} static std::string kCtxKey() {
bool hasCallback() override { return typeid(SerialExecutorContextData).name();
return false; }
} explicit SerialExecutorContextData(int id) : id_(id) {}
int getId() const { bool hasCallback() override {
return id_; return false;
} }
int getId() const {
return id_;
}
private:
const int id_;
};
private:
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