From 90c2f91629ad095cd69ca049c9e7a358ec24d037 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 15 Dec 2024 07:51:13 +1300 Subject: [PATCH] Update autoscale throughput minimum and enhance resource cleanup in tests (#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 --- CHANGELOG.md | 4 ++++ build.yaml | 4 ++-- docs/New-CosmosDbCollection.md | 2 +- docs/New-CosmosDbDatabase.md | 2 +- .../collections/New-CosmosDbCollection.ps1 | 2 +- .../Public/databases/New-CosmosDbDatabase.ps1 | 2 +- .../Integration/CosmosDB.integration.Tests.ps1 | 10 +++++----- tests/TestHelper/TestHelper.psm1 | 18 +++++++++++++++--- tests/Unit/CosmosDB.accounts.Tests.ps1 | 4 ++-- tests/Unit/CosmosDB.collections.Tests.ps1 | 10 +++++----- tests/Unit/CosmosDB.databases.Tests.ps1 | 2 +- 11 files changed, 38 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fb6668c..9efc7eb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/build.yaml b/build.yaml index 0b37cf89..dc8236ab 100644 --- a/build.yaml +++ b/build.yaml @@ -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 diff --git a/docs/New-CosmosDbCollection.md b/docs/New-CosmosDbCollection.md index db6fc0ca..9fd05bf1 100644 --- a/docs/New-CosmosDbCollection.md +++ b/docs/New-CosmosDbCollection.md @@ -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. diff --git a/docs/New-CosmosDbDatabase.md b/docs/New-CosmosDbDatabase.md index 45627ee2..89b64f66 100644 --- a/docs/New-CosmosDbDatabase.md +++ b/docs/New-CosmosDbDatabase.md @@ -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. diff --git a/source/Public/collections/New-CosmosDbCollection.ps1 b/source/Public/collections/New-CosmosDbCollection.ps1 index dfef52cf..e8028bf4 100644 --- a/source/Public/collections/New-CosmosDbCollection.ps1 +++ b/source/Public/collections/New-CosmosDbCollection.ps1 @@ -77,7 +77,7 @@ function New-CosmosDbCollection $UniqueKeyPolicy, [Alias('AutopilotThroughput')] - [ValidateRange(4000, 1000000)] + [ValidateRange(1000, 1000000)] [System.Int32] $AutoscaleThroughput ) diff --git a/source/Public/databases/New-CosmosDbDatabase.ps1 b/source/Public/databases/New-CosmosDbDatabase.ps1 index d1121d21..4dff8e17 100644 --- a/source/Public/databases/New-CosmosDbDatabase.ps1 +++ b/source/Public/databases/New-CosmosDbDatabase.ps1 @@ -37,7 +37,7 @@ function New-CosmosDbDatabase $OfferThroughput, [Alias('AutopilotThroughput','AutoscaleMaxThroughput','AutopilotMaxThroughput')] - [ValidateRange(4000, 1000000)] + [ValidateRange(1000, 1000000)] [System.Int32] $AutoscaleThroughput ) diff --git a/tests/Integration/CosmosDB.integration.Tests.ps1 b/tests/Integration/CosmosDB.integration.Tests.ps1 index dfb8d00e..3741fe46 100644 --- a/tests/Integration/CosmosDB.integration.Tests.ps1 +++ b/tests/Integration/CosmosDB.integration.Tests.ps1 @@ -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' { @@ -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 } } @@ -1388,7 +1388,7 @@ Describe 'Cosmos DB Module' -Tag 'Integration' { -Context $script:testContext ` -Id $script:testCollection ` -PartitionKey $script:testPartitionKey ` - -AutoscaleThroughput 4000 ` + -AutoscaleThroughput 1000 ` -Verbose } diff --git a/tests/TestHelper/TestHelper.psm1 b/tests/TestHelper/TestHelper.psm1 index ef99d897..77bd60d0 100644 --- a/tests/TestHelper/TestHelper.psm1 +++ b/tests/TestHelper/TestHelper.psm1 @@ -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] diff --git a/tests/Unit/CosmosDB.accounts.Tests.ps1 b/tests/Unit/CosmosDB.accounts.Tests.ps1 index 3f55d108..8e483970 100644 --- a/tests/Unit/CosmosDB.accounts.Tests.ps1 +++ b/tests/Unit/CosmosDB.accounts.Tests.ps1 @@ -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 } } @@ -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 } } diff --git a/tests/Unit/CosmosDB.collections.Tests.ps1 b/tests/Unit/CosmosDB.collections.Tests.ps1 index 837170ea..0760dcc0 100644 --- a/tests/Unit/CosmosDB.collections.Tests.ps1 +++ b/tests/Unit/CosmosDB.collections.Tests.ps1 @@ -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 ` @@ -943,7 +943,7 @@ InModuleScope $ProjectName { $newCosmosDbCollectionParameters = @{ Context = $script:testContext Id = $script:testCollection1 - AutoscaleThroughput = 4000 + AutoscaleThroughput = 1000 PartitionKey = 'partitionkey' Verbose = $true } @@ -972,7 +972,7 @@ InModuleScope $ProjectName { $newCosmosDbCollectionParameters = @{ Context = $script:testContext Id = $script:testCollection1 - AutoscaleThroughput = 4000 + AutoscaleThroughput = 1000 Verbose = $true } @@ -993,7 +993,7 @@ InModuleScope $ProjectName { Context = $script:testContext Id = $script:testCollection1 OfferThroughput = 400 - AutoscaleThroughput = 4000 + AutoscaleThroughput = 1000 Verbose = $true } @@ -1014,7 +1014,7 @@ InModuleScope $ProjectName { Context = $script:testContext Id = $script:testCollection1 OfferType = 'S1' - AutoscaleThroughput = 4000 + AutoscaleThroughput = 1000 Verbose = $true } diff --git a/tests/Unit/CosmosDB.databases.Tests.ps1 b/tests/Unit/CosmosDB.databases.Tests.ps1 index 00222c18..b48660fc 100644 --- a/tests/Unit/CosmosDB.databases.Tests.ps1 +++ b/tests/Unit/CosmosDB.databases.Tests.ps1 @@ -34,7 +34,7 @@ InModuleScope $ProjectName { $script:testDatabase1 = 'testDatabase1' $script:testDatabase2 = 'testDatabase2' $script:testOfferThroughput = 2000 - $script:testAutoscaleThroughput = 4000 + $script:testAutoscaleThroughput = 1000 $script:testJsonMulti = @' { "_rid": "",