-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print start of testhost standard error message #1708
Changes from 7 commits
8b865e4
268d353
a27b17d
784079a
55f8799
0f2f27b
c405246
5a50975
2fdda1f
16648ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions | ||
{ | ||
using System; | ||
using System.Text; | ||
|
||
public static class StringBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Add double quote around string. Useful in case of path which has white space in between. | ||
/// </summary> | ||
/// <param name="result">string builder</param> | ||
/// /// <param name="data">data to be appended.</param> | ||
/// <returns></returns> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:Extra line |
||
public static void AppendSafeWithNewLine(this StringBuilder result, string data) | ||
{ | ||
if (!string.IsNullOrEmpty(data)) | ||
{ | ||
// Don't append more data if already reached max length. | ||
if (result.Length >= result.MaxCapacity) | ||
{ | ||
return; | ||
} | ||
|
||
// Add newline for readbility. | ||
data += Environment.NewLine; | ||
|
||
// Append sub string of data if appending all the data exceeds max capacity. | ||
if (result.Length + data.Length >= result.MaxCapacity) | ||
{ | ||
data = data.Substring(0, result.MaxCapacity - result.Length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the idea here, are we saying the original Sting content will remain, & only add small part of new data? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
} | ||
|
||
result.Append(data); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
namespace Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions | ||
{ | ||
using System; | ||
using System.Net; | ||
using System.Text; | ||
|
||
public static class StringExtensions | ||
{ | ||
|
@@ -17,5 +17,28 @@ public static string AddDoubleQuote(this string value) | |
{ | ||
return "\"" + value + "\""; | ||
} | ||
|
||
public static void AppendToStringBuilderBasedOnMaxLength(this string data, StringBuilder result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't look like string extension. May be a string builder extension. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we write comment as well for this method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still see this code, please remove this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this method needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is removed in latest commits. |
||
{ | ||
if (!string.IsNullOrEmpty(data)) | ||
{ | ||
// Don't append more data if already reached max length. | ||
if (result.Length >= result.MaxCapacity) | ||
{ | ||
return; | ||
} | ||
|
||
// Add newline for readbility. | ||
data += Environment.NewLine; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are writing stringBuilder extension, then it should not be job of stringBuilder to add a new line. It should be the user's responsibility to add a new line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create |
||
|
||
// Append sub string of data if appending all the data exceeds max capacity. | ||
if (result.Length + data.Length >= result.MaxCapacity) | ||
{ | ||
data = data.Substring(0, result.MaxCapacity - result.Length); | ||
} | ||
|
||
result.Append(data); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection | |
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
using CoreUtilities.Extensions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Please use full namespace |
||
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; | ||
|
@@ -36,17 +36,12 @@ public DataCollectionLauncher(IProcessHelper processHelper, IMessageLogger messa | |
{ | ||
this.processHelper = processHelper; | ||
this.messageLogger = messageLogger; | ||
this.processStdError = new StringBuilder(this.ErrorLength, this.ErrorLength); | ||
this.processStdError = new StringBuilder(0, CoreUtilities.Constants.StandardErrorMaxLength); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When setting capacity to zero, will stringBuilder not be perf inefficient? As it needs to keep on copying and pasting the content to new instance whenever grow is required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't expect any stderr most of time. StringBuilder increase size exponentially. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we initialize it with something other than that of 0 length? |
||
} | ||
|
||
/// <inheritdoc /> | ||
public int DataCollectorProcessId { get; protected set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the error length for data collector error stream. | ||
/// </summary> | ||
protected int ErrorLength { get; set; } = 4096; | ||
|
||
/// <summary> | ||
/// Gets callback on process exit | ||
/// </summary> | ||
|
@@ -76,35 +71,13 @@ public DataCollectionLauncher(IProcessHelper processHelper, IMessageLogger messa | |
/// Gets callback to read from process error stream | ||
/// </summary> | ||
protected Action<object, string> ErrorReceivedCallback => (process, data) => | ||
{ | ||
if (!string.IsNullOrEmpty(data)) | ||
{ | ||
// Log all standard error message because on too much data we ignore starting part. | ||
// This is helpful in abnormal failure of process. | ||
EqtTrace.Warning("DataCollectionLauncher.ErrorReceivedCallback: Data collector standard error line: {0}", data); | ||
|
||
// Add newline for readbility. | ||
data += Environment.NewLine; | ||
|
||
// if incoming data stream is huge empty entire testError stream, & limit data stream to MaxCapacity | ||
if (data.Length > this.processStdError.MaxCapacity) | ||
{ | ||
this.processStdError.Clear(); | ||
data = data.Substring(data.Length - this.processStdError.MaxCapacity); | ||
} | ||
else | ||
{ | ||
// remove only what is required, from beginning of error stream | ||
int required = data.Length + this.processStdError.Length - this.processStdError.MaxCapacity; | ||
if (required > 0) | ||
{ | ||
this.processStdError.Remove(0, required); | ||
} | ||
} | ||
{ | ||
// Log all standard error message because on too much data we ignore starting part. | ||
// This is helpful in abnormal failure of datacollector. | ||
EqtTrace.Warning("DataCollectionLauncher.ErrorReceivedCallback datacollector standard error line: {0}", data); | ||
|
||
this.processStdError.Append(data); | ||
} | ||
}; | ||
this.processStdError.AppendSafeWithNewLine(data); | ||
}; | ||
|
||
/// <summary> | ||
/// The launch data collector. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary needs to be corrected.