-
Notifications
You must be signed in to change notification settings - Fork 1.6k
.NET: Improve visibility for AzureFunctions Workflows samples run tests in increase timeouts #4820
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
Merged
westey-m
merged 5 commits into
microsoft:main
from
westey-m:functions-workflows-samples-test-improve
Mar 20, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8ceab3
Reduce timeout flakiness for AzureFunctions Workflows samples run tests
westey-m 3ca5728
Add more updates
westey-m c39c3ee
Address PR comments
westey-m 8bee5f5
Address PR comments
westey-m 0e5a353
Merge branch 'main' into functions-workflows-samples-test-improve
westey-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...s/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/AzureFunctionsTestHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Diagnostics; | ||
|
|
||
| namespace Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests; | ||
|
|
||
| /// <summary> | ||
| /// Shared test helpers for Azure Functions integration tests. | ||
| /// </summary> | ||
| internal static class AzureFunctionsTestHelper | ||
| { | ||
| private static readonly TimeSpan s_buildTimeout = TimeSpan.FromMinutes(5); | ||
|
|
||
| /// <summary> | ||
| /// Builds the sample project, failing fast if the build fails or times out. | ||
| /// </summary> | ||
| internal static async Task BuildSampleAsync( | ||
| string samplePath, | ||
| string buildArgs, | ||
| ITestOutputHelper outputHelper) | ||
| { | ||
| outputHelper.WriteLine($"Building sample at {samplePath}..."); | ||
|
|
||
| ProcessStartInfo buildInfo = new() | ||
| { | ||
| FileName = "dotnet", | ||
| Arguments = $"build {buildArgs}", | ||
| WorkingDirectory = samplePath, | ||
| UseShellExecute = false, | ||
| RedirectStandardOutput = true, | ||
| RedirectStandardError = true, | ||
| }; | ||
|
|
||
| using Process buildProcess = new() { StartInfo = buildInfo }; | ||
| buildProcess.Start(); | ||
|
|
||
| // Read both streams asynchronously to avoid deadlocks from filled pipe buffers | ||
| Task<string> stdoutTask = buildProcess.StandardOutput.ReadToEndAsync(); | ||
| Task<string> stderrTask = buildProcess.StandardError.ReadToEndAsync(); | ||
|
|
||
| using CancellationTokenSource buildCts = new(s_buildTimeout); | ||
| try | ||
| { | ||
| await buildProcess.WaitForExitAsync(buildCts.Token); | ||
| } | ||
| catch (OperationCanceledException) | ||
| { | ||
| buildProcess.Kill(entireProcessTree: true); | ||
| throw new TimeoutException($"Build timed out after {s_buildTimeout.TotalMinutes} minutes for sample at {samplePath}."); | ||
| } | ||
|
|
||
| await Task.WhenAll(stdoutTask, stderrTask); | ||
|
|
||
| string stdout = stdoutTask.Result; | ||
| string stderr = stderrTask.Result; | ||
| if (buildProcess.ExitCode != 0) | ||
| { | ||
| throw new InvalidOperationException($"Failed to build sample at {samplePath}:\n{stdout}\n{stderr}"); | ||
| } | ||
|
|
||
| outputHelper.WriteLine($"Build completed for {samplePath}."); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Polls the Azure Functions host until it responds to an HTTP HEAD request, | ||
| /// failing fast if the host process exits unexpectedly. | ||
| /// </summary> | ||
| internal static async Task WaitForFunctionsReadyAsync( | ||
| Process funcProcess, | ||
| string port, | ||
| HttpClient httpClient, | ||
| ITestOutputHelper outputHelper, | ||
| TimeSpan timeout, | ||
| string? samplePath = null) | ||
| { | ||
| outputHelper.WriteLine( | ||
| $"Waiting for Azure Functions Core Tools to be ready at http://localhost:{port}/..."); | ||
|
|
||
| using CancellationTokenSource cts = new(timeout); | ||
| while (true) | ||
| { | ||
| // Fail fast if the host process has exited (e.g. build or startup failure) | ||
| if (funcProcess.HasExited) | ||
| { | ||
| string context = samplePath != null ? $" for sample '{samplePath}'" : string.Empty; | ||
| throw new InvalidOperationException( | ||
| $"The Azure Functions host process exited unexpectedly with code {funcProcess.ExitCode}{context}."); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| using HttpRequestMessage request = new(HttpMethod.Head, $"http://localhost:{port}/"); | ||
| using HttpResponseMessage response = await httpClient.SendAsync(request); | ||
| outputHelper.WriteLine($"Azure Functions Core Tools response: {response.StatusCode}"); | ||
| if (response.IsSuccessStatusCode) | ||
| { | ||
| return; | ||
| } | ||
| } | ||
| catch (HttpRequestException) | ||
| { | ||
| // Expected when the app isn't yet ready | ||
| } | ||
|
|
||
| try | ||
| { | ||
| await Task.Delay(TimeSpan.FromSeconds(1), cts.Token); | ||
| } | ||
| catch (OperationCanceledException) when (cts.IsCancellationRequested) | ||
| { | ||
| string context = samplePath != null ? $" for sample '{samplePath}'" : string.Empty; | ||
| throw new TimeoutException( | ||
| $"Timeout waiting for 'Azure Functions Core Tools is ready'{context}"); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.