Commit a88662de authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

tweaks to the AtFork tests

Summary: Use `waitpid` for more exact waits. Use `_exit` in the child to skip unnecessary teardown work. Remove unused local variable.

Differential Revision: D34191704

fbshipit-source-id: 38f4275eab38a4ba5a41fbf617aa3fb389ea00c0
parent 002c6020
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <folly/portability/GMock.h> #include <folly/portability/GMock.h>
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
TEST(ThreadLocal, AtFork) { class AtForkTest : public testing::Test {};
TEST_F(AtForkTest, prepare) {
int foo; int foo;
bool forked = false; bool forked = false;
folly::detail::AtFork::registerHandler( folly::detail::AtFork::registerHandler(
...@@ -41,11 +43,11 @@ TEST(ThreadLocal, AtFork) { ...@@ -41,11 +43,11 @@ TEST(ThreadLocal, AtFork) {
: fork(); : fork();
if (pid) { if (pid) {
int status; int status;
auto pid2 = wait(&status); auto pid2 = waitpid(pid, &status, 0);
EXPECT_EQ(status, 0); EXPECT_EQ(status, 0);
EXPECT_EQ(pid, pid2); EXPECT_EQ(pid, pid2);
} else { } else {
exit(0); _exit(0);
} }
EXPECT_TRUE(forked); EXPECT_TRUE(forked);
forked = false; forked = false;
...@@ -53,17 +55,16 @@ TEST(ThreadLocal, AtFork) { ...@@ -53,17 +55,16 @@ TEST(ThreadLocal, AtFork) {
pid = fork(); pid = fork();
if (pid) { if (pid) {
int status; int status;
auto pid2 = wait(&status); auto pid2 = waitpid(pid, &status, 0);
EXPECT_EQ(status, 0); EXPECT_EQ(status, 0);
EXPECT_EQ(pid, pid2); EXPECT_EQ(pid, pid2);
} else { } else {
exit(0); _exit(0);
} }
EXPECT_FALSE(forked); EXPECT_FALSE(forked);
} }
TEST(ThreadLocal, AtForkOrdering) { TEST_F(AtForkTest, ordering) {
std::atomic<bool> done{false};
std::atomic<bool> started{false}; std::atomic<bool> started{false};
std::mutex a; std::mutex a;
std::mutex b; std::mutex b;
...@@ -93,7 +94,7 @@ TEST(ThreadLocal, AtForkOrdering) { ...@@ -93,7 +94,7 @@ TEST(ThreadLocal, AtForkOrdering) {
: fork(); : fork();
if (pid) { if (pid) {
int status; int status;
auto pid2 = wait(&status); auto pid2 = waitpid(pid, &status, 0);
EXPECT_TRUE(WIFEXITED(status)); EXPECT_TRUE(WIFEXITED(status));
EXPECT_THAT( EXPECT_THAT(
WEXITSTATUS(status), WEXITSTATUS(status),
...@@ -102,8 +103,7 @@ TEST(ThreadLocal, AtForkOrdering) { ...@@ -102,8 +103,7 @@ TEST(ThreadLocal, AtForkOrdering) {
: testing::AnyOfArray({0})); : testing::AnyOfArray({0}));
EXPECT_EQ(pid, pid2); EXPECT_EQ(pid, pid2);
} else { } else {
exit(0); _exit(0);
} }
done = true;
thr.join(); thr.join();
} }
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