Skip to content

Commit

Permalink
Fix EndToEndTestHelper to read input and error streams only after pro…
Browse files Browse the repository at this point in the history
…cess exits (#129)
  • Loading branch information
kichalla authored May 11, 2019
1 parent c2fff09 commit fb02124
Showing 1 changed file with 14 additions and 42 deletions.
56 changes: 14 additions & 42 deletions tests/Oryx.Tests.Common/EndToEndTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public static async Task RunAndAssertAppAsync(
DockerCli dockerCli)
{
DockerRunCommandProcessResult runResult = null;
var showDebugInfo = true;
try
{
// Docker run the runtime container as a foreground process. This way we can catch any errors
Expand All @@ -187,63 +188,28 @@ public static async Task RunAndAssertAppAsync(
runCmd,
runArgs);

await RunAssertsAsync(
() =>
{
// An exception could have occurred when a Docker process failed to start.
Assert.Null(runResult.Exception);
Assert.False(runResult.Process.HasExited);
return Task.CompletedTask;
},
runResult,
output);
// An exception could have occurred when a Docker process failed to start.
Assert.Null(runResult.Exception);
Assert.False(runResult.Process.HasExited);

for (var i = 0; i < MaxRetryCount; i++)
{
await Task.Delay(TimeSpan.FromSeconds(DelayBetweenRetriesInSeconds));

try
{
// Make sure the process is still alive and fail fast if not alive.
await RunAssertsAsync(
async () =>
{
Assert.False(runResult.Process.HasExited);
await assertAction();
},
runResult,
output);
// Make sure the process is still alive and fail fast if not.
Assert.False(runResult.Process.HasExited);
await assertAction();

showDebugInfo = false;
break;
}
catch (Exception ex) when (ex.InnerException is IOException ||
ex.InnerException is SocketException)
{
if (i == MaxRetryCount - 1)
{
string debugInfo = string.Empty;

// ToString() on StringBuilder is throwing an exception probably because of a
// multithreading issue where the container is still writing data into it and we are trying
// to retrieve the content out of it.
try
{
// TO i
// System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative
// and less than the size of the collection.
// Parameter name: chunkLength
// Stack Trace:
// at System.Text.StringBuilder.ToString()
debugInfo = runResult.GetDebugInfo();
output.WriteLine(debugInfo);
}
catch (Exception debugInfoException)
{
output.WriteLine(
"An error occurred while trying to get data from the output and error " +
"streams of the container. Exception: " + debugInfoException.ToString());
}

throw;
}
}
Expand All @@ -255,6 +221,12 @@ await RunAssertsAsync(
{
// Stop the container so that shared resources (like ports) are disposed.
dockerCli.StopContainer(runResult.ContainerName);

// Access the output and error streams after the process has exited
if (showDebugInfo)
{
output.WriteLine(runResult.GetDebugInfo());
}
}
}
}
Expand Down

0 comments on commit fb02124

Please sign in to comment.