sapling/eden/fs/telemetry/test/SubprocessScribeLoggerTest.cpp
Chad Austin 9a5f0093f2 introduce a scribe logger that communicates with scribe_cat
Summary: Introduce a new ScribeLogger class that spawns and maintains a process. Log messages are newline-delimited and written to the process's stdin. If the process stops responding or responds too slowly, log messages are dropped.

Reviewed By: pkaush

Differential Revision: D17777215

fbshipit-source-id: c998d10c73fc103122d69ae19c5d84f58b7939d2
2019-10-22 12:42:54 -07:00

31 lines
823 B
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include "eden/fs/telemetry/SubprocessScribeLogger.h"
#include <folly/experimental/TestUtil.h>
#include <gtest/gtest.h>
using namespace facebook::eden;
using namespace folly::string_piece_literals;
TEST(ScribeLogger, log_messages_are_written_with_newlines) {
folly::test::TemporaryFile output;
{
SubprocessScribeLogger logger{std::vector<std::string>{"/bin/cat"},
output.fd()};
logger.log("foo"_sp);
logger.log("bar"_sp);
}
folly::checkUnixError(lseek(output.fd(), 0, SEEK_SET));
std::string contents;
folly::readFile(output.fd(), contents);
EXPECT_EQ("foo\nbar\n", contents);
}