Commit fbee4dec authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

Try to allocate all the EventBase instances first before running the test

Summary: Try to allocate all the EventBase instances first before running the test

Reviewed By: kevin-vigor

Differential Revision: D25720889

fbshipit-source-id: 93c837e68771f1ef44e80865bec260813158c6b3
parent a1251f06
...@@ -1396,6 +1396,13 @@ TYPED_TEST_P(EventBaseTest, RunInThread) { ...@@ -1396,6 +1396,13 @@ TYPED_TEST_P(EventBaseTest, RunInThread) {
// whether any of the race conditions happened. // whether any of the race conditions happened.
TYPED_TEST_P(EventBaseTest, RunInEventBaseThreadAndWait) { TYPED_TEST_P(EventBaseTest, RunInEventBaseThreadAndWait) {
const size_t c = 256; const size_t c = 256;
std::vector<std::unique_ptr<EventBase>> evbs;
for (size_t i = 0; i < c; ++i) {
auto evbPtr = getEventBase<TypeParam>();
SKIP_IF(!evbPtr) << "Backend not available";
evbs.push_back(std::move(evbPtr));
}
std::vector<std::unique_ptr<std::atomic<size_t>>> atoms(c); std::vector<std::unique_ptr<std::atomic<size_t>>> atoms(c);
for (size_t i = 0; i < c; ++i) { for (size_t i = 0; i < c; ++i) {
auto& atom = atoms.at(i); auto& atom = atoms.at(i);
...@@ -1403,9 +1410,7 @@ TYPED_TEST_P(EventBaseTest, RunInEventBaseThreadAndWait) { ...@@ -1403,9 +1410,7 @@ TYPED_TEST_P(EventBaseTest, RunInEventBaseThreadAndWait) {
} }
std::vector<std::thread> threads; std::vector<std::thread> threads;
for (size_t i = 0; i < c; ++i) { for (size_t i = 0; i < c; ++i) {
auto evbPtr = getEventBase<TypeParam>(); threads.emplace_back([&atoms, i, evb = std::move(evbs[i])] {
SKIP_IF(!evbPtr) << "Backend not available";
threads.emplace_back([&atoms, i, evb = std::move(evbPtr)] {
folly::EventBase& eb = *evb; folly::EventBase& eb = *evb;
auto& atom = *atoms.at(i); auto& atom = *atoms.at(i);
auto ebth = std::thread([&] { eb.loopForever(); }); auto ebth = std::thread([&] { eb.loopForever(); });
......
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