Closed
Description
I'm experimenting with parallelizing unit tests. I'd like to be able to run each test in a clean runspace so that variables set during one test don't affect other tests.
Steps to reproduce
$runspacePool = [runspacefactory]::CreateRunspacePool()
$runspacePool.Open()
$scriptblock = { $a; $a = 1 }
'first'
$powershell1 = [powershell]::Create().AddScript($scriptblock)
$powershell1.RunspacePool = $runspacePool
$powershell1.Invoke()
'second'
$powershell2 = [powershell]::Create().AddScript($scriptblock)
$powershell2.RunspacePool = $runspacePool
$powershell2.Invoke()
Expected behavior
I expected the PowerShell/RunspacePool objects to ensure that the Runspace used on each call to .Invoke() was reset prior to use.
first
second
Actual behavior
The variable set by the first PowerShell object is available to the second PowerShell object.
first
second
1
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.0-preview.688
PSEdition Core
GitCommitId v6.1.0-preview.688
OS Microsoft Windows 6.3.9600
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0