Skip to content

Commit a1f25f2

Browse files
Use new AppVeyor image to test against SQL Server 2022 (#10101)
1 parent 6f62467 commit a1f25f2

10 files changed

Lines changed: 516 additions & 50 deletions

appveyor.yml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# See http://www.appveyor.com/docs/appveyor-yml for many more options
2-
image: Previous Visual Studio 2015
2+
image: Previous Visual Studio 2022
33
configuration: "Debug"
44

55
# skip PR builds when there's already a push build
@@ -49,22 +49,43 @@ environment:
4949
matrix:
5050
- scenario: SINGLE
5151
part: 1/3
52-
setup_scripts: \tests\appveyor.SQL2016.ps1
52+
InstanceSingle: sql2022
5353
- scenario: SINGLE
5454
part: 2/3
55-
setup_scripts: \tests\appveyor.SQL2016.ps1
55+
InstanceSingle: sql2022
5656
- scenario: SINGLE
5757
part: 3/3
58-
setup_scripts: \tests\appveyor.SQL2016.ps1
58+
InstanceSingle: sql2022
5959
- scenario: MULTI
60-
setup_scripts: \tests\appveyor.SQL2017.ps1,\tests\appveyor.SQL2016.ps1
60+
InstanceMulti1: sql2022
61+
InstanceMulti2: sql2017
6162
- scenario: COPY
62-
setup_scripts: \tests\appveyor.SQL2017.ps1,\tests\appveyor.SQL2016.ps1
63+
InstanceCopy1: sql2017
64+
InstanceCopy2: sql2022
6365
- scenario: HADR
64-
setup_scripts: \tests\appveyor.SQL2017.ps1
66+
InstanceHadr: sql2022
6567
- scenario: RESTART
66-
setup_scripts: \tests\appveyor.SQL2017.ps1
68+
InstanceRestart: sql2022
6769
- scenario: default
70+
- scenario: 2008R2SP2Express
71+
part: 1/2
72+
InstanceSingle: sql2008r2sp2
73+
InstanceMulti1: sql2008r2sp2
74+
InstanceMulti2: sql2017
75+
InstanceCopy1: sql2008r2sp2
76+
InstanceCopy2: sql2017
77+
InstanceRestart: sql2008r2sp2
78+
APPVEYOR_BUILD_WORKER_IMAGE: Previous Visual Studio 2015
79+
- scenario: 2008R2SP2Express
80+
part: 2/2
81+
InstanceSingle: sql2008r2sp2
82+
InstanceMulti1: sql2008r2sp2
83+
InstanceMulti2: sql2017
84+
InstanceCopy1: sql2008r2sp2
85+
InstanceCopy2: sql2017
86+
InstanceHadr: sql2017
87+
InstanceRestart: sql2008r2sp2
88+
APPVEYOR_BUILD_WORKER_IMAGE: Previous Visual Studio 2015
6889

6990
# Set alternative clone folder
7091
clone_folder: c:\github\dbatools

private/testing/Get-TestConfig.ps1

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,43 @@ function Get-TestConfig {
2121

2222
if (Test-Path $LocalConfigPath) {
2323
. $LocalConfigPath
24+
} elseif ($env:AppVeyor) {
25+
Write-Host -Object "Get-TestConfig: Setting up test configuration for AppVeyor" -ForegroundColor DarkGreen
26+
27+
if ($env:InstanceSingle) {
28+
$config['InstanceSingle'] = "$(hostname)\$($env:InstanceSingle)"
29+
}
30+
if ($env:InstanceMulti1) {
31+
$config['InstanceMulti1'] = "$(hostname)\$($env:InstanceMulti1)"
32+
}
33+
if ($env:InstanceMulti2) {
34+
$config['InstanceMulti2'] = "$(hostname)\$($env:InstanceMulti2)"
35+
}
36+
if ($env:InstanceCopy1) {
37+
$config['InstanceCopy1'] = "$(hostname)\$($env:InstanceCopy1)"
38+
}
39+
if ($env:InstanceCopy2) {
40+
$config['InstanceCopy2'] = "$(hostname)\$($env:InstanceCopy2)"
41+
}
42+
if ($env:InstanceHadr) {
43+
$config['InstanceHadr'] = "$(hostname)\$($env:InstanceHadr)"
44+
}
45+
if ($env:InstanceRestart) {
46+
$config['InstanceRestart'] = "$(hostname)\$($env:InstanceRestart)"
47+
}
48+
49+
$config['SQLUserName'] = $null # placeholders for -SqlCredential testing
50+
$config['SQLPassword'] = $null
51+
52+
$config['AppveyorLabRepo'] = "C:\github\appveyor-lab"
53+
54+
$config['AzureBlob'] = "https://dbatools.blob.core.windows.net/sql"
55+
$config['AzureBlobAccount'] = "dbatools"
56+
$config['AzureServer'] = 'psdbatools.database.windows.net'
57+
$config['AzureSqlDbLogin'] = "appveyor@clemairegmail.onmicrosoft.com"
58+
59+
$config['BigDatabaseBackup'] = 'C:\github\StackOverflowMini.bak'
60+
$config['BigDatabaseBackupSourceUrl'] = 'https://github.com/BrentOzarULTD/Stack-Overflow-Database/releases/download/20230114/StackOverflowMini.bak'
2461
} elseif ($env:CODESPACES -or ($env:TERM_PROGRAM -eq 'vscode' -and $env:REMOTE_CONTAINERS)) {
2562
$null = Set-DbatoolsInsecureConnection
2663

@@ -46,30 +83,6 @@ function Get-TestConfig {
4683
$config['AzureBlobAccount'] = "dbatools"
4784
$config['AzureServer'] = 'psdbatools.database.windows.net'
4885
$config['AzureSqlDbLogin'] = "appveyor@clemairegmail.onmicrosoft.com"
49-
} else {
50-
# This configuration is used for the automated test on AppVeyor
51-
$config['DbaToolsCi_Computer'] = "$(hostname)"
52-
53-
$config['InstanceSingle'] = "$(hostname)\sql2016"
54-
$config['InstanceMulti1'] = "$(hostname)\sql2016"
55-
$config['InstanceMulti2'] = "$(hostname)\sql2017"
56-
$config['InstanceCopy1'] = "$(hostname)\sql2016"
57-
$config['InstanceCopy2'] = "$(hostname)\sql2017"
58-
$config['InstanceHadr'] = "$(hostname)\sql2017"
59-
$config['InstanceRestart'] = "$(hostname)\sql2017"
60-
61-
$config['SQLUserName'] = $null # placeholders for -SqlCredential testing
62-
$config['SQLPassword'] = $null
63-
64-
$config['AppveyorLabRepo'] = "C:\github\appveyor-lab"
65-
66-
$config['AzureBlob'] = "https://dbatools.blob.core.windows.net/sql"
67-
$config['AzureBlobAccount'] = "dbatools"
68-
$config['AzureServer'] = 'psdbatools.database.windows.net'
69-
$config['AzureSqlDbLogin'] = "appveyor@clemairegmail.onmicrosoft.com"
70-
71-
$config['BigDatabaseBackup'] = 'C:\github\StackOverflowMini.bak'
72-
$config['BigDatabaseBackupSourceUrl'] = 'https://github.com/BrentOzarULTD/Stack-Overflow-Database/releases/download/20230114/StackOverflowMini.bak'
7386
}
7487

7588
[pscustomobject]$config

tests/appveyor.SQL2017.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
$indent = '...'
22
Write-Host -Object "$indent Running $PSCommandPath" -ForegroundColor DarkGreen
33

4-
# This script spins up the 2016 instance and the relative setup
4+
# This script spins up the 2017 instance and the relative setup
55

66
$sqlinstance = "localhost\SQL2017"
77
$instance = "SQL2017"
88
$port = "14334"
99

10-
Write-Host -Object "$indent Setting up AppVeyor Services" -ForegroundColor DarkGreen
11-
Set-Service -Name SQLBrowser -StartupType Automatic
12-
Set-Service -Name "SQLAgent`$$instance" -StartupType Automatic
13-
Start-Service -Name SQLBrowser -ErrorAction SilentlyContinue
14-
1510
Write-Host -Object "$indent Changing the port on $instance to $port" -ForegroundColor DarkGreen
1611
$null = Set-DbaNetworkConfiguration -SqlInstance $sqlinstance -StaticPortForIPAll $port -EnableException -Confirm:$false -WarningAction SilentlyContinue
1712

1813
Write-Host -Object "$indent Starting $instance" -ForegroundColor DarkGreen
19-
Restart-Service "MSSQL`$$instance" -Force
20-
Restart-Service "SQLAgent`$$instance" -Force
14+
Start-Service -Name "MSSQL`$$instance" -WarningAction SilentlyContinue
15+
Start-Service -Name "SQLAgent`$$instance" -WarningAction SilentlyContinue
2116

2217
Write-Host -Object "$indent Configuring $instance" -ForegroundColor DarkGreen
2318
$null = Set-DbaSpConfigure -SqlInstance $sqlinstance -Name ExtensibleKeyManagementEnabled -Value $true -EnableException
2419
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CRYPTOGRAPHIC PROVIDER dbatoolsci_AKV FROM FILE = 'C:\github\appveyor-lab\keytests\ekm\Microsoft.AzureKeyVaultService.EKM.dll'" -EnableException
25-
$null = Enable-DbaAgHadr -SqlInstance $sqlinstance -Force -EnableException -Confirm:$false
2620
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<StrongPassword>'" -EnableException
27-
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CERTIFICATE dbatoolsci_AGCert WITH SUBJECT = 'AG Certificate'" -EnableException
21+
22+
$loginName = "$env:COMPUTERNAME\$env:USERNAME"
23+
$login = Get-DbaLogin -SqlInstance $sqlinstance -Login $loginName
24+
if (-not $login) {
25+
Write-Host -Object "$indent Creating login $env:COMPUTERNAME\$env:USERNAME on $instance" -ForegroundColor DarkGreen
26+
$null = New-DbaLogin -SqlInstance $sqlinstance -Name $loginName -EnableException
27+
}

tests/appveyor.SQL2019.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$indent = '...'
2+
Write-Host -Object "$indent Running $PSCommandPath" -ForegroundColor DarkGreen
3+
4+
# This script spins up the 2019 instance and the relative setup
5+
6+
$sqlinstance = "localhost\SQL2019"
7+
$instance = "SQL2019"
8+
$port = "14335"
9+
10+
Write-Host -Object "$indent Changing the port on $instance to $port" -ForegroundColor DarkGreen
11+
$null = Set-DbaNetworkConfiguration -SqlInstance $sqlinstance -StaticPortForIPAll $port -EnableException -Confirm:$false -WarningAction SilentlyContinue
12+
13+
Write-Host -Object "$indent Starting $instance" -ForegroundColor DarkGreen
14+
Start-Service -Name "MSSQL`$$instance" -WarningAction SilentlyContinue
15+
Start-Service -Name "SQLAgent`$$instance" -WarningAction SilentlyContinue
16+
17+
Write-Host -Object "$indent Configuring $instance" -ForegroundColor DarkGreen
18+
$null = Set-DbaSpConfigure -SqlInstance $sqlinstance -Name ExtensibleKeyManagementEnabled -Value $true -EnableException
19+
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CRYPTOGRAPHIC PROVIDER dbatoolsci_AKV FROM FILE = 'C:\github\appveyor-lab\keytests\ekm\Microsoft.AzureKeyVaultService.EKM.dll'" -EnableException
20+
$null = Enable-DbaAgHadr -SqlInstance $sqlinstance -Force -EnableException -Confirm:$false
21+
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<StrongPassword>'" -EnableException
22+
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CERTIFICATE dbatoolsci_AGCert WITH SUBJECT = 'AG Certificate'" -EnableException
23+
24+
$loginName = "$env:COMPUTERNAME\$env:USERNAME"
25+
$login = Get-DbaLogin -SqlInstance $sqlinstance -Login $loginName
26+
if (-not $login) {
27+
Write-Host -Object "$indent Creating login $env:COMPUTERNAME\$env:USERNAME on $instance" -ForegroundColor DarkGreen
28+
$null = New-DbaLogin -SqlInstance $sqlinstance -Name $loginName -EnableException
29+
}

tests/appveyor.SQL2022.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$indent = '...'
2+
Write-Host -Object "$indent Running $PSCommandPath" -ForegroundColor DarkGreen
3+
4+
# This script spins up the 2022 instance and the relative setup
5+
6+
$sqlinstance = "localhost\SQL2022"
7+
$instance = "SQL2022"
8+
$port = "14336"
9+
10+
Write-Host -Object "$indent Changing the port on $instance to $port" -ForegroundColor DarkGreen
11+
$null = Set-DbaNetworkConfiguration -SqlInstance $sqlinstance -StaticPortForIPAll $port -EnableException -Confirm:$false -WarningAction SilentlyContinue
12+
13+
Write-Host -Object "$indent Starting $instance" -ForegroundColor DarkGreen
14+
Start-Service -Name "MSSQL`$$instance" -WarningAction SilentlyContinue
15+
Start-Service -Name "SQLAgent`$$instance" -WarningAction SilentlyContinue
16+
17+
Write-Host -Object "$indent Configuring $instance" -ForegroundColor DarkGreen
18+
$null = Set-DbaSpConfigure -SqlInstance $sqlinstance -Name ExtensibleKeyManagementEnabled -Value $true -EnableException
19+
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CRYPTOGRAPHIC PROVIDER dbatoolsci_AKV FROM FILE = 'C:\github\appveyor-lab\keytests\ekm\Microsoft.AzureKeyVaultService.EKM.dll'" -EnableException
20+
$null = Enable-DbaAgHadr -SqlInstance $sqlinstance -Force -EnableException -Confirm:$false
21+
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<StrongPassword>'" -EnableException
22+
Invoke-DbaQuery -SqlInstance $sqlinstance -Query "CREATE CERTIFICATE dbatoolsci_AGCert WITH SUBJECT = 'AG Certificate'" -EnableException
23+
24+
$loginName = "$env:COMPUTERNAME\$env:USERNAME"
25+
$login = Get-DbaLogin -SqlInstance $sqlinstance -Login $loginName
26+
if (-not $login) {
27+
Write-Host -Object "$indent Creating login $env:COMPUTERNAME\$env:USERNAME on $instance" -ForegroundColor DarkGreen
28+
$null = New-DbaLogin -SqlInstance $sqlinstance -Name $loginName -EnableException
29+
}

tests/appveyor.common.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ function Get-TestsForScenario {
33

44
# does this scenario run an 'autodetect' ?
55
if ($TestsRunGroups[$Scenario].StartsWith('autodetect_')[0]) {
6-
# exclude any test specifically tied to a non-autodetect scenario
7-
$TiedFunctions = ($TestsRunGroups.GetEnumerator() | Where-Object { $_.Value -notlike 'autodetect_*' }).Value
6+
# exclude any test specifically tied to a non-autodetect or version specific scenario
7+
$TiedFunctions = ($TestsRunGroups.GetEnumerator() | Where-Object { $_.Value -notlike 'autodetect_*' -and $_.Name -notlike '20*' }).Value
88
$RemainingTests = $AllTests | Where-Object { ($_.Name -replace '^([^.]+)(.+)?.Tests.ps1', '$1') -notin $TiedFunctions }
99
# and now scan for the instance string
1010
$ScanFor = $TestsRunGroups[$Scenario].Replace('autodetect_', '')

tests/appveyor.pester.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,15 @@ if (-not $Finalize) {
446446
}
447447
$errorMessageDetail = $failedTestsList -join " | "
448448

449-
Update-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome "Failed" -Duration $PesterRun.Duration.TotalMilliseconds -ErrorMessage $errorMessageDetail
449+
if ($trialNo -le 3) {
450+
Write-Host -Object "appveyor.pester: Test failed with $($PesterRun.FailedCount) failed tests. Retrying (attempt $trialNo of 3)..." -ForegroundColor Yellow
451+
# Restarting all used instances to avoid state issues
452+
$null = Get-DbaService -Type Engine | Where-Object State -eq 'Running' | Restart-DbaService -Force -Confirm:$false
453+
Start-Sleep -Seconds 10
454+
} else {
455+
Write-Host -Object "appveyor.pester: Test failed with $($PesterRun.FailedCount) failed tests. No more retries left." -ForegroundColor Red
456+
Update-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome "Failed" -Duration $PesterRun.Duration.TotalMilliseconds -ErrorMessage $errorMessageDetail
457+
}
450458

451459
# Add to summary
452460
$allTestsSummary.TestRuns += @{

tests/appveyor.prep.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,21 @@ Install-Module -Name Pester -Force -SkipPublisherCheck -RequiredVersion 5.7.1
5555
Write-Host -Object "appveyor.prep: Create Path.DbatoolsExport" -ForegroundColor DarkGreen
5656
$null = New-Item -Path C:\Users\appveyor\Documents\DbatoolsExport -ItemType Directory
5757

58-
Write-Host -Object "Creating temp directory" -ForegroundColor DarkGreen
58+
Write-Host -Object "appveyor.prep: Creating temp directory" -ForegroundColor DarkGreen
5959
$null = New-Item -Path C:\Temp -ItemType Directory
6060

61+
Write-Host -Object "appveyor.prep: Configuring WSMan (see #9782)" -ForegroundColor DarkGreen
62+
$null = Set-WSManQuickConfig -Force
63+
6164
Write-Host -Object "appveyor.prep: Trust SQL Server Cert (now required)" -ForegroundColor DarkGreen
6265
Import-Module dbatools.library
6366
Import-Module C:\github\dbatools\dbatools.psd1
6467
Set-DbatoolsConfig -FullName sql.connection.trustcert -Value $true -Register
6568
Set-DbatoolsConfig -FullName sql.connection.encrypt -Value $false -Register
69+
70+
Write-Host -Object "appveyor.prep: Setting up SQL Server Browser" -ForegroundColor DarkGreen
71+
Set-Service -Name SQLBrowser -StartupType Automatic
72+
Start-Service -Name SQLBrowser
73+
6674
$sw.Stop()
6775
Update-AppveyorTest -Name "appveyor.prep" -Framework NUnit -FileName "appveyor.prep.ps1" -Outcome Passed -Duration $sw.ElapsedMilliseconds

tests/appveyor.sqlserver.ps1

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
1-
if ($env:SETUP_SCRIPTS) {
2-
Write-Host -Object "Scenario $($env:SCENARIO)" -ForegroundColor DarkGreen
3-
$Setup_Scripts = $env:SETUP_SCRIPTS.split(',').Trim()
4-
foreach ($Setup_Script in $Setup_Scripts) {
1+
Write-Host -Object "appveyor.sqlserver: Setting up instances for scenario $($env:SCENARIO)" -ForegroundColor DarkGreen
2+
$instances = @( )
3+
if ($env:InstanceSingle) {
4+
$instances += $env:InstanceSingle
5+
}
6+
if ($env:InstanceMulti1) {
7+
$instances += $env:InstanceMulti1
8+
}
9+
if ($env:InstanceMulti2) {
10+
$instances += $env:InstanceMulti2
11+
}
12+
if ($env:InstanceCopy1) {
13+
$instances += $env:InstanceCopy1
14+
}
15+
if ($env:InstanceCopy2) {
16+
$instances += $env:InstanceCopy2
17+
}
18+
if ($env:InstanceHadr) {
19+
$instances += $env:InstanceHadr
20+
}
21+
if ($env:InstanceRestart) {
22+
$instances += $env:InstanceRestart
23+
}
24+
if ($instances) {
25+
$instances = $instances | Sort-Object -Unique
26+
foreach ($instance in $instances) {
27+
$Setup_Script = "tests\appveyor.$($instance).ps1"
28+
Write-Host -Object "appveyor.sqlserver: Running setup script $Setup_Script for instance $instance" -ForegroundColor DarkGreen
529
$SetupScriptPath = Join-Path $env:APPVEYOR_BUILD_FOLDER $Setup_Script
630
Add-AppveyorTest -Name $Setup_Script -Framework NUnit -FileName $Setup_Script -Outcome Running
731
$sw = [system.diagnostics.stopwatch]::startNew()
832
. $SetupScriptPath
933
$sw.Stop()
1034
Update-AppveyorTest -Name $Setup_Script -Framework NUnit -FileName $Setup_Script -Outcome Passed -Duration $sw.ElapsedMilliseconds
1135
}
36+
} else {
37+
Write-Host -Object "appveyor.sqlserver: No instances needed" -ForegroundColor DarkGreen
1238
}

0 commit comments

Comments
 (0)