From: Adam C. Emerson Date: Thu, 2 May 2019 18:18:55 +0000 (-0400) Subject: test/simple_spin: Explicitly wait for futures from async X-Git-Tag: v15.1.0~2390^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=2ddb170320fe286daba3f33dc10e9164d7793831;p=ceph-ci.git test/simple_spin: Explicitly wait for futures from async Rather than count on implicitly blocking destruct. Signed-off-by: Adam C. Emerson --- diff --git a/src/test/simple_spin.cc b/src/test/simple_spin.cc index 81194d84991..4afa670743e 100644 --- a/src/test/simple_spin.cc +++ b/src/test/simple_spin.cc @@ -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 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 g(sl); counter++; } }); + f.wait(); + g.wait(); ASSERT_EQ(2*n, counter); }