@@ -25,10 +25,10 @@ Describe $CommandName -Tag IntegrationTests {
2525 # We want to run all commands in the BeforeAll block with EnableException to ensure that the test fails if the setup fails.
2626 $PSDefaultParameterValues [" *-Dba*:EnableException" ] = $true
2727
28- $computerName = Resolve-DbaComputerName - ComputerName $TestConfig.InstanceSingle - Property ComputerName
28+ $computerName = Resolve-DbaComputerName - ComputerName $TestConfig.InstanceRestart - Property ComputerName
2929
3030 # Setup xp_cmdshell to create external processes for testing
31- $null = Invoke-DbaQuery - SqlInstance $TestConfig.InstanceSingle - Query "
31+ $null = Invoke-DbaQuery - SqlInstance $TestConfig.InstanceRestart - Query "
3232 -- To allow advanced options to be changed.
3333 EXECUTE sp_configure 'show advanced options', 1;
3434 GO
@@ -47,7 +47,7 @@ Describe $CommandName -Tag IntegrationTests {
4747 Set-Content - Path $sqlFile - Value " xp_cmdshell 'powershell -command "" sleep 5"" '"
4848
4949 # Run sql file to start external process
50- Start-Process - FilePath sqlcmd - ArgumentList " -S $ ( $TestConfig.InstanceSingle ) -i $sqlFile " - NoNewWindow - RedirectStandardOutput null
50+ Start-Process - FilePath sqlcmd - ArgumentList " -S $ ( $TestConfig.InstanceRestart ) -i $sqlFile " - NoNewWindow - RedirectStandardOutput null
5151
5252 # We want to run all commands outside of the BeforeAll block without EnableException to be able to test for specific warnings.
5353 $PSDefaultParameterValues.Remove (" *-Dba*:EnableException" )
@@ -58,7 +58,7 @@ Describe $CommandName -Tag IntegrationTests {
5858 $PSDefaultParameterValues [" *-Dba*:EnableException" ] = $true
5959
6060 # Cleanup: Disable xp_cmdshell for security
61- $null = Invoke-DbaQuery - SqlInstance $TestConfig.InstanceSingle - Query "
61+ $null = Invoke-DbaQuery - SqlInstance $TestConfig.InstanceRestart - Query "
6262 EXECUTE sp_configure 'xp_cmdshell', 0;
6363 GO
6464 RECONFIGURE;
@@ -68,17 +68,20 @@ Describe $CommandName -Tag IntegrationTests {
6868 RECONFIGURE;
6969 GO"
7070
71- # remove sql file
71+ # Restart the SQL Service to ensure we can remove the temporary file.
72+ $null = Restart-DbaService - ComputerName $TestConfig.InstanceRestart - Type Engine - Force
7273 Remove-Item - Path $sqlFile
7374
7475 $PSDefaultParameterValues.Remove (" *-Dba*:EnableException" )
7576 }
7677
7778 Context " Can get an external process" {
7879 It " returns a process" {
79- Start-Sleep - Seconds 1
80- $results = Get-DbaExternalProcess - ComputerName $computerName | Where-Object Name -eq " cmd.exe"
81- Start-Sleep - Seconds 5
80+ 1 .. 10 | ForEach-Object {
81+ $results = Get-DbaExternalProcess - ComputerName $computerName
82+ if ($results ) { break }
83+ Start-Sleep - Milliseconds 500
84+ }
8285 $results.ComputerName | Should - Be $computerName
8386 $results.Name | Should - Be " cmd.exe"
8487 $results.ProcessId | Should -Not - Be $null
0 commit comments