Commit 5d276f09 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

update ThreadPoolExecutorTest to never try lowering niceness

Summary:
The code in PriorityThreadFactoryTest.ThreadPriority attempted to set the
thread niceness to 1.  This would fail if the process was already running at a
higher niceness value and was not being run as root.

This updates the test to get the current niceness first, and to use that plus 1
as the niceness value to change to.

Reviewed By: yfeldblum

Differential Revision: D6817548

fbshipit-source-id: 80e740f1fbe751865a418a58081bde4086b21679
parent fa2cd75d
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <memory> #include <memory>
#include <thread> #include <thread>
#include <folly/Exception.h>
#include <folly/executors/CPUThreadPoolExecutor.h> #include <folly/executors/CPUThreadPoolExecutor.h>
#include <folly/executors/FutureExecutor.h> #include <folly/executors/FutureExecutor.h>
#include <folly/executors/IOThreadPoolExecutor.h> #include <folly/executors/IOThreadPoolExecutor.h>
...@@ -427,12 +428,23 @@ TEST(ThreadPoolExecutorTest, BlockingQueue) { ...@@ -427,12 +428,23 @@ TEST(ThreadPoolExecutorTest, BlockingQueue) {
} }
TEST(PriorityThreadFactoryTest, ThreadPriority) { TEST(PriorityThreadFactoryTest, ThreadPriority) {
errno = 0;
auto currentPriority = getpriority(PRIO_PROCESS, 0);
if (errno != 0) {
throwSystemError("failed to get current priority");
}
// Non-root users can only increase the priority value. Make sure we are
// trying to go to a higher priority than we are currently running as, up to
// the maximum allowed of 20.
int desiredPriority = std::min(20, currentPriority + 1);
PriorityThreadFactory factory( PriorityThreadFactory factory(
std::make_shared<NamedThreadFactory>("stuff"), 1); std::make_shared<NamedThreadFactory>("stuff"), desiredPriority);
int actualPriority = -21; int actualPriority = -21;
factory.newThread([&]() { actualPriority = getpriority(PRIO_PROCESS, 0); }) factory.newThread([&]() { actualPriority = getpriority(PRIO_PROCESS, 0); })
.join(); .join();
EXPECT_EQ(1, actualPriority); EXPECT_EQ(desiredPriority, actualPriority);
} }
class TestData : public folly::RequestData { class TestData : public folly::RequestData {
......
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