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

Read asynchronously from test host process. #529

Merged
merged 3 commits into from
Feb 22, 2017
Merged

Read asynchronously from test host process. #529

merged 3 commits into from
Feb 22, 2017

Conversation

mayankbansal018
Copy link
Contributor

No description provided.

@msftclas
Copy link

Hi @mayankbansal018, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor. If you're full-time or an intern, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

}

this.RequestSender.OnClientProcessExit(testHostProcessStdError);
if (process.HasExited && process.ExitCode != 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

process.HasExited can throw InvalidOperationException if no process associated with object, process.ExitCode can throw IOE if the process has not exited. is there a guaranty process.HasExited doesn't throw in callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested process.HasExited out, the process object is valid, even after the actual process has ended.
Process.ExitCode is only called if the process.HasExited is successful.

{
if (process.ExitCode != 0)
if(data != null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: move this to a method.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: if ( instead if(.

/// Returns the current error data in stream
/// Written purely for UT as of now.
/// </summary>
public virtual string GetStandardError()
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it protected. Use a Testable in unit test.

@@ -39,12 +44,14 @@ public abstract class ProxyOperationManager
/// <param name="requestSender">Request Sender instance.</param>
/// <param name="testHostManager">Test host manager instance.</param>
/// <param name="clientConnectionTimeout">Client Connection Timeout.</param>
protected ProxyOperationManager(ITestRequestSender requestSender, ITestHostManager testHostManager, int clientConnectionTimeout)
protected ProxyOperationManager(ITestRequestSender requestSender, ITestHostManager testHostManager, int clientConnectionTimeout, int errorLength = 1000)
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicit arguments are better. Please call with 1000 from the public ctor.

if (data.Length > testHostProcessStdError.MaxCapacity)
{
testHostProcessStdError.Remove(0, testHostProcessStdError.Length);
data = data.Substring(data.Length - testHostProcessStdError.MaxCapacity);
Copy link
Contributor

Choose a reason for hiding this comment

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

We're keeping the first few characters, should it be last few characters?

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 are keeping last few only substring(index) which will give from starting index to end

{
this.RequestSender = requestSender;
this.connectionTimeout = clientConnectionTimeout;
this.testHostManager = testHostManager;
this.processHelper = new ProcessHelper();
this.errorLength = errorLength;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instance variable is not used any where?

data = data.Substring(data.Length - testHostProcessStdError.MaxCapacity);
}

//remove only what is required, from begining of error stream
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: spelling

//if incoming data stream is huge empty entire testError stream, & limit data stream to MaxCapacity
if (data.Length > testHostProcessStdError.MaxCapacity)
{
testHostProcessStdError.Remove(0, testHostProcessStdError.Length);
Copy link
Contributor

Choose a reason for hiding this comment

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

Which of these is most efficient?

  1. StringBuilder.Clear followed by StringBuilder.Append
  2. StringBuilder.Remove(x, y) followed by StringBuilder.Append
  3. StringBuilder[i] = data[i]

}

EqtTrace.Verbose("ProcessHelper: Starting process '{0}' with command line '{1}'", processPath, arguments);
process.Start();

process.BeginErrorReadLine();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we require this even if errorCallback is not set?

[TestMethod]
public void ErrorMessageShouldBeTruncatedToMatchErrorLength()
{
string errorData = "Long Custom Error Strings";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to organize unit tests as follows for readability (comments are not required, newlines are only between blocks):

// Block of arrange
int x = 10;
double y = 9.0

// Block of act
CallFoo(y);

// Block of assert
Assert(12.0, y);
Assert(29, x);

Copy link
Contributor

@codito codito left a comment

Choose a reason for hiding this comment

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

Looks good with few suggested changes.

@mayankbansal018
Copy link
Contributor Author

Bug: #521

@mayankbansal018 mayankbansal018 deleted the #521-ReadErrorStream-Async branch March 9, 2017 12:39
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