Skip to content

Commit

Permalink
TESTS: Add a global fixture for folly::IOThreadPoolExecutor
Browse files Browse the repository at this point in the history
Currently with centos7 we're having faults with thread_local when folly
executors are created and destroyed with
facebook/folly#1252 & possibly
facebook/folly#1135, these issues don't seem to be
reproducible in newer gcc's shipped with centos8+. Since in the EOS Code we
create the executors and keep them around until shutdown, use a similar pattern
instead of creating and destroying multiple folly threadpools

Signed-off-by: Abhishek Lekshmanan <abhishek.lekshmanan@cern.ch>
  • Loading branch information
theanalyst committed Oct 3, 2022
1 parent 42d2f3c commit 160c12d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
28 changes: 28 additions & 0 deletions unit_tests/common/async/ExecutorMgrTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// Created by Abhishek Lekshmanan on 29/09/2022.
//
#include "common/async/ExecutorMgr.hh"
#include "unit_tests/common/async/FollyExecutorFixture.hh"
#include <gtest/gtest.h>
#include <folly/executors/CPUThreadPoolExecutor.h>

Expand Down Expand Up @@ -62,3 +63,30 @@ TEST(ExecutorMgr, ThreadPool)
// Check if we have exactly 3 different thread ids
ASSERT_EQ(3, threadIds.size());
}

TEST_F(FollyExecutor_F, IOThreadPoolExecutorTests)
{
eos::common::ExecutorMgr mgr(folly_executor);
ASSERT_TRUE(mgr.IsFollyExecutor());
std::vector<eos::common::OpaqueFuture<std::thread::id>> futures;

for (int i = 0; i < 10; i++) {
auto future = mgr.PushTask(
[]
{
std::this_thread::sleep_for(std::chrono::milliseconds(20));
return std::this_thread::get_id();
}
);
futures.emplace_back(std::move(future));
}

std::set<std::thread::id> threadIds;

for (auto && future : futures) {
threadIds.insert(future.getValue());
}

// Check if we have exactly 4 different thread ids
ASSERT_EQ(kNumThreads, threadIds.size());
}
42 changes: 42 additions & 0 deletions unit_tests/common/async/FollyExecutorFixture.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// ----------------------------------------------------------------------
// File: FollyExecutorFixture.hh
// Author: Abhishek Lekshmanan - CERN
// ----------------------------------------------------------------------

/************************************************************************
* EOS - the CERN Disk Storage System *
* Copyright (C) 2022 CERN/Switzerland *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/


#pragma once

#include <folly/executors/IOThreadPoolExecutor.h>
#include <gtest/gtest.h>

class FollyExecutor_F : public ::testing::Test {
protected:
void SetUp() override {
folly_executor = std::make_shared<folly::IOThreadPoolExecutor>(kNumThreads);
}

void TearDown() override {
folly_executor.reset();
}

std::shared_ptr<folly::IOThreadPoolExecutor> folly_executor;
constexpr static size_t kNumThreads = 4;
};
6 changes: 3 additions & 3 deletions unit_tests/common/async/OpaqueFutureTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


#include "common/async/OpaqueFuture.hh"
#include "unit_tests/common/async/FollyExecutorFixture.hh"
#include <gtest/gtest.h>
#include <folly/executors/CPUThreadPoolExecutor.h>
using eos::common::OpaqueFuture;
Expand Down Expand Up @@ -125,10 +126,9 @@ TEST(OpaqueFuture, StdFutureWait)
EXPECT_EQ(f.getValue(), 102334155);
}

TEST(OpaqueFuture, follyFutureWait)
TEST_F(FollyExecutor_F, follyOpaqueFutureWait)
{
auto executor = folly::CPUThreadPoolExecutor(1);
auto f = folly::makeFuture().via(&executor).then([](auto&&) {
auto f = folly::makeFuture().via(folly_executor.get()).then([](auto&&) {
return fib(40);
});

Expand Down

0 comments on commit 160c12d

Please sign in to comment.