Skip to content

Commit

Permalink
Updates list of exceptions with System.ArgumentException for retry (#586
Browse files Browse the repository at this point in the history
)
  • Loading branch information
X-Guardian authored and johlju committed Apr 9, 2020
1 parent c00252d commit 657a7c2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)

## [Unreleased]

### Fixed

- ADDomain
- Added additional Get-ADDomain retry exceptions
([issue #581](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/581)).

### Changed

- ActiveDirectoryDsc
Expand Down
21 changes: 21 additions & 0 deletions Tests/Unit/MSFT_ADDomain.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,27 @@ try
}
}

Context 'When Get-ADDomain throws an ArgumentException until timeout' {
BeforeAll {
Mock -CommandName Get-AdDomain `
-MockWith { throw New-Object -TypeName 'System.ArgumentException' }
Mock -CommandName Start-Sleep
}

It 'Should throw the correct exception' {
{ Get-TargetResource @mockGetTargetResourceParameters } |
Should -Throw ($script:localizedData.MaxDomainRetriesReachedError -f $mockDomainFQDN)
}

It 'Should call the expected mocks' {
Assert-MockCalled -CommandName Get-ADDomain `
-ParameterFilter { $Identity -eq $mockDomainFQDN } `
-Exactly -Times $maxRetries
Assert-MockCalled -CommandName Start-Sleep `
-Exactly -Times $maxRetries
}
}

Context 'When Get-ADForest throws an unexpected error' {
BeforeAll {
Mock -CommandName Get-AdForest `
Expand Down
3 changes: 2 additions & 1 deletion source/DSCResources/MSFT_ADDomain/MSFT_ADDomain.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ function Get-TargetResource
}
catch [Microsoft.ActiveDirectory.Management.ADServerDownException], `
[System.Security.Authentication.AuthenticationException], `
[System.InvalidOperationException]
[System.InvalidOperationException], `
[System.ArgumentException]
{
Write-Verbose ($script:localizedData.ADServerNotReady -f $domainFQDN)
$domainFound = $false
Expand Down

0 comments on commit 657a7c2

Please sign in to comment.