fix FutexTest v2017.06.12.00
authorTianjiao Yin <ytj@fb.com>
Sat, 10 Jun 2017 05:03:48 +0000 (22:03 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sat, 10 Jun 2017 05:07:05 +0000 (22:07 -0700)
Summary: 2_ms seems too short. I am not sure whether it's feasible to check whether thread is waiting for an address. We could wait for longer to reduce false alarm.

Reviewed By: nbronson

Differential Revision: D5220819

fbshipit-source-id: 42f31206e9cb7f9addaa049d0e7cd995f6735f6c

folly/test/FutexTest.cpp

index 24cd175625758281d893dae811202c4872c0ab22..b64238b6274db2e8702509574f76805899b967dd 100644 (file)
@@ -184,17 +184,19 @@ void run_steady_clock_test() {
 
 template <template <typename> class Atom>
 void run_wake_blocked_test() {
-  Futex<Atom> f(0);
-
-  auto thr = DSched::thread([&] { EXPECT_TRUE(f.futexWait(0)); });
-
-  // A sleep here guarantees to a large extent that 'thr' will execute
-  // futexWait before we wake it up, thus testing late futexWake.
-  std::this_thread::sleep_for(std::chrono::milliseconds(2));
-
-  f.store(1);
-  f.futexWake(1);
-  DSched::join(thr);
+  for (auto delay = std::chrono::milliseconds(1);; delay *= 2) {
+    bool success = false;
+    Futex<Atom> f(0);
+    auto thr = DSched::thread([&] { success = f.futexWait(0); });
+    /* sleep override */ std::this_thread::sleep_for(delay);
+    f.store(1);
+    f.futexWake(1);
+    DSched::join(thr);
+    LOG(INFO) << "delay=" << delay.count() << "_ms, success=" << success;
+    if (success) {
+      break;
+    }
+  }
 }
 
 TEST(Futex, clock_source) {