snapuserd_test: don't discard result of std::async
std::async returns a std::future whose destructor blocks until the
async function has completed, which defeats the purpose of using
std::async. The future needs to be kept alive to allow the function to
run concurrently.
Starting in C++20, std::async marked [[nodiscard]] to help catch this
misuse. Upgrading libc++ adds the [[nodiscard]] attribute to
std::async, so fixing this bug is necessary to keep the code compiling
after libc++ is updated.
Bug: 175635923
Test: treehugger
Test: m && m snapuserd_test
Change-Id: Id2e820248c2b6111aa843fb709e08a2c19677066
diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_test.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_test.cpp
index 01fe06f..620ecbd 100644
--- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_test.cpp
+++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_test.cpp
@@ -714,10 +714,12 @@
}
ASSERT_NO_FATAL_FAILURE(SetupDefault());
// Issue I/O before merge begins
- std::async(std::launch::async, &SnapuserdTest::ReadSnapshotDeviceAndValidate, this);
+ auto read_future =
+ std::async(std::launch::async, &SnapuserdTest::ReadSnapshotDeviceAndValidate, this);
// Start the merge
ASSERT_TRUE(Merge());
ValidateMerge();
+ read_future.wait();
}
TEST_F(SnapuserdTest, Snapshot_MERGE_IO_TEST_1) {
@@ -728,9 +730,11 @@
// Start the merge
ASSERT_TRUE(StartMerge());
// Issue I/O in parallel when merge is in-progress
- std::async(std::launch::async, &SnapuserdTest::ReadSnapshotDeviceAndValidate, this);
+ auto read_future =
+ std::async(std::launch::async, &SnapuserdTest::ReadSnapshotDeviceAndValidate, this);
CheckMergeCompletion();
ValidateMerge();
+ read_future.wait();
}
TEST_F(SnapuserdTest, Snapshot_Merge_Resume) {