Do not mix stdout/stderr, write service messages atomically.

This commit is contained in:
Aleksey Khoroshilov
2024-05-13 18:30:33 +07:00
parent d4c5403e00
commit 65fdfbbbba
3 changed files with 13 additions and 3 deletions
@@ -53,18 +53,22 @@ class EscapedValue {
TeamcityServiceMessages::Message::Message(std::ostream& ostream,
std::string_view name)
: ostream_(ostream) {
(*ostream_) << "##teamcity[" << name;
// Use stringstream to format the message before writing it to stdout.
sstream_ << "##teamcity[" << name;
}
TeamcityServiceMessages::Message::~Message() {
(*ostream_) << "]" << std::endl;
sstream_ << "]" << std::endl;
// Important: output into stdout in a single call to not mix with outputs from
// other threads.
(*ostream_) << sstream_.str() << std::flush;
}
TeamcityServiceMessages::Message&
TeamcityServiceMessages::Message::WriteProperty(std::string_view name,
std::string_view value) {
if (!value.empty()) {
(*ostream_) << " " << name << "='" << EscapedValue(value) << "'";
sstream_ << " " << name << "='" << EscapedValue(value) << "'";
}
return *this;
}
@@ -7,6 +7,7 @@
#define BRAVE_BASE_TEST_LAUNCHER_TEAMCITY_SERVICE_MESSAGES_H_
#include <ostream>
#include <sstream>
#include <string_view>
#include "base/memory/raw_ref.h"
@@ -48,6 +49,7 @@ class TeamcityServiceMessages {
private:
raw_ref<std::ostream> ostream_;
std::ostringstream sstream_;
};
raw_ref<std::ostream> ostream_;
+4
View File
@@ -164,6 +164,10 @@ const runTests = (passthroughArgs, suite, buildConfig, options) => {
`--avd-config tools/android/avd/proto/generic_android${options.android_test_emulator_version}.textpb`)
}
let runOptions = config.defaultOptions
if (config.isTeamcity) {
// Stdout and stderr must be separate for a test launcher.
runOptions.stdio = 'inherit'
}
if (options.output)
// When test results are saved to a file, callers (such as CI) generate
// and analyze test reports as a next step. These callers are typically