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

Running pester tests using dbatools powershell module causes Pester extension to always timeout #498

Closed
hintbw opened this issue May 30, 2019 · 7 comments
Assignees
Labels

Comments

@hintbw
Copy link

hintbw commented May 30, 2019

Azure DevOps Extension you are using

There are a number of Azure DevOps (VSTS) extension in this repo so please say which one you are using, and if an extension contains multiple tasks which task also

Pester Extension

Where are you running it?

You can run the extensions in the cloud or on-premise

  • Azure DevOps Service (VSTS)
  • Azure DevOps Server (on-premise TFS, if so what version)

Azure DevOps Service

Version of Extension/Task

I assume it is the currently public version, if you are using an older version on-premises let me know, but the answer will probably involve upgrading to the currently public version

Current Public Version

Expected behaviour and actual behaviour

With a simple pester test that runs the following thing in setup in a BeforeAll

Install-Module dbatools -SkipPublisherCheck -AcceptLicense -Verbose -Force -Scope CurrentUser -AllowClobber

Then runs a simple test something like It "test 1" { $true | Should -Be $true } and the extension will timeout and never return

Actual behavior should be that it returns from the extension with the results instead of timing out

We like using your extension but we use dbatools in a number of our scripts and modules and we are unable to use it whenever we have tests for scripts that use dbatools. In order to be able to run tests we have to switch over to using a powershell task and just run a pester-bootstrap script ourselves.

Steps to reproduce the problem

Pester test file like:

Describe "test file for importing dbatools module" {
BeforeAll{
Install-Module dbatools -SkipPublisherCheck -AcceptLicense -Verbose -Force -Scope CurrentUser -AllowClobber
}
It "test 1" {
$true | Should -Be $true
}

}

@ChrisLGardner ChrisLGardner self-assigned this May 30, 2019
@ChrisLGardner
Copy link
Collaborator

I'll have a look at this over the weekend, I'm surprised that's happening unless it's hanging on installing dbatools for some reason.

My usual approach for installing dependencies is to do it all in their own step near the start of the build so that might be better approach to take if I can't resolve this directly.

@hintbw
Copy link
Author

hintbw commented May 31, 2019

@ChrisLGardner - I probably should have left the module install out as it really isn't essential. I could simplify it to assuming the module has already been installed and have a pester test as follows:

Describe "Test dbatools" -Tag "dbatools" {
#Requires -module dbatools

}

I do have it publishing code coverage in case that matters (I don't believe it does). But it will just run until timeout with the above pester test in our Azure Pipeline with only one task ahead of it that simply runs an inline powershell task with the following
Install-Module dbatools -SkipPublisherCheck -AcceptLicense -Verbose -Force -Scope CurrentUser -AllowClobber

@ChrisLGardner
Copy link
Collaborator

If you're using #Requires then I'd make sure you have it outside the the Describe block. You can put them anywhere in a file as long as it's not inside a function, I've never tried doing in a scriptblock so I'm not sure how that works. I'd give it a try outside of that to see if that make a difference.

I'll do some more digging at the weekend and see what I can find.

@hintbw hintbw changed the title Running pester tests using dbatools module causes Pester extension to always timeout Running pester tests requiring some powershell modules causes Pester extension to always timeout May 31, 2019
@hintbw
Copy link
Author

hintbw commented May 31, 2019

@ChrisLGardner - sounds good. I appreciate it.

The test case I'm trying to highlight is that if certain modules, like dbatools are used in tests, even when no commands on the module are even executed, but they are just imported into the powershell session, then the extension will hang and timeout. In my example above you can swap the requires statement to just use an import-module dbatools for example without any commands and the pester extension hangs.

I was just trying to get to a really simple reproducible scenario you could use.

@hintbw hintbw changed the title Running pester tests requiring some powershell modules causes Pester extension to always timeout Running pester tests using dbatools powershell module causes Pester extension to always timeout May 31, 2019
@hintbw
Copy link
Author

hintbw commented May 31, 2019

I thought it might happen with the sqlserver module from Microsoft as well, but in the tests that I ran using the #requires was causing things to hang, but when I tried just the import-module, only dbatools continued to hang the extension.

@jdholbrook81
Copy link

Believe I'm running into a similar issue with the PSScriptAnalyzer module. The module is installed, all my tests run, then after the summary is ouput in the logs (Tests Passed, Failed, Skipped, etc) the extension hangs until timeout.

@ChrisLGardner
Copy link
Collaborator

I'm tracking this on the new repo now at pester/AzureDevOpsExtension#13. I'll do some testing once I get the initial version of the new extension out and see what I can find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants