From: Tudor Bosman Date: Wed, 13 Jun 2012 00:08:04 +0000 (-0700) Subject: Fix intermittent failure in concurrent_skip_list_test X-Git-Tag: v0.22.0~1267 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=827861961925702ee5e60b043f5d8f6686a3b64a;p=folly.git 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 --- 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();