summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2019-02-04 16:34:37 -0800
committerShentubot <shentubot@google.com>2019-02-04 16:35:37 -0800
commit3eae03fe4f2813dc56d6e33cd7feb7760fccfb25 (patch)
tree4109020aabbc58d6032ddd65d8148368de1eaa5a
parenta9fe9afd6301bed8ab4fe4fd354d3cefa8dbd21e (diff)
Deflake unlink test.
Multiple tests were creating the same directory before removing it, making it possible for concurrent tests to fail because the directory already exists. PiperOrigin-RevId: 232389814 Change-Id: I35d409fff4b3fd864b30fee742cb587b14975c23
-rw-r--r--test/syscalls/linux/unlink.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/test/syscalls/linux/unlink.cc b/test/syscalls/linux/unlink.cc
index 4d5e0c6b6..4118fb19c 100644
--- a/test/syscalls/linux/unlink.cc
+++ b/test/syscalls/linux/unlink.cc
@@ -47,19 +47,20 @@ TEST(UnlinkTest, DirNotEmpty) {
}
TEST(UnlinkTest, Rmdir) {
- std::string path = JoinPath(GetAbsoluteTestTmpdir(), "NewDir");
- ASSERT_THAT(mkdir(path.c_str(), 0755), SyscallSucceeds());
- EXPECT_THAT(rmdir(path.c_str()), SyscallSucceeds());
+ auto dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
+ EXPECT_THAT(rmdir(dir.path().c_str()), SyscallSucceeds());
}
TEST(UnlinkTest, AtDir) {
int dirfd;
- EXPECT_THAT(dirfd = open(GetAbsoluteTestTmpdir().c_str(), O_DIRECTORY, 0),
- SyscallSucceeds());
+ auto tmpdir = GetAbsoluteTestTmpdir();
+ EXPECT_THAT(dirfd = open(tmpdir.c_str(), O_DIRECTORY, 0), SyscallSucceeds());
- std::string path = JoinPath(GetAbsoluteTestTmpdir(), "NewDir");
- EXPECT_THAT(mkdir(path.c_str(), 0755), SyscallSucceeds());
- EXPECT_THAT(unlinkat(dirfd, "NewDir", AT_REMOVEDIR), SyscallSucceeds());
+ auto dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDirIn(tmpdir));
+ auto dir_relpath =
+ ASSERT_NO_ERRNO_AND_VALUE(GetRelativePath(tmpdir, dir.path()));
+ EXPECT_THAT(unlinkat(dirfd, dir_relpath.c_str(), AT_REMOVEDIR),
+ SyscallSucceeds());
ASSERT_THAT(close(dirfd), SyscallSucceeds());
}