Skip to content
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

Merged
merged 10 commits into from
Aug 1, 2018

Conversation

smadala
Copy link
Contributor

@smadala smadala commented Jul 31, 2018

Description

  • Prints start of stderr stacktrace
  • Increase max length of stderr message.

Related issue

Fixes #1688

@@ -17,5 +19,28 @@ public static string AddDoubleQuote(this string value)
{
return "\"" + value + "\"";
}

public static void AppendToStringBuilderBasedOnMaxLength(this string data, StringBuilder result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like string extension. May be a string builder extension.
public static void AppendSafe(this StringBuilder stringBuilder, string data)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create StringBuilderExtensions class with AppendSafeWithNewLine().

@@ -17,5 +19,28 @@ public static string AddDoubleQuote(this string value)
{
return "\"" + value + "\"";
}

public static void AppendToStringBuilderBasedOnMaxLength(this string data, StringBuilder result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write comment as well for this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

}

[TestMethod]
public void ErrorReceivedCallbackShouldAppendEntireStringEvenItReachesToMaxLength()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EvenItReachesToMaxLength? In code, max length is not reached.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Windows NewLine is two characters.

}

// Add newline for readbility.
data += Environment.NewLine;
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create StringBuilderExtensions class with AppendSafeWithNewLine().

Copy link
Contributor

@abhishkk abhishkk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with suggestions.


/// <summary>
/// Number of character should be logged on child process exited with
/// error message on stadard error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:standard

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/// Number of character should be logged on child process exited with
/// error message on stadard error.
/// </summary>
public const int StandardErrorMaxLength = 20480; // 20 KB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason for increasing it by 5 times. 4096 was a reasonable buffer, we can probably make ti 8192 (2x), if user wants more info, they can always go ahead check the logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it 8192

/// <param name="result">string builder</param>
/// /// <param name="data">data to be appended.</param>
/// <returns></returns>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:Extra line
Nit:readability* inside the method below

public static class StringBuilderExtensions
{
/// <summary>
/// Add double quote around string. Useful in case of path which has white space in between.
Copy link
Contributor

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.

@@ -17,5 +17,28 @@ public static string AddDoubleQuote(this string value)
{
return "\"" + value + "\"";
}

public static void AppendToStringBuilderBasedOnMaxLength(this string data, StringBuilder result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still see this code, please remove this.

// 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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@@ -17,5 +17,28 @@ public static string AddDoubleQuote(this string value)
{
return "\"" + value + "\"";
}

public static void AppendToStringBuilderBasedOnMaxLength(this string data, StringBuilder result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this method needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is removed in latest commits.

@@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection
using System;
using System.Collections.Generic;
using System.Text;

using CoreUtilities.Extensions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Please use full namespace

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we initialize it with something other than that of 0 length?

@smadala smadala merged commit a3a2775 into microsoft:master Aug 1, 2018
@smadala smadala deleted the fix-debug-assert branch August 1, 2018 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants