Skip to content

Commit e80871c

Browse files
authored
Makes test script more resilient to aborts (#118)
1 parent 2674fac commit e80871c

File tree

1 file changed

+62
-34
lines changed

1 file changed

+62
-34
lines changed

tests.ps1

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ $FirebirdConfiguration = @{
3232
$testsBaseDir = "$baseDir\src\FirebirdSql.Data.FirebirdClient.Tests"
3333
$testsProviderDir = "$testsBaseDir\bin\$Configuration\$(Get-UsedTargetFramework)"
3434

35-
$startDir = $null
3635
$firebirdProcess = $null
3736

3837
if ($env:tests_firebird_dir) {
@@ -45,44 +44,53 @@ else {
4544
function Prepare() {
4645
echo "=== $($MyInvocation.MyCommand.Name) ==="
4746

48-
$script:startDir = $pwd
4947
$selectedConfiguration = $FirebirdConfiguration[$FirebirdSelection]
5048
$fbDownload = $selectedConfiguration.Download
5149
$fbDownloadName = $fbDownload -Replace '.+/(.+)$','$1'
5250
if (Test-Path $firebirdDir) {
5351
rm -Force -Recurse $firebirdDir
5452
}
5553
mkdir $firebirdDir | Out-Null
56-
cd $firebirdDir
57-
echo "Downloading $fbDownload"
58-
Invoke-RestMethod -Uri $fbDownload -OutFile $fbDownloadName
59-
echo "Extracting $fbDownloadName"
60-
7z x -bsp0 -bso0 $fbDownloadName
61-
rm $fbDownloadName
62-
cp -Recurse -Force .\* $testsProviderDir
6354

64-
ni firebird.log -ItemType File | Out-Null
55+
pushd $firebirdDir
56+
try {
57+
echo "Downloading $fbDownload"
58+
Invoke-RestMethod -Uri $fbDownload -OutFile $fbDownloadName
59+
echo "Extracting $fbDownloadName"
60+
7z x -bsp0 -bso0 $fbDownloadName
61+
rm $fbDownloadName
62+
cp -Recurse -Force .\* $testsProviderDir
6563

66-
echo "Starting Firebird"
67-
$process = Start-Process -FilePath $selectedConfiguration.Executable -ArgumentList $selectedConfiguration.Args -PassThru
68-
echo "Version: $($process.MainModule.FileVersionInfo.FileVersion)"
69-
$script:firebirdProcess = $process
64+
ni firebird.log -ItemType File | Out-Null
7065

71-
echo "=== END ==="
66+
echo "Starting Firebird"
67+
$process = Start-Process -FilePath $selectedConfiguration.Executable -ArgumentList $selectedConfiguration.Args -PassThru
68+
echo "Version: $($process.MainModule.FileVersionInfo.FileVersion)"
69+
$script:firebirdProcess = $process
70+
71+
echo "=== END ==="
72+
}
73+
finally {
74+
popd
75+
}
7276
}
7377

7478
function Cleanup() {
75-
echo "=== $($MyInvocation.MyCommand.Name) ==="
79+
# Do not write to output (Write-Output, echo) here. Write-Host is ok.
80+
# -- https://stackoverflow.com/a/45105609
81+
82+
Write-Host "=== $($MyInvocation.MyCommand.Name) ==="
7683

77-
cd $script:startDir
7884
$process = $script:firebirdProcess
79-
$process.Kill()
80-
$process.WaitForExit()
81-
# give OS time to release all files
82-
sleep -Milliseconds 100
85+
if ($process) {
86+
$process.Kill()
87+
$process.WaitForExit()
88+
# give OS time to release all files
89+
sleep -Milliseconds 100
90+
}
8391
rm -Force -Recurse $firebirdDir
8492

85-
echo "=== END ==="
93+
Write-Host "=== END ==="
8694
}
8795

8896
function Tests-All() {
@@ -112,26 +120,46 @@ function Tests-FirebirdClient-Embedded() {
112120
Tests-FirebirdClient 'Embedded' $False 'Disabled'
113121
}
114122
function Tests-FirebirdClient($serverType, $compression, $wireCrypt) {
115-
cd $testsProviderDir
116-
.\FirebirdSql.Data.FirebirdClient.Tests.exe --labels=All "--where=(ServerType==$serverType && Compression==$compression && WireCrypt==$wireCrypt) || Category==NoServer"
117-
Check-ExitCode
123+
pushd $testsProviderDir
124+
try {
125+
.\FirebirdSql.Data.FirebirdClient.Tests.exe --labels=All "--where=(ServerType==$serverType && Compression==$compression && WireCrypt==$wireCrypt) || Category==NoServer"
126+
Check-ExitCode
127+
}
128+
finally {
129+
popd
130+
}
118131
}
119132

120133
function Tests-EF6() {
121-
cd "$baseDir\src\EntityFramework.Firebird.Tests\bin\$Configuration\$(Get-UsedTargetFramework)"
122-
.\EntityFramework.Firebird.Tests.exe --labels=All
123-
Check-ExitCode
134+
pushd "$baseDir\src\EntityFramework.Firebird.Tests\bin\$Configuration\$(Get-UsedTargetFramework)"
135+
try {
136+
.\EntityFramework.Firebird.Tests.exe --labels=All
137+
Check-ExitCode
138+
}
139+
finally {
140+
popd
141+
}
124142
}
125143

126144
function Tests-EFCore() {
127-
cd "$baseDir\src\FirebirdSql.EntityFrameworkCore.Firebird.Tests\bin\$Configuration\$(Get-UsedTargetFramework)"
128-
.\FirebirdSql.EntityFrameworkCore.Firebird.Tests.exe --labels=All
129-
Check-ExitCode
145+
pushd "$baseDir\src\FirebirdSql.EntityFrameworkCore.Firebird.Tests\bin\$Configuration\$(Get-UsedTargetFramework)"
146+
try {
147+
.\FirebirdSql.EntityFrameworkCore.Firebird.Tests.exe --labels=All
148+
Check-ExitCode
149+
}
150+
finally {
151+
popd
152+
}
130153
}
131154
function Tests-EFCore-Functional() {
132-
cd "$baseDir\src\FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests"
133-
dotnet test --no-build -c $Configuration
134-
Check-ExitCode
155+
pushd "$baseDir\src\FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests"
156+
try {
157+
dotnet test --no-build -c $Configuration
158+
Check-ExitCode
159+
}
160+
finally {
161+
popd
162+
}
135163
}
136164

137165
try {

0 commit comments

Comments
 (0)