Enable a couple of AsyncFileWriter tests on Windows
authorChristopher Dykes <cdykes@fb.com>
Mon, 17 Jul 2017 19:57:29 +0000 (12:57 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 17 Jul 2017 20:08:09 +0000 (13:08 -0700)
Summary:
There is no longer anything keeping them from working on Windows.
Except for that `signal(SIGPIPE, SIG_IGN)` call; that has to stay disabled.

Reviewed By: simpkins

Differential Revision: D5308007

fbshipit-source-id: 74a392cf484404f41a6c51e50b5a9e6fbd05b4a9

folly/experimental/logging/test/AsyncFileWriterTest.cpp

index 962ec8c77c3848da8c121d4fb88b780ab9fad778..32dd790d1c7d2e37c61b02b5f530b2e6d01ae3e2 100644 (file)
@@ -86,6 +86,7 @@ TEST(AsyncFileWriter, simpleMessages) {
       sched_yield();
     }
   }
+  tmpFile.close();
 
   std::string data;
   auto ret = folly::readFile(tmpFile.path().string().c_str(), data);
@@ -105,7 +106,6 @@ TEST(AsyncFileWriter, simpleMessages) {
   EXPECT_EQ(expected, data);
 }
 
-#ifndef _WIN32
 namespace {
 static std::vector<std::string>* internalWarnings;
 
@@ -127,7 +127,9 @@ TEST(AsyncFileWriter, ioError) {
   std::array<int, 2> fds;
   auto rc = pipe(fds.data());
   folly::checkUnixError(rc, "failed to create pipe");
+#ifndef _WIN32
   signal(SIGPIPE, SIG_IGN);
+#endif
   ::close(fds[0]);
 
   // Log a bunch of messages to the writer
@@ -145,11 +147,23 @@ TEST(AsyncFileWriter, ioError) {
   // AsyncFileWriter should have some internal warning messages about the
   // log failures.  This will generally be many fewer than the number of
   // messages we wrote, though, since it performs write batching.
+  //
+  // GTest on Windows doesn't support alternation in the regex syntax -_-....
+  const std::string kExpectedErrorMessage =
+#if _WIN32
+      // The `pipe` call above is actually implemented via sockets, so we get
+      // a different error message.
+      "An established connection was aborted by the software in your host machine\\.";
+#else
+      "Broken pipe";
+#endif
+
   for (const auto& msg : logErrors) {
     EXPECT_THAT(
         msg,
         testing::ContainsRegex(
-            "error writing to log file .* in AsyncFileWriter.*: Broken pipe"));
+            "error writing to log file .* in AsyncFileWriter.*: " +
+            kExpectedErrorMessage));
   }
   EXPECT_GT(logErrors.size(), 0);
   EXPECT_LE(logErrors.size(), numMessages);
@@ -239,7 +253,6 @@ TEST(AsyncFileWriter, flush) {
   // Make sure flush completes successfully now
   future.get(10ms);
 }
-#endif
 
 // A large-ish message suffix, just to consume space and help fill up
 // log buffers faster.