]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/simple_spin: Explicitly wait for futures from async
authorAdam C. Emerson <aemerson@redhat.com>
Thu, 2 May 2019 18:18:55 +0000 (14:18 -0400)
committerKefu Chai <kchai@redhat.com>
Fri, 21 Jun 2019 03:41:16 +0000 (11:41 +0800)
Rather than count on implicitly blocking destruct.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/test/simple_spin.cc

index 81194d84991531773e4d73ceecaf5592759181bb..4afa670743e8a39183399b2fca7b517e63d62e6d 100644 (file)
@@ -49,13 +49,14 @@ TEST(SimpleSpin, Test1)
   // Should also work with pass-by-reference:
   // (Note that we don't care about cross-threading here as-such.)
   counter = 0;
-  async(std::launch::async, []() {
+  auto f = async(std::launch::async, []() {
         for(int i = 0; n != i; ++i) {
             spin_lock(lock);
             counter++;
             spin_unlock(lock);
         }
        });
+  f.wait();
   ASSERT_EQ(n, counter);
 }
 
@@ -111,22 +112,24 @@ TEST(SimpleSpin, spinlock_guard)
   const auto n = 2000000U;
 
   ceph::spinlock sl;
+
   counter = 0;
-  async(std::launch::async, [&sl]() {
+  auto f = async(std::launch::async, [&sl]() {
         for(int i = 0; n != i; ++i) {
             std::lock_guard<ceph::spinlock> g(sl);
             counter++;
         }
        });
 
-  async(std::launch::async, [&sl]() {
+  auto g = async(std::launch::async, [&sl]() {
         for(int i = 0; n != i; ++i) {
             std::lock_guard<ceph::spinlock> g(sl);
             counter++;
         }
        });
 
+  f.wait();
+  g.wait();
   ASSERT_EQ(2*n, counter);
 }