Skip to content

Commit

Permalink
Update autoscale throughput minimum and enhance resource cleanup in t…
Browse files Browse the repository at this point in the history
…ests (#495)

* Update autoscale throughput minimum to 1000 and enhance Cosmos DB resource cleanup in tests

* Refactor build.yaml and unit tests for Cosmos DB to improve formatting and assertion readability

* Add error handling to resource group removal check in TestHelper.psm1

* Update Cosmos DB integration test to reflect new offer throughput value
  • Loading branch information
PlagueHO authored Dec 14, 2024
1 parent 9060ce4 commit 90c2f91
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changed integration tests to display the removal of the Cosmos DB account
in the teardown phase to ensure the account is removed after the tests are
completed.
- Updated collection and database autoscale minimum from 4000 to
1000 - Fixes [Issue #493](https://github.com/PlagueHO/CosmosDB/issues/493).
- Changed integration tests to attempt to clean up the Cosmos DB resource group
if it is not removed by the teardown phase - Fixes [Issue #494](https://github.com/PlagueHO/CosmosDB/issues/494).

## [5.0.0] - 2024-06-07

Expand Down
4 changes: 2 additions & 2 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ CopyPaths:
- formats
- en-US
- types
prefix: prefix.ps1
suffix: suffix.ps1
Prefix: prefix.ps1
Suffix: suffix.ps1
Encoding: UTF8
VersionedOutputDirectory: true

Expand Down
2 changes: 1 addition & 1 deletion docs/New-CosmosDbCollection.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ Accept wildcard characters: False
### -AutoscaleThroughput
The user specified autoscale throughput for the database expressed in RU/s.
This can be between 4000 and 1,000,000 and should be specified in increments
This can be between 1000 and 1,000,000 and should be specified in increments
of 100 RU/s.
This parameter can not be specified in OfferThroughput or OfferType is specified.
Expand Down
2 changes: 1 addition & 1 deletion docs/New-CosmosDbDatabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Accept wildcard characters: False
### -AutoscaleThroughput
The user specified autoscale throughput for the database expressed in RU/s.
This can be between 4000 and 1,000,000 and should be specified in increments
This can be between 1000 and 1,000,000 and should be specified in increments
of 100 RU/s.
This parameter can not be specified in OfferThroughput is specified.
Expand Down
2 changes: 1 addition & 1 deletion source/Public/collections/New-CosmosDbCollection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function New-CosmosDbCollection
$UniqueKeyPolicy,

[Alias('AutopilotThroughput')]
[ValidateRange(4000, 1000000)]
[ValidateRange(1000, 1000000)]
[System.Int32]
$AutoscaleThroughput
)
Expand Down
2 changes: 1 addition & 1 deletion source/Public/databases/New-CosmosDbDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function New-CosmosDbDatabase
$OfferThroughput,

[Alias('AutopilotThroughput','AutoscaleMaxThroughput','AutopilotMaxThroughput')]
[ValidateRange(4000, 1000000)]
[ValidateRange(1000, 1000000)]
[System.Int32]
$AutoscaleThroughput
)
Expand Down
10 changes: 5 additions & 5 deletions tests/Integration/CosmosDB.integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ Describe 'Cosmos DB Module' -Tag 'Integration' {

Context 'When creating third new database with a specified autoscale throughput' {
It 'Should not throw an exception' {
$script:result = New-CosmosDbDatabase -Context $script:testContext -Id $script:testDatabase3 -AutoscaleThroughput 4000 -Verbose
$script:result = New-CosmosDbDatabase -Context $script:testContext -Id $script:testDatabase3 -AutoscaleThroughput 1000 -Verbose
}

It 'Should return expected object' {
Expand All @@ -553,9 +553,9 @@ Describe 'Cosmos DB Module' -Tag 'Integration' {
$script:result.OfferType | Should -BeOfType [System.String]
$script:result.OfferResourceId | Should -BeOfType [System.String]
$script:result.Id | Should -BeOfType [System.String]
$script:result.content.offerThroughput | Should -BeExactly 400
$script:result.content.offerMinimumThroughputParameters.maxThroughputEverProvisioned | Should -BeExactly 4000
$script:result.content.offerAutopilotSettings.maxThroughput | Should -BeExactly 4000
$script:result.content.offerThroughput | Should -BeExactly 100
$script:result.content.offerMinimumThroughputParameters.maxThroughputEverProvisioned | Should -BeExactly 1000
$script:result.content.offerAutopilotSettings.maxThroughput | Should -BeExactly 1000
}
}

Expand Down Expand Up @@ -1388,7 +1388,7 @@ Describe 'Cosmos DB Module' -Tag 'Integration' {
-Context $script:testContext `
-Id $script:testCollection `
-PartitionKey $script:testPartitionKey `
-AutoscaleThroughput 4000 `
-AutoscaleThroughput 1000 `
-Verbose
}

Expand Down
18 changes: 15 additions & 3 deletions tests/TestHelper/TestHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,22 @@ function Remove-AzureTestCosmosDbResourceGroup

if ($PSCmdlet.ShouldProcess('Azure', ("Remove Azure Cosmos DB resource group '{0}'" -f $ResourceGroupName)))
{
$null = Remove-AzResourceGroup `
Remove-AzResourceGroup `
-Name $ResourceGroupName `
-Force `
-AsJob
-Force

# Check if the resource group was removed
$resourceGroup = Get-AzResourceGroup `
-Name $ResourceGroupName `
-ErrorAction SilentlyContinue

if ($null -ne $resourceGroup)
{
Write-Warning -Message ('Resource group {0} was not removed. Trying again.' -f $ResourceGroupName)
Remove-AzResourceGroup `
-Name $ResourceGroupName `
-Force
}
}
}
catch [System.Exception]
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/CosmosDB.accounts.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ InModuleScope $ProjectName {

Context 'When called with a valid name' {
It 'Should return $true' {
Assert-CosmosDbAccountNameValid -Name 'validaccountname' | Should -Be $true
Assert-CosmosDbAccountNameValid -Name 'validaccountname' | Should -BeTrue
}
}

Expand Down Expand Up @@ -196,7 +196,7 @@ InModuleScope $ProjectName {

Context 'When called with a valid resource group name' {
It 'Should return $true' {
Assert-CosmosDbResourceGroupNameValid -ResourceGroupName 'valid_resource-group.name123' | Should -Be $true
Assert-CosmosDbResourceGroupNameValid -ResourceGroupName 'valid_resource-group.name123' | Should -BeTrue
}
}

Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/CosmosDB.collections.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ InModuleScope $ProjectName {
$Method -eq 'Post' -and `
$ResourceType -eq 'colls' -and `
$BodyObject.id -eq $script:testCollection1 -and `
$Headers.'x-ms-cosmos-offer-autopilot-settings' -eq "{`"maxThroughput`":4000}"
$Headers.'x-ms-cosmos-offer-autopilot-settings' -eq "{`"maxThroughput`":1000}"
}

Mock `
Expand All @@ -943,7 +943,7 @@ InModuleScope $ProjectName {
$newCosmosDbCollectionParameters = @{
Context = $script:testContext
Id = $script:testCollection1
AutoscaleThroughput = 4000
AutoscaleThroughput = 1000
PartitionKey = 'partitionkey'
Verbose = $true
}
Expand Down Expand Up @@ -972,7 +972,7 @@ InModuleScope $ProjectName {
$newCosmosDbCollectionParameters = @{
Context = $script:testContext
Id = $script:testCollection1
AutoscaleThroughput = 4000
AutoscaleThroughput = 1000
Verbose = $true
}

Expand All @@ -993,7 +993,7 @@ InModuleScope $ProjectName {
Context = $script:testContext
Id = $script:testCollection1
OfferThroughput = 400
AutoscaleThroughput = 4000
AutoscaleThroughput = 1000
Verbose = $true
}

Expand All @@ -1014,7 +1014,7 @@ InModuleScope $ProjectName {
Context = $script:testContext
Id = $script:testCollection1
OfferType = 'S1'
AutoscaleThroughput = 4000
AutoscaleThroughput = 1000
Verbose = $true
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/CosmosDB.databases.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ InModuleScope $ProjectName {
$script:testDatabase1 = 'testDatabase1'
$script:testDatabase2 = 'testDatabase2'
$script:testOfferThroughput = 2000
$script:testAutoscaleThroughput = 4000
$script:testAutoscaleThroughput = 1000
$script:testJsonMulti = @'
{
"_rid": "",
Expand Down

0 comments on commit 90c2f91

Please sign in to comment.