diff options
author | James E. King III <jking@apache.org> | 2019-02-02 11:22:26 -0500 |
---|---|---|
committer | James E. King III <jking@apache.org> | 2019-02-02 22:10:41 -0500 |
commit | 71afec0ea3fc700d5f0d1c46512723963bf1e2f7 (patch) | |
tree | 608b3060611783aecb999968468b2754054c12ba | |
parent | 4c57be0b609924f6516dd293985fc6d76f738c16 (diff) | |
download | thrift-71afec0ea3fc700d5f0d1c46512723963bf1e2f7.tar.gz |
THRIFT-4739: fix concurrency_test (test-only fix)
-rwxr-xr-x | appveyor.yml | 8 | ||||
-rw-r--r-- | lib/cpp/test/concurrency/TimerManagerTests.h | 21 |
2 files changed, 20 insertions, 9 deletions
diff --git a/appveyor.yml b/appveyor.yml index 2dee45fa8..39aba4f95 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -45,7 +45,7 @@ environment: PYTHON_VERSION: 3.6 QT_VERSION: 5.10 ZLIB_VERSION: 1.2.11 - DISABLED_TESTS: (concurrency_test|StressTestNonBlocking) + DISABLED_TESTS: (StressTestNonBlocking) - PROFILE: MSVC2015 PLATFORM: x86 @@ -56,18 +56,18 @@ environment: PYTHON_VERSION: 3.5 QT_VERSION: 5.8 ZLIB_VERSION: 1.2.8 - DISABLED_TESTS: (concurrency_test|StressTestNonBlocking) + DISABLED_TESTS: (StressTestNonBlocking) APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - PROFILE: MINGW PLATFORM: x64 CONFIGURATION: RelWithDebInfo - DISABLED_TESTS: (concurrency_test|StressTestNonBlocking) + DISABLED_TESTS: (StressTestNonBlocking) - PROFILE: CYGWIN PLATFORM: x64 CONFIGURATION: RelWithDebInfo - DISABLED_TESTS: (concurrency_test|ZlibTest|OpenSSLManualInitTest|TNonblockingServerTest|StressTestNonBlocking) + DISABLED_TESTS: (ZlibTest|OpenSSLManualInitTest|TNonblockingServerTest|StressTestNonBlocking) install: - cd %APPVEYOR_BUILD_FOLDER% diff --git a/lib/cpp/test/concurrency/TimerManagerTests.h b/lib/cpp/test/concurrency/TimerManagerTests.h index 313572aff..2d1a2620a 100644 --- a/lib/cpp/test/concurrency/TimerManagerTests.h +++ b/lib/cpp/test/concurrency/TimerManagerTests.h @@ -22,6 +22,8 @@ #include <thrift/concurrency/Monitor.h> #include <assert.h> +#include <chrono> +#include <thread> #include <iostream> namespace apache { @@ -223,7 +225,7 @@ public: } /** - * This test creates one tasks, and tries to remove it after it has expired. + * This test creates one task, and tries to remove it after it has expired. */ bool test04(uint64_t timeout = 1000LL) { TimerManager timerManager; @@ -237,15 +239,24 @@ public: shared_ptr<TimerManagerTests::Task> task = shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, timeout / 10)); TimerManager::Timer timer = timerManager.add(task, task->_timeout); + task.reset(); // Wait until the task has completed _monitor.wait(timeout); // Verify behavior when removing the expired task - try { - timerManager.remove(timer); - assert(nullptr == "ERROR: This remove should send a NoSuchTaskException exception."); - } catch (NoSuchTaskException&) { + // notify is called inside the task so the task may still + // be running when we get here, so we need to loop... + for (;;) { + try { + timerManager.remove(timer); + assert(nullptr == "ERROR: This remove should throw NoSuchTaskException, or UncancellableTaskException."); + } catch (const NoSuchTaskException&) { + break; + } catch (const UncancellableTaskException&) { + // the thread was still exiting; try again... + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } } return true; |