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

Update tests to be able to run them outside of AppVeyor (part 3) #9426

Merged
merged 31 commits into from
Oct 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4ad3ee8
some more fixes
andreasjordan Jul 20, 2024
b8d71c5
fix test
andreasjordan Jul 20, 2024
338c203
more fixes
andreasjordan Jul 21, 2024
e5acd20
more fixes
andreasjordan Jul 21, 2024
e905510
more fixes
andreasjordan Jul 21, 2024
886e639
more fixes
andreasjordan Jul 21, 2024
b6a4cac
more fixes
andreasjordan Jul 21, 2024
379690e
more fixes
andreasjordan Jul 21, 2024
7b292ac
disable failing tests
andreasjordan Jul 21, 2024
14e8892
more fixes
andreasjordan Jul 22, 2024
74be105
more fixes
andreasjordan Jul 22, 2024
7926fff
fix test (do Start-DbaXESession)
andreasjordan Jul 22, 2024
936d776
skip test on appvayor
andreasjordan Jul 22, 2024
e7ff850
revert changes
andreasjordan Jul 22, 2024
bc506b1
revert changes
andreasjordan Jul 22, 2024
9b5ae5b
revert changes
andreasjordan Jul 22, 2024
8a712b5
revert changes
andreasjordan Jul 22, 2024
397c044
revert changes
andreasjordan Jul 22, 2024
fa98381
revert part of the test (do Find-DbaAgentJob)
andreasjordan Jul 24, 2024
944c9cf
just use one command
andreasjordan Jul 26, 2024
142d16e
revert the changes
andreasjordan Jul 26, 2024
ac21c00
just to trigger build (do Find)
niphlod Jul 30, 2024
ee9a982
reorg context (do Find)
niphlod Jul 30, 2024
cdb9eec
something is funny either with the before or after steps (do Find-Dba…
niphlod Jul 30, 2024
5cfe287
comment out more (do Find-DbaAgent)
niphlod Jul 30, 2024
b8d137c
investigating service status (do Find-DbaAgent)
niphlod Jul 30, 2024
82c6434
trying to remove the offending job that can't be started (do Find-Dba…
niphlod Jul 30, 2024
893d92a
another kind of setup (do Find-DbaAgent)
niphlod Jul 30, 2024
3e5dbb5
start job outside of the beforeall (do Find-DbaAgent)
niphlod Jul 30, 2024
eaa1099
retrieve real name for jobstep (do Find)
niphlod Jul 30, 2024
192633f
Merge branch 'development' into test_refactoring_3
potatoqualitee Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions tests/Find-DbaAgentJob.Tests.ps1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the change from 13 to 2 is the only thing that I can't readily say "ok, I get it"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me change that back and see what happens...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are still green. How is that possible?

Maybe because the test failed with an exception:
image

So we don't catch those errors, or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the AppVayor output from the dbatools-buildref-index.json run, you see more failed tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, it seems that those tests have a structure that is not compatible with pester.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the test works locally on my maschine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

problem here is that something either on the beforeall or afterall raises an error (seemingly the offending one is Start-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob').
I'm trying different variations because here, e.g., it seems that there are a sleuth of other jobs already present due to other tests (and the reason why the test creates 2 jobs but checks for 11, which is strange).
Being "bad-dy" ideally this test should clear out any existing job on the agent, create its own, do the tests, and re-cleanup (optionally).
Approaching with a bit of brain, the test creates two jobs and may only make assumptions on those two (and doing so, if one wants to run it locally, it will try - at least - to preserve already existing jobs).
I fear that starting the job (which is the step failing in the beforeall, and avoiding all the tests to be run) is needed for the very last test, but, still, I'm investigating.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaaand found. jobstep was failing to be created, because appveyor targets "localhost\SQL2016" but the param -SubsystemServer needs the real name (doesn't work with "localhost"). JobStep was failing to be created silently, Start-DbaAgent excepted (because it was a job with no steps), Pester4 doesn't handle well exceptions in the beforeall/afterall blocks.

Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
}

Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
#Context "Make sure Agent is running" {
# $results = Get-Service | Where-Object Name -like '*SqlAgent*'
# foreach($ag in $results) {
# It "$($ag.Name) status should be started" {
# $ag.Status | Should -Be "Running"
# }
# }
#}

Context "Command finds jobs using all parameters" {
BeforeAll {
#subsystemServer needs the real underlying name, and it doesn't work if targeting something like localhost\namedinstance
# the typical error would be WARNING: [17:19:26][New-DbaAgentJobStep] Something went wrong creating the job step | The specified '@server' is
#invalid (valid values are returned by sp_helpserver).
$srvName = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select @@servername as sn" -as PSObject
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using -As SingleValue and replacing $srvName.sn by $srvName?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that would work, too.

$null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa'
$null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $script:instance2 -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2
$null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2
$null = Start-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob'
$null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa'
$null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2
$null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' -CategoryType LocalJob
$null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -Category 'dbatoolsci_job_category' -Disabled
$null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -StepId 1 -StepName 'dbatoolsci Test Step' -Subsystem TransactSql -SubsystemServer $script:instance2 -Command 'SELECT * FROM master.sys.all_columns' -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2
$null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -StepId 1 -StepName 'dbatoolsci Test Step' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command 'SELECT * FROM master.sys.all_columns' -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2
}
AfterAll {
$null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false
Expand Down Expand Up @@ -79,8 +79,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
It "Should find jobs that are owned by sa" {
$results | Should not be null
}
$null = Start-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob'
Start-Sleep 5


$results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsFailed -Since '2016-07-01 10:47:00'
It "Should find jobs that have been failed since July of 2016" {
$results | Should not be null
Expand Down
Loading