-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-find-e2e-tests.ps1
More file actions
103 lines (84 loc) · 3.32 KB
/
run-find-e2e-tests.ps1
File metadata and controls
103 lines (84 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<#
.DESCRIPTION
Rudimentary script for reliably running e2e tests locally
.EXAMPLE
dotnet pwsh ./run-find-e2e-tests.ps1
(Having already run `dotnet tool restore` as a one-off prerequisite. Using the dotnet tool alleviates PowerShell execution policy issues.)
#>
$ErrorActionPreference = "Stop"
function SetupAndRunTests {
docker compose --profile aspire down
docker compose --profile grafana down
docker compose --profile aspire up -d
$procs = $null
try
{
# Build
Write-Host "Building .NET projects..."
$procs = $(
Start-Process dotnet "build" -NoNewWindow -WorkingDirectory Apps/Find/src/SUI.Find.FindApi -PassThru;
Start-Process dotnet "build" -NoNewWindow -WorkingDirectory Apps/StubCustodians/src/SUI.StubCustodians.API -PassThru;
)
$procs | Wait-Process
Write-Host "Built .NET projects ok"
# Start apps
Write-Host "Starting apps..."
$procs = $(
Start-Process func "start --port 7182" -NoNewWindow -WorkingDirectory Apps/Find/src/SUI.Find.FindApi -PassThru;
Start-Process dotnet "run --no-build" -NoNewWindow -WorkingDirectory Apps/StubCustodians/src/SUI.StubCustodians.API -PassThru;
)
# Wait for Find API to be up...
WaitForAPI -Url "http://localhost:7182/api/health" -Name "Find API"
# Run e2e tests
Write-Host "Running e2e tests..."
dotnet test Apps/Find/tests/SUI.Find.E2ETests/SUI.Find.E2ETests.csproj `
--filter "Category=E2E&Suite=Standard" `
--logger "console;verbosity=detailed" `
--logger "trx;LogFileName=e2e-test-results.trx" `
--results-directory TestResults
}
finally
{
Write-Host "Stopping child processes..."
Stop-Process $procs
$procs | Wait-Process
}
Write-Host "Done"
}
function WaitForAPI {
param (
[Parameter(Mandatory = $true)]
[string]$Url,
[Parameter(Mandatory = $true)]
[string]$Name,
[int]$TimeoutSeconds = 30,
[int]$PollIntervalMs = 250,
[string]$ExpectedValue = "Healthy"
)
Write-Host "Waiting for $Name $Url to be up..." -ForegroundColor Cyan
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$isHealthy = $false
$healthCheckError = $null
while ($stopwatch.Elapsed.TotalSeconds -lt $TimeoutSeconds) {
try {
$response = Invoke-RestMethod -Uri $Url -Method Get -ErrorAction Stop
if ($response.Value -eq $ExpectedValue) {
$isHealthy = $true
Write-Host "$Name $Url is up (Took $($stopwatch.Elapsed.TotalSeconds.ToString('F2')) seconds)" -ForegroundColor Green
break
}
}
catch {
Write-Host "$Name $Url does not yet appear to be up (timeout in $(($TimeoutSeconds - $stopwatch.Elapsed.TotalSeconds).ToString('F2')) seconds)..." -ForegroundColor Magenta
Write-Verbose "Health check attempt failed: $_"
$healthCheckError = $_
}
Start-Sleep -Milliseconds $PollIntervalMs
}
$stopwatch.Stop()
if (-not $isHealthy) {
throw "$Name $Url did not indicate healthy within $TimeoutSeconds seconds ($healthCheckError)"
}
}
# Setup and run the tests...
SetupAndRunTests