From ce0b374c2762880be59a5e527f103776a5f02c10 Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Wed, 25 Feb 2026 12:20:34 +0000 Subject: [PATCH] Pre-build samples via tests to avoid timeouts (#4245) --- .github/workflows/dotnet-build-and-test.yml | 2 +- .../SamplesValidation.cs | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet-build-and-test.yml b/.github/workflows/dotnet-build-and-test.yml index e79ff15f6d..8e3582517f 100644 --- a/.github/workflows/dotnet-build-and-test.yml +++ b/.github/workflows/dotnet-build-and-test.yml @@ -260,7 +260,7 @@ jobs: --ignore-exit-code 8 ` --filter-not-trait "Category=IntegrationDisabled" ` --parallel-algorithm aggressive ` - --max-threads 4.0x + --max-threads 2.0x env: # Cosmos DB Emulator connection settings COSMOSDB_ENDPOINT: https://localhost:8081 diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/SamplesValidation.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/SamplesValidation.cs index 19e75467c8..5b1e46ebf0 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/SamplesValidation.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/SamplesValidation.cs @@ -792,6 +792,9 @@ public sealed class SamplesValidation(ITestOutputHelper outputHelper) : IAsyncLi private async Task RunSampleTestAsync(string samplePath, Func, Task> testAction) { + // Build the sample project first (it may not have been built as part of the solution) + await this.BuildSampleAsync(samplePath); + // Start the Azure Functions app List logsContainer = []; using Process funcProcess = this.StartFunctionApp(samplePath, logsContainer); @@ -811,12 +814,39 @@ public sealed class SamplesValidation(ITestOutputHelper outputHelper) : IAsyncLi private sealed record OutputLog(DateTime Timestamp, LogLevel Level, string Message); + private async Task BuildSampleAsync(string samplePath) + { + this._outputHelper.WriteLine($"Building sample at {samplePath}..."); + + ProcessStartInfo buildInfo = new() + { + FileName = "dotnet", + Arguments = $"build -f {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}"); + } + + this._outputHelper.WriteLine($"Build completed for {samplePath}."); + } + private Process StartFunctionApp(string samplePath, List logs) { ProcessStartInfo startInfo = new() { FileName = "dotnet", - Arguments = $"run -f {s_dotnetTargetFramework} --port {AzureFunctionsPort}", + Arguments = $"run --no-build -f {s_dotnetTargetFramework} --port {AzureFunctionsPort}", WorkingDirectory = samplePath, UseShellExecute = false, RedirectStandardOutput = true,