Skip to content

Commit ca6dc74

Browse files
yfeldblumfacebook-github-bot
authored andcommitted
let AsyncFileWriter.fork test not discard writes
Summary: X-link: facebook/folly#2459 If testing that all expected writes are accepted, then the `AsyncFileWriter` must be configured not to discard writes. The test is currently failing in the mac builds on github - perhaps this will help. Reviewed By: ilvokhin Differential Revision: D77422878 fbshipit-source-id: 81951ac88b35760b7b138722cca54f3463982440
1 parent b0a0e36 commit ca6dc74

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

third-party/folly/src/folly/logging/test/AsyncFileWriterTest.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,9 @@ TEST(AsyncFileWriter, fork) {
650650

651651
{
652652
AsyncFileWriter writer{folly::File{tmpFile.fd(), false}};
653-
writer.writeMessage(folly::to<std::string>("parent pid=", getpid(), "\n"));
653+
writer.writeMessage(
654+
folly::to<std::string>("parent pid=", getpid(), "\n"),
655+
AsyncFileWriter::NEVER_DISCARD);
654656

655657
// Start some background threads just to exercise the behavior
656658
// when other threads are also logging to the writer when the fork occurs
@@ -661,22 +663,30 @@ TEST(AsyncFileWriter, fork) {
661663
size_t iter = 0;
662664
while (!stop) {
663665
writer.writeMessage(
664-
folly::to<std::string>("bgthread_", getpid(), "_", iter, "\n"));
666+
folly::to<std::string>("bgthread_", getpid(), "_", iter, "\n"),
667+
AsyncFileWriter::NEVER_DISCARD);
665668
++iter;
669+
asm_volatile_pause();
666670
}
667671
});
668672
}
669673

670674
for (size_t n = 0; n < numMessages; ++n) {
671-
writer.writeMessage(folly::to<std::string>("prefork", n, "\n"));
675+
writer.writeMessage(
676+
folly::to<std::string>("prefork", n, "\n"),
677+
AsyncFileWriter::NEVER_DISCARD);
672678
}
673679

674680
auto pid = fork();
675681
folly::checkUnixError(pid, "failed to fork");
676682
if (pid == 0) {
677-
writer.writeMessage(folly::to<std::string>("child pid=", getpid(), "\n"));
683+
writer.writeMessage(
684+
folly::to<std::string>("child pid=", getpid(), "\n"),
685+
AsyncFileWriter::NEVER_DISCARD);
678686
for (size_t n = 0; n < numMessages; ++n) {
679-
writer.writeMessage(folly::to<std::string>("child", n, "\n"));
687+
writer.writeMessage(
688+
folly::to<std::string>("child", n, "\n"),
689+
AsyncFileWriter::NEVER_DISCARD);
680690
std::this_thread::sleep_for(sleepDuration);
681691
}
682692

@@ -692,7 +702,9 @@ TEST(AsyncFileWriter, fork) {
692702
}
693703

694704
for (size_t n = 0; n < numMessages; ++n) {
695-
writer.writeMessage(folly::to<std::string>("parent", n, "\n"));
705+
writer.writeMessage(
706+
folly::to<std::string>("parent", n, "\n"),
707+
AsyncFileWriter::NEVER_DISCARD);
696708
std::this_thread::sleep_for(sleepDuration);
697709
}
698710

0 commit comments

Comments
 (0)