Skip to content

Commit ce0b374

Browse files
authored
Pre-build samples via tests to avoid timeouts (#4245)
1 parent ce9f2cd commit ce0b374

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

.github/workflows/dotnet-build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ jobs:
260260
--ignore-exit-code 8 `
261261
--filter-not-trait "Category=IntegrationDisabled" `
262262
--parallel-algorithm aggressive `
263-
--max-threads 4.0x
263+
--max-threads 2.0x
264264
env:
265265
# Cosmos DB Emulator connection settings
266266
COSMOSDB_ENDPOINT: https://localhost:8081

dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/SamplesValidation.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,9 @@ private async Task WaitForConditionAsync(Func<Task<bool>> condition, string mess
792792

793793
private async Task RunSampleTestAsync(string samplePath, Func<IReadOnlyList<OutputLog>, Task> testAction)
794794
{
795+
// Build the sample project first (it may not have been built as part of the solution)
796+
await this.BuildSampleAsync(samplePath);
797+
795798
// Start the Azure Functions app
796799
List<OutputLog> logsContainer = [];
797800
using Process funcProcess = this.StartFunctionApp(samplePath, logsContainer);
@@ -811,12 +814,39 @@ private async Task RunSampleTestAsync(string samplePath, Func<IReadOnlyList<Outp
811814

812815
private sealed record OutputLog(DateTime Timestamp, LogLevel Level, string Message);
813816

817+
private async Task BuildSampleAsync(string samplePath)
818+
{
819+
this._outputHelper.WriteLine($"Building sample at {samplePath}...");
820+
821+
ProcessStartInfo buildInfo = new()
822+
{
823+
FileName = "dotnet",
824+
Arguments = $"build -f {s_dotnetTargetFramework}",
825+
WorkingDirectory = samplePath,
826+
UseShellExecute = false,
827+
RedirectStandardOutput = true,
828+
RedirectStandardError = true,
829+
};
830+
831+
using Process buildProcess = new() { StartInfo = buildInfo };
832+
buildProcess.Start();
833+
await buildProcess.WaitForExitAsync();
834+
835+
if (buildProcess.ExitCode != 0)
836+
{
837+
string stderr = await buildProcess.StandardError.ReadToEndAsync();
838+
throw new InvalidOperationException($"Failed to build sample at {samplePath}: {stderr}");
839+
}
840+
841+
this._outputHelper.WriteLine($"Build completed for {samplePath}.");
842+
}
843+
814844
private Process StartFunctionApp(string samplePath, List<OutputLog> logs)
815845
{
816846
ProcessStartInfo startInfo = new()
817847
{
818848
FileName = "dotnet",
819-
Arguments = $"run -f {s_dotnetTargetFramework} --port {AzureFunctionsPort}",
849+
Arguments = $"run --no-build -f {s_dotnetTargetFramework} --port {AzureFunctionsPort}",
820850
WorkingDirectory = samplePath,
821851
UseShellExecute = false,
822852
RedirectStandardOutput = true,

0 commit comments

Comments
 (0)