Fix threading issue in ExecuteHelper (#13643)
This commit is contained in:
parent
5609d7db88
commit
21c7bb3abb
5 changed files with 104 additions and 98 deletions
|
@ -5,7 +5,6 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
|
||||
|
@ -81,15 +80,6 @@ internal class DotNetHelper
|
|||
|
||||
public void ExecuteCmd(string args, string? workingDirectory = null, Action<Process>? additionalProcessConfigCallback = null, int expectedExitCode = 0, int millisecondTimeout = -1)
|
||||
{
|
||||
Action<Process, string?> configureProcess = (Process process, string? workingDirectory) => {
|
||||
ConfigureProcess(process, workingDirectory);
|
||||
|
||||
if (additionalProcessConfigCallback != null)
|
||||
{
|
||||
additionalProcessConfigCallback(process);
|
||||
}
|
||||
};
|
||||
|
||||
(Process Process, string StdOut, string StdErr) executeResult = ExecuteHelper.ExecuteProcess(
|
||||
DotNetPath,
|
||||
args,
|
||||
|
@ -98,6 +88,13 @@ internal class DotNetHelper
|
|||
millisecondTimeout: millisecondTimeout);
|
||||
|
||||
ExecuteHelper.ValidateExitCode(executeResult, expectedExitCode);
|
||||
|
||||
void configureProcess(Process process, string? workingDirectory)
|
||||
{
|
||||
ConfigureProcess(process, workingDirectory);
|
||||
|
||||
additionalProcessConfigCallback?.Invoke(process);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ConfigureProcess(Process process, string? workingDirectory, bool setPath = false)
|
||||
|
|
|
@ -44,10 +44,24 @@ internal static class ExecuteHelper
|
|||
configure?.Invoke(process);
|
||||
|
||||
StringBuilder stdOutput = new();
|
||||
process.OutputDataReceived += new DataReceivedEventHandler((sender, e) => stdOutput.AppendLine(e.Data));
|
||||
process.OutputDataReceived += new DataReceivedEventHandler(
|
||||
(sender, e) =>
|
||||
{
|
||||
lock (stdOutput)
|
||||
{
|
||||
stdOutput.AppendLine(e.Data);
|
||||
}
|
||||
});
|
||||
|
||||
StringBuilder stdError = new();
|
||||
process.ErrorDataReceived += new DataReceivedEventHandler((sender, e) => stdError.AppendLine(e.Data));
|
||||
process.ErrorDataReceived += new DataReceivedEventHandler(
|
||||
(sender, e) =>
|
||||
{
|
||||
lock (stdError)
|
||||
{
|
||||
stdError.AppendLine(e.Data);
|
||||
}
|
||||
});
|
||||
|
||||
process.Start();
|
||||
process.BeginOutputReadLine();
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.SourceBuild.SmokeTests
|
||||
{
|
||||
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
|
||||
|
||||
/// <summary>
|
||||
/// A Fact that will be skipped based on the specified environment variable's value.
|
||||
/// </summary>
|
||||
|
@ -37,4 +37,3 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.SourceBuild.SmokeTests
|
||||
{
|
||||
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
|
||||
|
||||
/// <summary>
|
||||
/// A Theory that will be skipped based on the specified environment variable's value.
|
||||
/// </summary>
|
||||
|
@ -17,4 +17,3 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
|
|||
public SkippableTheoryAttribute(string[] envNames, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) =>
|
||||
SkippableFactAttribute.CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envNames);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
|
||||
|
||||
namespace Microsoft.DotNet.SourceBuild.SmokeTests
|
||||
{
|
||||
public class TestScenario
|
||||
{
|
||||
public DotNetActions Commands { get; }
|
||||
|
@ -64,4 +62,3 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue