From 232e5c3a3bfb5150b951620c517418bd4bd97383 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 16 May 2014 06:25:20 -0700 Subject: [PATCH] Test retry on EINTR in close. --- test/gtest-extra.cc | 1 - test/posix-test.cc | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/test/gtest-extra.cc b/test/gtest-extra.cc index a218803b..25fd8389 100644 --- a/test/gtest-extra.cc +++ b/test/gtest-extra.cc @@ -56,7 +56,6 @@ namespace { #ifdef _WIN32 // On Windows the count argument to read and write is unsigned, so convert // it from size_t preventing integer overflow. -// TODO: test inline unsigned ConvertRWCount(std::size_t count) { return count <= UINT_MAX ? static_cast(count) : UINT_MAX; } diff --git a/test/posix-test.cc b/test/posix-test.cc index a8f16891..7cd9daf8 100644 --- a/test/posix-test.cc +++ b/test/posix-test.cc @@ -119,4 +119,28 @@ TEST(FileTest, OpenRetry) { open, "cannot open file CMakeLists.txt"); } +TEST(FileTest, CloseNoRetryInDtor) { + File read_end, write_end; + File::pipe(read_end, write_end); + File *f = new File(std::move(read_end)); + int saved_close_count = 0; + EXPECT_WRITE(stderr, { + close_count = 1; + delete f; + saved_close_count = close_count; + close_count = 0; + }, FormatSystemErrorMessage(EINTR, "cannot close file") + "\n"); + EXPECT_EQ(2, saved_close_count); +} + +TEST(FileTest, CloseNoRetry) { + File read_end, write_end; + File::pipe(read_end, write_end); + close_count = 1; + EXPECT_SYSTEM_ERROR(read_end.close(), EINTR, "cannot close file"); + EXPECT_EQ(2, close_count); + close_count = 0; +} + // TODO: test retry on EINTR +// TODO: test ConvertRWCount