dm_test.cpp: DeleteDeviceWithTimeout asserts that unique path is deleted
Before this patch, DeleteDeviceWithTimeout was checking that the dev
node (i.e. /dev/block/dm-XX) is deleted after the call to DeleteDevice
API. Since ueventd first deletes the symlinks that correspond to a
device and only then deletes this device node, this assertion introduced
a race condition (DeleteDevice API waits for the symlink to be deleted).
This patch changes the DeleteDeviceWithTimeout test to check that unique
path of the device has been deleted.
Bug: 318425605
Test: presubmit
Change-Id: I3fd9de507c75bcf6ac1350fa0b8adfdb5a2e89e8
diff --git a/fs_mgr/libdm/dm_test.cpp b/fs_mgr/libdm/dm_test.cpp
index c522eaf..a0129c2 100644
--- a/fs_mgr/libdm/dm_test.cpp
+++ b/fs_mgr/libdm/dm_test.cpp
@@ -580,9 +580,18 @@
ASSERT_TRUE(dm.GetDmDevicePathByName("libdm-test-dm-linear", &path));
ASSERT_EQ(0, access(path.c_str(), F_OK));
+ std::string unique_path;
+ ASSERT_TRUE(dm.GetDeviceUniquePath("libdm-test-dm-linear", &unique_path));
+ ASSERT_EQ(0, access(unique_path.c_str(), F_OK));
+
ASSERT_TRUE(dm.DeleteDevice("libdm-test-dm-linear", 5s));
ASSERT_EQ(DmDeviceState::INVALID, dm.GetState("libdm-test-dm-linear"));
- ASSERT_NE(0, access(path.c_str(), F_OK));
+ // Check that unique path of this device has been deleteted.
+ // Previously this test case used to check that dev node (i.e. /dev/block/dm-XX) has been
+ // deleted. However, this introduces a race condition, ueventd will remove the unique symlink
+ // (i.e. /dev/block/mapper/by-uuid/...) **before** removing the device node, while DeleteDevice
+ // API synchronizes on the unique symlink being deleted.
+ ASSERT_NE(0, access(unique_path.c_str(), F_OK));
ASSERT_EQ(ENOENT, errno);
}