Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlServerDsc: Stop instances in integration tests #1115

Merged
merged 13 commits into from
Apr 22, 2018
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
- Changes to SqlAlwaysOnService
- Updated the integration tests to use a loopback adapter to be less intrusive
in the build worker environment.
- Minor code cleanup in integration test, fixed the scope on variable.
- Changes to SqlSetup
- Updated the integration tests to stop some services after each integration test.
This is to save memory on the AppVeyor build worker.
- Updated the integration tests to use a SQL Server 2016 Service Pack 1.
- Changes to SqlRS
- Updated the integration tests to stop the Reporting Services service after
the integration test. This is to save memory on the AppVeyor build worker.
- The helper function `Restart-ReportingServicesService` should no longer timeout
when restarting the service ([issue #1114](https://github.com/PowerShell/SqlServerDsc/issues/1114)).
- Changes to SqlServiceAccount
- Updated the integration tests to stop some services after each integration test.
This is to save memory on the AppVeyor build worker.

## 11.1.0.0

Expand Down
2 changes: 1 addition & 1 deletion DSCResources/MSFT_SqlRS/MSFT_SqlRS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ function Set-TargetResource
Invoke-RsCimMethod @invokeRsCimMethodParameters
}

Restart-ReportingServicesService -SQLInstanceName $InstanceName
Restart-ReportingServicesService -SQLInstanceName $InstanceName -WaitTime 30
}
else
{
Expand Down
31 changes: 25 additions & 6 deletions SqlServerDscHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -900,11 +900,15 @@ function Restart-SqlService

<#
.SYNOPSIS
Restarts a Reporting Services instance and associated services
Restarts a Reporting Services instance and associated services

.PARAMETER SQLInstanceName
Name of the instance to be restarted. Default is 'MSSQLSERVER'
(the default instance).
Name of the instance to be restarted. Default is 'MSSQLSERVER'
(the default instance).

.PARAMETER WaitTime
Number of seconds to wait between service stop and service start.
Defaults to 0 seconds.
#>
function Restart-ReportingServicesService
{
Expand All @@ -913,7 +917,11 @@ function Restart-ReportingServicesService
(
[Parameter()]
[System.String]
$SQLInstanceName = 'MSSQLSERVER'
$SQLInstanceName = 'MSSQLSERVER',

[Parameter()]
[System.UInt16]
$WaitTime = 0
)

$ServiceName = 'ReportServer'
Expand All @@ -935,8 +943,19 @@ function Restart-ReportingServicesService
$_.Status -eq 'Running'
}

Write-Verbose -Message ($script:localizedData.RestartService -f 'Reporting Services') -Verbose
$reportingServicesService | Restart-Service -Force
Write-Verbose -Message ($script:localizedData.RestartService -f $reportingServicesService.DisplayName) -Verbose

Write-Verbose -Message ($script:localizedData.StoppingService -f $reportingServicesService.DisplayName) -Verbose
$reportingServicesService | Stop-Service -Force

if ($WaitTime -ne 0)
{
Write-Verbose -Message ($script:localizedData.WaitServiceRestart -f $WaitTime, $reportingServicesService.DisplayName) -Verbose
Start-Sleep -Seconds $WaitTime
}

Write-Verbose -Message ($script:localizedData.StartingService -f $reportingServicesService.DisplayName) -Verbose
$reportingServicesService | Start-Service

# Start dependent services
$dependentService | ForEach-Object {
Expand Down
10 changes: 5 additions & 5 deletions Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $TestEnvironment = Initialize-TestEnvironment `

#endregion

$integrationErrorMessagePrefix = 'INTEGRATION ERROR MESSAGE:'
$script:integrationErrorMessagePrefix = 'INTEGRATION ERROR MESSAGE:'

$testRootFolderPath = Split-Path -Path $PSScriptRoot -Parent
Import-Module -Name (Join-Path -Path $testRootFolderPath -ChildPath (Join-Path -Path 'TestHelpers' -ChildPath 'CommonTestHelper.psm1')) -Force
Expand Down Expand Up @@ -84,7 +84,7 @@ try
}
catch
{
Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose
Write-Verbose -Message ('{0} {1}' -f $script:integrationErrorMessagePrefix, $_) -Verbose
throw $_
}
} | Should -Not -Throw
Expand Down Expand Up @@ -120,7 +120,7 @@ try
}
catch
{
Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose
Write-Verbose -Message ('{0} {1}' -f $script:integrationErrorMessagePrefix, $_) -Verbose
throw $_
}
} | Should -Not -Throw
Expand Down Expand Up @@ -172,7 +172,7 @@ try
}
catch
{
Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose
Write-Verbose -Message ('{0} {1}' -f $script:integrationErrorMessagePrefix, $_) -Verbose
throw $_
}
} | Should -Not -Throw
Expand Down Expand Up @@ -223,7 +223,7 @@ try
}
catch
{
Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose
Write-Verbose -Message ('{0} {1}' -f $script:integrationErrorMessagePrefix, $_) -Verbose
throw $_
}
} | Should -Not -Throw
Expand Down
77 changes: 73 additions & 4 deletions Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $TestEnvironment = Initialize-TestEnvironment `
-DSCResourceName $script:DSCResourceName `
-TestType Integration

$script:integrationErrorMessagePrefix = 'INTEGRATION ERROR MESSAGE:'
#endregion

$mockSqlInstallAccountPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
Expand Down Expand Up @@ -71,7 +72,15 @@ try
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
try
{
Start-DscConfiguration @startDscConfigurationParameters
}
catch
{
Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose
throw $_
}
} | Should -Not -Throw
}
}
Expand Down Expand Up @@ -99,7 +108,15 @@ try
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
try
{
Start-DscConfiguration @startDscConfigurationParameters
}
catch
{
Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose
throw $_
}
} | Should -Not -Throw
}

Expand Down Expand Up @@ -191,7 +208,15 @@ try
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
try
{
Start-DscConfiguration @startDscConfigurationParameters
}
catch
{
Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose
throw $_
}
} | Should -Not -Throw
}

Expand Down Expand Up @@ -247,7 +272,15 @@ try
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
try
{
Start-DscConfiguration @startDscConfigurationParameters
}
catch
{
Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose
throw $_
}
} | Should -Not -Throw
}

Expand Down Expand Up @@ -289,6 +322,42 @@ try
$webRequestStatusCode | Should -BeExactly 200
}
}

$configurationName = "$($script:DSCResourceName)_StopReportingServicesInstance_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
ConfigurationData = $ConfigurationData
}

& $configurationName @configurationParameters

$startDscConfigurationParameters = @{
Path = $TestDrive
ComputerName = 'localhost'
Wait = $true
Verbose = $true
Force = $true
ErrorAction = 'Stop'
}

try
{
Start-DscConfiguration @startDscConfigurationParameters
}
catch
{
Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose
throw $_
}
} | Should -Not -Throw
}
}

}
}
finally
Expand Down
14 changes: 14 additions & 0 deletions Tests/Integration/MSFT_SqlRS.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,17 @@ Configuration MSFT_SqlRS_InstallReportingServices_RestoreToNoSsl_Config
}
}
}

Configuration MSFT_SqlRS_StopReportingServicesInstance_Config
{
Import-DscResource -ModuleName 'PSDscResources'

node localhost
{
Service ('StopReportingServicesInstance{0}' -f $Node.InstanceName)
{
Name = ('ReportServer${0}' -f $Node.InstanceName)
State = 'Stopped'
}
}
}
Loading