diff --git a/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/Infrastructure/PackageLayoutFixture.cs b/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/Infrastructure/PackageLayoutFixture.cs index 2ba1712..164549e 100644 --- a/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/Infrastructure/PackageLayoutFixture.cs +++ b/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/Infrastructure/PackageLayoutFixture.cs @@ -53,14 +53,20 @@ private static ProcessResult RunProcess(string fileName, string arguments) CreateNoWindow = true }; + // Reused MSBuild nodes outlive the build and inherit the redirected pipes, so reading + // stdout/stderr to the end would block until their idle timeout expires. + startInfo.Environment["MSBUILDDISABLENODEREUSE"] = "1"; + using var process = new Process { StartInfo = startInfo }; process.Start(); + // Drain both streams concurrently; reading them one after another can deadlock once the + // other pipe's buffer is full. + var error = process.StandardError.ReadToEndAsync(); var output = process.StandardOutput.ReadToEnd(); - var error = process.StandardError.ReadToEnd(); process.WaitForExit(); - return new ProcessResult(process.ExitCode, string.Concat(output, error)); + return new ProcessResult(process.ExitCode, string.Concat(output, error.Result)); } private sealed record ProcessResult(int ExitCode, string Output); diff --git a/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/RefProjectBuildTests.cs b/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/RefProjectBuildTests.cs index 3496c34..02d9efd 100644 --- a/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/RefProjectBuildTests.cs +++ b/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/RefProjectBuildTests.cs @@ -66,6 +66,10 @@ private static ProcessResult RunProcess( CreateNoWindow = true }; + // Reused MSBuild nodes outlive the build and inherit the redirected pipes, so reading + // stdout/stderr to the end would block until their idle timeout expires. + process.StartInfo.Environment["MSBUILDDISABLENODEREUSE"] = "1"; + process.Start(); var stdOut = process.StandardOutput.ReadToEndAsync(); var stdErr = process.StandardError.ReadToEndAsync(); diff --git a/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/Tenekon.MethodOverloads.SourceGenerator.Tests.csproj b/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/Tenekon.MethodOverloads.SourceGenerator.Tests.csproj index 20096b0..895fcdb 100644 --- a/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/Tenekon.MethodOverloads.SourceGenerator.Tests.csproj +++ b/tests/Tenekon.MethodOverloads.SourceGenerator.Tests/Tenekon.MethodOverloads.SourceGenerator.Tests.csproj @@ -1,6 +1,8 @@  net8.0 + + Major preview enable enable