Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1555)

Unified Diff: base/test/launcher/test_results_tracker.cc

Issue 2592923002: Keep track of output_snippet bytes and drop output snippets if output is too large
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/launcher/test_results_tracker.cc
diff --git a/base/test/launcher/test_results_tracker.cc b/base/test/launcher/test_results_tracker.cc
index 01d222edb78a0da59e5e34dd2e512d6a0284f6ad..33e8628f33cd09e4e652e7ccc7cef708a0cec3a5 100644
--- a/base/test/launcher/test_results_tracker.cc
+++ b/base/test/launcher/test_results_tracker.cc
@@ -301,6 +301,46 @@ void TestResultsTracker::AddGlobalTag(const std::string& tag) {
global_tags_.insert(tag);
}
+// Sets output_snippet-related fields in test_result_value.
+// Does not take ownership of test_result_value.
+// Returns the number of bytes of snippet data that were added to
+// test_result_value.
+int SetSnippets(StringPiece output_snippet,
+ DictionaryValue* test_result_value) {
+ int num_bytes = 0;
+ // Always include the raw version (base64-encoded so that it can be safely
+ // JSON-serialized - there are no guarantees about character encoding of the
+ // snippet). This can be very useful piece of information when debugging a
+ // test failure related to character encoding.
+ std::string base64;
+ Base64Encode(output_snippet, &base64);
+ test_result_value->SetString("output_snippet_base64", base64);
+ num_bytes += base64.size();
+
+ bool lossless_snippet = false;
+ if (IsStringUTF8(output_snippet)) {
+ lossless_snippet = true;
+ } else {
+ output_snippet = "<non-UTF-8 snippet, see output_snippet_base64>";
+ }
+
+ test_result_value->SetString("output_snippet", output_snippet);
+ num_bytes += output_snippet.size();
+
+ // TODO(phajdan.jr): Fix typo in JSON key (losless -> lossless)
+ // making sure not to break any consumers of this data.
+ test_result_value->SetBoolean("losless_snippet", lossless_snippet);
+
+ return num_bytes;
+}
+
+// This is the maximum output.json which can be handled by
+// build/scripts/slave/recipe_modules/swarming/resources/collect_gtest_task.py
+// SaveSummaryAsJSON does not strictly ensure that its output is below this
+// threshold, but it will attempt to avoid exceeding this maximum by dropping
+// output_snippets as the total output approaches this threshold.
+const int kMaxSummaryJSON = 100 * 1024 * 1024;
+
bool TestResultsTracker::SaveSummaryAsJSON(
const FilePath& path,
const std::vector<std::string>& additional_tags) const {
@@ -329,6 +369,12 @@ bool TestResultsTracker::SaveSummaryAsJSON(
std::unique_ptr<ListValue> per_iteration_data(new ListValue);
+ // Keep track of the number of bytes used by the contents of output snippets.
+ // Once we use up half of the maxium output size, we will start dropping
+ // snippets.
+ int snippet_bytes = 0;
+ int snippet_byte_threshold = kMaxSummaryJSON / 2;
+
for (int i = 0; i <= iteration_; i++) {
std::unique_ptr<DictionaryValue> current_iteration_data(
new DictionaryValue);
@@ -349,29 +395,11 @@ bool TestResultsTracker::SaveSummaryAsJSON(
"elapsed_time_ms",
static_cast<int>(test_result.elapsed_time.InMilliseconds()));
- bool lossless_snippet = false;
- if (IsStringUTF8(test_result.output_snippet)) {
- test_result_value->SetString(
- "output_snippet", test_result.output_snippet);
- lossless_snippet = true;
- } else {
- test_result_value->SetString(
- "output_snippet",
- "<non-UTF-8 snippet, see output_snippet_base64>");
- }
-
- // TODO(phajdan.jr): Fix typo in JSON key (losless -> lossless)
- // making sure not to break any consumers of this data.
- test_result_value->SetBoolean("losless_snippet", lossless_snippet);
-
- // Also include the raw version (base64-encoded so that it can be safely
- // JSON-serialized - there are no guarantees about character encoding
- // of the snippet). This can be very useful piece of information when
- // debugging a test failure related to character encoding.
- std::string base64_output_snippet;
- Base64Encode(test_result.output_snippet, &base64_output_snippet);
- test_result_value->SetString("output_snippet_base64",
- base64_output_snippet);
+ StringPiece snippet = snippet_bytes > snippet_byte_threshold
+ ? "lengthy output elided"
Paweł Hajdan Jr. 2016/12/22 14:18:39 I'm concerned this seems to result in a silent fai
+ : test_result.output_snippet;
+ snippet_bytes += SetSnippets(snippet, test_result_value.get());
+
test_results->Append(std::move(test_result_value));
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698