Skip to content

Commit b087bab

Browse files
committed
Switching back to jobs
1 parent ee67416 commit b087bab

1 file changed

Lines changed: 40 additions & 24 deletions

File tree

tests/deploy.ps1.Tests.ps1

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ Describe "deploy.ps1 integration tests" -Tag $commandName, IntegrationTests {
107107
$scriptBlock = {
108108
param (
109109
$Path,
110-
$Instance,
111-
[pscredential]$Credential,
110+
$DotSource,
112111
$Database
113112
)
114-
$testResults = & $Path\deploy.ps1 -SqlInstance $Instance -Credential $Credential -Database $Database -Silent
113+
. $DotSource
114+
$testResults = & $Path\deploy.ps1 -SqlInstance $script:mssqlInstance -Credential $script:mssqlCredential -Database $Database -Silent
115115
$testResults.Successful | Should -Be $true
116116
$testResults.Scripts.Name | Should -Not -BeNullOrEmpty
117-
$testResults.SqlInstance | Should -Be $Instance
117+
$testResults.SqlInstance | Should -Be $script:mssqlInstance
118118
$testResults.Database | Should Be $Database
119119
$testResults.SourcePath | Should Be $Path
120120
$testResults.ConnectionType | Should Be 'SQLServer'
@@ -125,26 +125,42 @@ Describe "deploy.ps1 integration tests" -Tag $commandName, IntegrationTests {
125125
$testResults.EndTime | Should -Not -BeNullOrEmpty
126126
$testResults.EndTime | Should -BeGreaterOrEqual $testResults.StartTime
127127
}
128-
# Get modules
129-
$modules = Get-Module dbops, PSFramework, Pester | Select-Object -ExpandProperty Path
130-
$sessionstate = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
131-
foreach ($modulePath in $modules) {
132-
$sessionstate.ImportPSModule($modulePath)
133-
}
134-
#Create runspace pool
135-
$runspacepool = [runspacefactory]::CreateRunspacePool(1, 5, $sessionstate, $Host)
136-
$runspacepool.Open()
137-
$script:runspaces = New-Object System.Collections.ArrayList
138-
$powershell = [powershell]::Create()
139-
$params = @{
140-
Path = $workFolder
141-
Instance = $script:mssqlInstance
142-
Credential = $script:mssqlCredential
143-
Database = $newDbName
144-
}
145-
[void]$powershell.AddScript($scriptBlock).AddParameters($params)
146-
$powershell.RunspacePool = $runspacepool
147-
$powershell.Invoke()
128+
$job = Start-Job -ScriptBlock $scriptBlock -ArgumentList $workFolder, "$here\constants.ps1", $newDbName
129+
$job | Wait-Job | Receive-Job -ErrorAction Stop
130+
# # Get modules
131+
# $modules = Get-Module Pester | Select-Object -ExpandProperty Path
132+
# $sessionstate = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
133+
# foreach ($modulePath in $modules) {
134+
# $sessionstate.ImportPSModule($modulePath)
135+
# }
136+
# # Create runspace pool
137+
# $runspacepool = [runspacefactory]::CreateRunspacePool(1, 5, $sessionstate, $Host)
138+
# $runspacepool.Open()
139+
# $powershell = [powershell]::Create()
140+
# $params = @{
141+
# Path = $workFolder
142+
# Instance = $script:mssqlInstance
143+
# Credential = $script:mssqlCredential
144+
# Database = $newDbName
145+
# }
146+
# [void]$powershell.AddScript($scriptBlock).AddParameters($params)
147+
# $powershell.RunspacePool = $runspacepool
148+
# try {
149+
# $handle = $powershell.BeginInvoke()
150+
# $cycles = 0
151+
# do { Start-Sleep 1; $cycles++ } while (-not $handle.IsCompleted -and $cycles -lt 5)
152+
# if ($powershell.Streams.Error.Count -gt 0) {
153+
# throw $powershell.Streams.Error[0]
154+
# }
155+
# $powershell.EndInvoke($handle)
156+
# }
157+
# catch {
158+
# throw $_
159+
# }
160+
# finally {
161+
# $powershell.Dispose()
162+
# $runspacepool.Close()
163+
# }
148164
}
149165
}
150166
Context "$commandName whatif tests" {

0 commit comments

Comments
 (0)