X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fexperimental%2Flogging%2Ftest%2FAsyncFileWriterTest.cpp;h=eefcf746f6c378efdd61936dd54b23b90d169dd1;hp=3879740444b3ff124e363442a0eeb3acad4cb06b;hb=6072ce3be8548bae30fdd48afe67e986074f5a5b;hpb=d4e51b57186c30a66318ff14de720eea069b141e diff --git a/folly/experimental/logging/test/AsyncFileWriterTest.cpp b/folly/experimental/logging/test/AsyncFileWriterTest.cpp index 38797404..eefcf746 100644 --- a/folly/experimental/logging/test/AsyncFileWriterTest.cpp +++ b/folly/experimental/logging/test/AsyncFileWriterTest.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -86,6 +87,7 @@ TEST(AsyncFileWriter, simpleMessages) { sched_yield(); } } + tmpFile.close(); std::string data; auto ret = folly::readFile(tmpFile.path().string().c_str(), data); @@ -105,7 +107,6 @@ TEST(AsyncFileWriter, simpleMessages) { EXPECT_EQ(expected, data); } -#ifndef _WIN32 namespace { static std::vector* internalWarnings; @@ -115,7 +116,7 @@ void handleLoggingError( std::string&& msg) { internalWarnings->emplace_back(std::move(msg)); } -} +} // namespace TEST(AsyncFileWriter, ioError) { // Set the LoggerDB internal warning handler so we can record the messages @@ -127,7 +128,9 @@ TEST(AsyncFileWriter, ioError) { std::array 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 +148,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); @@ -191,7 +206,7 @@ size_t fillUpPipe(int fd) { return totalBytes; } -} +} // namespace TEST(AsyncFileWriter, flush) { // Set up a pipe(), then write data to the write endpoint until it fills up @@ -239,7 +254,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. @@ -255,7 +269,7 @@ class ReadStats { : deadline_{steady_clock::now() + milliseconds{FLAGS_async_discard_timeout_msec}}, readSleepUS_{static_cast( - std::min(0L, FLAGS_async_discard_read_sleep_usec))} {} + std::min(int64_t{0}, FLAGS_async_discard_read_sleep_usec))} {} void clearSleepDuration() { readSleepUS_.store(0); @@ -281,7 +295,9 @@ class ReadStats { } void writerFinished(size_t threadID, size_t messagesWritten, uint32_t flags) { auto map = perThreadWriteData_.wlock(); - assert(map->find(threadID) == map->end()); + FOLLY_SAFE_CHECK( + map->find(threadID) == map->end(), + "multiple writer threads with same ID"); auto& data = (*map)[threadID]; data.numMessagesWritten = messagesWritten; data.flags = flags; @@ -599,8 +615,7 @@ TEST(AsyncFileWriter, discard) { int main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); folly::init(&argc, &argv); - // Don't use async logging in the async logging tests :-) - folly::initLoggingGlogStyle(FLAGS_logging, LogLevel::INFO, /* async */ false); + folly::initLogging(FLAGS_logging); return RUN_ALL_TESTS(); }