Skip to content

Commit 23d785f

Browse files
author
Scott Arbeit
committed
Stabilize CI Aspire tests
1 parent ee4dace commit 23d785f

File tree

3 files changed

+21
-52
lines changed

3 files changed

+21
-52
lines changed

.github/workflows/validate.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,12 @@ jobs:
3636
run: dotnet workload install aspire
3737
- name: Docker info
3838
run: docker info
39+
- name: Pre-pull Aspire images
40+
run: |
41+
docker pull redis:latest
42+
docker pull mcr.microsoft.com/azure-storage/azurite:latest
43+
docker pull mcr.microsoft.com/mssql/server:2022-latest
44+
docker pull mcr.microsoft.com/azure-messaging/servicebus-emulator:latest
45+
docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
3946
- name: Validate (Full)
4047
run: pwsh ./scripts/validate.ps1 -Full

scripts/validate.ps1

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -135,40 +135,6 @@ function Invoke-External([string]$Label, [scriptblock]$Command) {
135135
}
136136
}
137137

138-
function Invoke-ParallelTests([array]$TestRuns, [string]$Configuration, [string]$RepoRoot) {
139-
if (-not $TestRuns -or $TestRuns.Count -eq 0) {
140-
return
141-
}
142-
143-
$jobs = foreach ($testRun in $TestRuns) {
144-
Start-Job -Name $testRun.Label -ArgumentList $testRun.Project, $Configuration, $RepoRoot, $testRun.Label -ScriptBlock {
145-
param($project, $configuration, $repoRoot, $label)
146-
Set-Location $repoRoot
147-
dotnet test $project -c $configuration
148-
$exitCode = $LASTEXITCODE
149-
[pscustomobject]@{ Label = $label; ExitCode = $exitCode }
150-
}
151-
}
152-
153-
$results = @()
154-
foreach ($job in $jobs) {
155-
$jobOutput = Receive-Job -Job $job -Wait -AutoRemoveJob
156-
foreach ($item in $jobOutput) {
157-
if ($item -is [pscustomobject] -and $item.PSObject.Properties.Name -contains "ExitCode") {
158-
$results += $item
159-
} else {
160-
Write-Host $item
161-
}
162-
}
163-
}
164-
165-
$failed = $results | Where-Object { $_.ExitCode -ne 0 }
166-
if ($failed) {
167-
$failedLabels = ($failed | Select-Object -ExpandProperty Label) -join ", "
168-
throw "Tests failed: $failedLabels."
169-
}
170-
}
171-
172138
try {
173139
if (-not $Fast -and -not $Full) {
174140
$Fast = $true
@@ -226,22 +192,10 @@ try {
226192

227193
if (-not $SkipTests) {
228194
Write-Section "Test"
229-
if ($Full) {
230-
$repoRoot = (Get-Location).Path
231-
$testRuns = @(
232-
[pscustomobject]@{
233-
Label = "Grace.CLI.Tests"
234-
Project = "src/Grace.CLI.Tests/Grace.CLI.Tests.fsproj"
235-
},
236-
[pscustomobject]@{
237-
Label = "Grace.Server.Tests"
238-
Project = "src/Grace.Server.Tests/Grace.Server.Tests.fsproj"
239-
}
240-
)
195+
Invoke-External "Grace.CLI.Tests" { dotnet test "src/Grace.CLI.Tests/Grace.CLI.Tests.fsproj" -c $Configuration }
241196

242-
Invoke-ParallelTests -TestRuns $testRuns -Configuration $Configuration -RepoRoot $repoRoot
243-
} else {
244-
Invoke-External "Grace.CLI.Tests" { dotnet test "src/Grace.CLI.Tests/Grace.CLI.Tests.fsproj" -c $Configuration }
197+
if ($Full) {
198+
Invoke-External "Grace.Server.Tests" { dotnet test "src/Grace.Server.Tests/Grace.Server.Tests.fsproj" -c $Configuration }
245199
}
246200
} else {
247201
Write-Section "Test"

src/Grace.Server.Tests/AspireTestHost.fs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ module AspireTestHost =
3737

3838
let private graceServerResourceName = "grace-server"
3939
let private serviceBusEmulatorResourceName = "servicebus-emulator"
40-
let private defaultWaitTimeout = TimeSpan.FromMinutes(5.0)
40+
let private isCi =
41+
match Environment.GetEnvironmentVariable("GITHUB_ACTIONS"), Environment.GetEnvironmentVariable("CI") with
42+
| value, _ when not (String.IsNullOrWhiteSpace value) -> true
43+
| _, value when not (String.IsNullOrWhiteSpace value) -> true
44+
| _ -> false
45+
46+
let private getTimeout (local: TimeSpan) (ci: TimeSpan) = if isCi then ci else local
47+
48+
let private defaultWaitTimeout = getTimeout (TimeSpan.FromMinutes(5.0)) (TimeSpan.FromMinutes(10.0))
4149

4250
let private getResource (app: DistributedApplication) (resourceName: string) =
4351
let model = app.Services.GetRequiredService<DistributedApplicationModel>()
@@ -294,7 +302,7 @@ module AspireTestHost =
294302
let private waitForServiceBusReadyAsync (state: TestHostState) =
295303
task {
296304
let sw = Stopwatch.StartNew()
297-
let timeout = TimeSpan.FromSeconds(60.0)
305+
let timeout = getTimeout (TimeSpan.FromSeconds(60.0)) (TimeSpan.FromMinutes(3.0))
298306
let mutable lastError = String.Empty
299307
let mutable ready = false
300308

@@ -343,7 +351,7 @@ module AspireTestHost =
343351

344352
use client = new CosmosClient(connectionString, options)
345353
let sw = Stopwatch.StartNew()
346-
let timeout = TimeSpan.FromMinutes(3.0)
354+
let timeout = getTimeout (TimeSpan.FromMinutes(3.0)) (TimeSpan.FromMinutes(6.0))
347355
let perCallTimeout = TimeSpan.FromSeconds(10.0)
348356
let mutable lastError = String.Empty
349357
let mutable attempt = 0

0 commit comments

Comments
 (0)