[libcxx-commits] [libcxx] 3f66bb2 - [libcxx testing] Remove ALLOW_RETRIES from last futures test

David Zarzycki via libcxx-commits libcxx-commits at lists.llvm.org
Sat May 16 04:12:03 PDT 2020


Author: David Zarzycki
Date: 2020-05-16T07:11:49-04:00
New Revision: 3f66bb20174eb6d1f7689eeb5fbd19128d504063

URL: https://github.com/llvm/llvm-project/commit/3f66bb20174eb6d1f7689eeb5fbd19128d504063
DIFF: https://github.com/llvm/llvm-project/commit/3f66bb20174eb6d1f7689eeb5fbd19128d504063.diff

LOG: [libcxx testing] Remove ALLOW_RETRIES from last futures test

Like other uses of ALLOW_RETRIES, this test tried to verify that an API
returned "quickly" but quick is not safe to define given slow and/or
busy machines.

Instead, we now verify that these "wait" APIs actually wait, which the
old test did not.

Added: 
    

Modified: 
    libcxx/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp b/libcxx/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
index d055f6468467..bdd6b9e2b4d3 100644
--- a/libcxx/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
@@ -8,7 +8,6 @@
 //
 // UNSUPPORTED: libcpp-has-no-threads
 // UNSUPPORTED: c++98, c++03
-// ALLOW_RETRIES: 2
 
 // <future>
 
@@ -25,49 +24,63 @@
 
 typedef std::chrono::milliseconds ms;
 
+static const ms sleepTime(500);
+static const ms waitTime(5000);
+
 void func1(std::promise<int> p)
 {
-    std::this_thread::sleep_for(ms(500));
-    p.set_value(3);
+  std::this_thread::sleep_for(sleepTime);
+  p.set_value(3);
 }
 
 int j = 0;
 
 void func3(std::promise<int&> p)
 {
-    std::this_thread::sleep_for(ms(500));
-    j = 5;
-    p.set_value(j);
+  std::this_thread::sleep_for(sleepTime);
+  j = 5;
+  p.set_value(j);
 }
 
 void func5(std::promise<void> p)
 {
-    std::this_thread::sleep_for(ms(500));
-    p.set_value();
+  std::this_thread::sleep_for(sleepTime);
+  p.set_value();
 }
 
 template <typename T, typename F>
-void test(F func) {
-    typedef std::chrono::high_resolution_clock Clock;
-    std::promise<T> p;
-    std::future<T> f = p.get_future();
-    std::thread(func, std::move(p)).detach();
+void test(F func, bool waitFirst) {
+  typedef std::chrono::high_resolution_clock Clock;
+  std::promise<T> p;
+  std::future<T> f = p.get_future();
+  Clock::time_point t1, t0 = Clock::now();
+  std::thread(func, std::move(p)).detach();
+  assert(f.valid());
+  assert(f.wait_for(ms(1)) == std::future_status::timeout);
+  assert(f.valid());
+  if (waitFirst) {
+    f.wait();
     assert(f.valid());
-    assert(f.wait_for(ms(300)) == std::future_status::timeout);
+    t1 = Clock::now();
+    assert(f.wait_for(ms(waitTime)) == std::future_status::ready);
     assert(f.valid());
-    assert(f.wait_for(ms(300)) == std::future_status::ready);
+  } else {
+    assert(f.wait_for(ms(waitTime)) == std::future_status::ready);
     assert(f.valid());
-    Clock::time_point t0 = Clock::now();
+    t1 = Clock::now();
     f.wait();
-    Clock::time_point t1 = Clock::now();
     assert(f.valid());
-    assert(t1-t0 < ms(50));
+  }
+  assert(t1 - t0 >= sleepTime);
 }
 
 int main(int, char**)
 {
-    test<int>(func1);
-    test<int&>(func3);
-    test<void>(func5);
-    return 0;
+  test<int>(func1, true);
+  test<int&>(func3, true);
+  test<void>(func5, true);
+  test<int>(func1, false);
+  test<int&>(func3, false);
+  test<void>(func5, false);
+  return 0;
 }


        


More information about the libcxx-commits mailing list