-
Notifications
You must be signed in to change notification settings - Fork 1.3k
.NET: Separate build from run for console sample validation #4251
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -735,6 +735,9 @@ private async Task<bool> IsRedisRunningAsync() | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private async Task RunSampleTestAsync(string samplePath, Func<Process, BlockingCollection<OutputLog>, Task> testAction) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| // Build the sample project first (it may not have been built as part of the solution) | ||||||||||||||||||||||||||||||||||||||||||
| await this.BuildSampleAsync(samplePath); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // Generate a unique TaskHub name for this sample test to prevent cross-test interference | ||||||||||||||||||||||||||||||||||||||||||
| // when multiple tests run together and share the same DTS emulator. | ||||||||||||||||||||||||||||||||||||||||||
| string uniqueTaskHubName = $"sample-{Guid.NewGuid().ToString("N").Substring(0, 6)}"; | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -813,12 +816,39 @@ private async Task WriteInputAsync(Process process, string input, CancellationTo | |||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private async Task BuildSampleAsync(string samplePath) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| this._outputHelper.WriteLine($"Building sample at {samplePath}..."); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ProcessStartInfo buildInfo = new() | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| FileName = "dotnet", | ||||||||||||||||||||||||||||||||||||||||||
| Arguments = $"build --framework {s_dotnetTargetFramework}", | ||||||||||||||||||||||||||||||||||||||||||
| WorkingDirectory = samplePath, | ||||||||||||||||||||||||||||||||||||||||||
| UseShellExecute = false, | ||||||||||||||||||||||||||||||||||||||||||
| RedirectStandardOutput = true, | ||||||||||||||||||||||||||||||||||||||||||
| RedirectStandardError = true, | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| using Process buildProcess = new() { StartInfo = buildInfo }; | ||||||||||||||||||||||||||||||||||||||||||
| buildProcess.Start(); | ||||||||||||||||||||||||||||||||||||||||||
| await buildProcess.WaitForExitAsync(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if (buildProcess.ExitCode != 0) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| string stderr = await buildProcess.StandardError.ReadToEndAsync(); | ||||||||||||||||||||||||||||||||||||||||||
| throw new InvalidOperationException($"Failed to build sample at {samplePath}: {stderr}"); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+835
to
+840
|
||||||||||||||||||||||||||||||||||||||||||
| await buildProcess.WaitForExitAsync(); | |
| if (buildProcess.ExitCode != 0) | |
| { | |
| string stderr = await buildProcess.StandardError.ReadToEndAsync(); | |
| throw new InvalidOperationException($"Failed to build sample at {samplePath}: {stderr}"); | |
| Task<string> standardOutputTask = buildProcess.StandardOutput.ReadToEndAsync(); | |
| Task<string> standardErrorTask = buildProcess.StandardError.ReadToEndAsync(); | |
| await Task.WhenAll(buildProcess.WaitForExitAsync(), standardOutputTask, standardErrorTask); | |
| if (buildProcess.ExitCode != 0) | |
| { | |
| string stdout = await standardOutputTask; | |
| string stderr = await standardErrorTask; | |
| throw new InvalidOperationException( | |
| $"Failed to build sample at {samplePath}:{Environment.NewLine}" + | |
| $"STDOUT:{Environment.NewLine}{stdout}{Environment.NewLine}" + | |
| $"STDERR:{Environment.NewLine}{stderr}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new build step runs before the per-test timeout/cancellation used by the sample validation logic. If
dotnet buildhangs (e.g., restore stall, MSBuild issue), these tests may never time out and can wedge CI. Consider threading aCancellationTokenintoRunSampleTestAsync/BuildSampleAsync(or using a dedicated build timeout) and passing it toWaitForExitAsync(token).