Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .github/workflows/cloud-human-confidence.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ on:
- cron: '50 6 * * *'
pull_request:
branches: [main, rc]
# The example and its tests, the files they import, and the files the
# install step uses.
paths:
- 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/humanconfidence_web/**'
- 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/example_utils.py'
- 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/conftest.py'
- 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/live_cloud.py'
- 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_cloud_humanconfidence_web.py'
- 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/pyproject.toml'
- 'ci/write-package-versions.ps1'
- 'ci/packages.ps1'
- 'ci/packages.json'
- '.github/workflows/cloud-human-confidence.yml'

permissions:
Expand Down Expand Up @@ -110,17 +118,18 @@ jobs:
Remove-Item $report -ErrorAction SilentlyContinue
python -m pytest -m staging -p no:cacheprovider -v -rs `
"--junit-xml=$report"
# pytest exits 5 when it selects no test.
if ($LASTEXITCODE -eq 5) {
Write-Host '::error::No staging test ran.'
exit 1
}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
if (-not (Test-Path $report)) {
Write-Host '::error::The staging tests did not run.'
exit 1
}
$suite = ([xml](Get-Content -Raw $report)).SelectSingleNode(
'//testsuite')
if ([int]$suite.tests -eq 0) {
Write-Host '::error::No staging test ran.'
exit 1
}
if ([int]$suite.skipped -gt 0) {
foreach ($skipped in $suite.SelectNodes('testcase[skipped]')) {
Write-Host ("::error::$($skipped.name) skipped, so it proved " +
Expand Down
47 changes: 42 additions & 5 deletions ci/key-names.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ foreach ($asset in $Assets) { Set-Content -LiteralPath "assets/$asset" '' }

# Runs the Cloud Human Confidence workflow's test step in its own process
# and folder, with the names given set and no others, and python replaced
# by a function that writes $Report as the junit report. Gives the exit
# code and the output.
function Invoke-StagingStep([hashtable]$Names, [string]$Report) {
# by a function that writes $Report as the junit report and exits with
# $PytestExitCode. Gives the step's exit code and the output.
function Invoke-StagingStep([hashtable]$Names, [string]$Report,
[int]$PytestExitCode = 0) {
$folder = Join-Path $TestDrive ([Guid]::NewGuid().ToString())
$null = New-Item -ItemType Directory $folder
$stepFile = Join-Path $folder 'step.ps1'
Expand All @@ -116,7 +117,7 @@ foreach ($asset in $Assets) { Set-Content -LiteralPath "assets/$asset" '' }
' Write-Output "pytest ran"'
' $path = "$($args | Where-Object { "$_" -like "--junit-xml=*" })" -replace "^--junit-xml=", ""'
" if (`$path) { Set-Content `$path '$Report' }"
' $global:LASTEXITCODE = 0'
" `$global:LASTEXITCODE = $PytestExitCode"
'}'
)
@($python + @(Get-StepScript 'cloud-human-confidence.yml' 'Human Confidence tests against the staging cloud')) |
Expand Down Expand Up @@ -527,19 +528,55 @@ Describe 'Keys under their _51DEGREES_ names' {
$result.Output | Should -Match 'test_0 skipped'
}

# pytest exits 5 when it selects no test, and still writes the report.
It 'fail the Cloud Human Confidence step when no staging test ran' {
$result = Invoke-StagingStep $script:StagingNames (New-JunitReport 0 0)
$result = Invoke-StagingStep $script:StagingNames (New-JunitReport 0 0) 5

$result.ExitCode | Should -Not -Be 0
$result.Output | Should -Match 'pytest ran'
$result.Output | Should -Match 'No staging test ran'
}

It 'fail the Cloud Human Confidence step with pytest''s exit code when a staging test failed' {
$result = Invoke-StagingStep $script:StagingNames (New-JunitReport 2 0) 1

$result.ExitCode | Should -Be 1
$result.Output | Should -Not -Match 'No staging test ran'
}

It 'pass the Cloud Human Confidence step when every staging test ran' {
$result = Invoke-StagingStep $script:StagingNames (New-JunitReport 2 0)

$result.ExitCode | Should -Be 0
$result.Output | Should -Match 'pytest ran'
}

# The workflow runs for a pull request that changes one of its
# pull_request paths, so each path it names is a file in this
# repository.
It 'run for a pull request on files that exist, in the Cloud Human Confidence workflow' {
$lines = @(Get-Content (Join-Path $script:Root '.github/workflows/cloud-human-confidence.yml'))
$trigger = ($lines | Select-String -Pattern '^(\s*)pull_request:\s*$' |
Select-Object -First 1)
$trigger | Should -Not -BeNullOrEmpty
$indent = $trigger.Matches[0].Groups[1].Value.Length
$paths = @()
$inPaths = $false
foreach ($line in $lines | Select-Object -Skip $trigger.LineNumber) {
if (-not $line.Trim() -or $line.Trim().StartsWith('#')) { continue }
if ($line -notmatch "^\s{$($indent + 1),}") { break }
if ($line -match '^\s*paths:\s*$') { $inPaths = $true; continue }
if ($inPaths -and $line -match '^\s*-\s*[''"]?(?<path>[^''"]+?)[''"]?\s*$') {
$paths += $Matches['path']
} elseif ($inPaths) {
break
}
}
$paths | Should -Not -BeNullOrEmpty
$paths | Where-Object { $_ -notmatch '[*?\[!]' } |
Where-Object { -not (Test-Path -LiteralPath (Join-Path $script:Root $_) -PathType Leaf) } |
Should -BeNullOrEmpty
}
}

Describe 'The live cloud tests' {
Expand Down
Loading