From 827861961925702ee5e60b043f5d8f6686a3b64a Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Tue, 12 Jun 2012 17:08:04 -0700 Subject: [PATCH] Fix intermittent failure in concurrent_skip_list_test Summary: It creates too many threads, stop when we run out of resources. Test Plan: by hand, in a loop, in a memory-constrained environment Reviewed By: delong.j@fb.com FB internal diff: D493239 --- folly/test/ConcurrentSkipListTest.cpp | 28 +++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/folly/test/ConcurrentSkipListTest.cpp b/folly/test/ConcurrentSkipListTest.cpp index fb558f70..c7bb9977 100644 --- a/folly/test/ConcurrentSkipListTest.cpp +++ b/folly/test/ConcurrentSkipListTest.cpp @@ -19,11 +19,13 @@ #include #include #include +#include #include #include #include "folly/ConcurrentSkipList.h" #include "folly/Foreach.h" +#include "folly/String.h" #include "gtest/gtest.h" DEFINE_int32(num_threads, 12, "num concurrent threads to test"); @@ -210,9 +212,16 @@ void testConcurrentAdd(int numThreads) { vector threads; vector verifiers(numThreads); - for (int i = 0; i < numThreads; ++i) { - threads.push_back(std::thread( - &randomAdding, 100, skipList, &verifiers[i], kMaxValue)); + try { + for (int i = 0; i < numThreads; ++i) { + threads.push_back(std::thread( + &randomAdding, 100, skipList, &verifiers[i], kMaxValue)); + } + } catch (const std::system_error& e) { + LOG(WARNING) + << "Caught " << exceptionStr(e) + << ": could only create " << threads.size() << " threads out of " + << numThreads; } for (int i = 0; i < threads.size(); ++i) { threads[i].join(); @@ -240,9 +249,16 @@ void testConcurrentRemoval(int numThreads, int maxValue) { vector threads; vector verifiers(numThreads); - for (int i = 0; i < numThreads; ++i) { - threads.push_back(std::thread( - &randomRemoval, 100, skipList, &verifiers[i], maxValue)); + try { + for (int i = 0; i < numThreads; ++i) { + threads.push_back(std::thread( + &randomRemoval, 100, skipList, &verifiers[i], maxValue)); + } + } catch (const std::system_error& e) { + LOG(WARNING) + << "Caught " << exceptionStr(e) + << ": could only create " << threads.size() << " threads out of " + << numThreads; } FOR_EACH(t, threads) { (*t).join(); -- 2.34.1