Skip to content

Commit 90c2f91

Browse files
authored
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
1 parent 9060ce4 commit 90c2f91

11 files changed

+38
-22
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Changed integration tests to display the removal of the Cosmos DB account
1818
in the teardown phase to ensure the account is removed after the tests are
1919
completed.
20+
- Updated collection and database autoscale minimum from 4000 to
21+
1000 - Fixes [Issue #493](https://github.com/PlagueHO/CosmosDB/issues/493).
22+
- Changed integration tests to attempt to clean up the Cosmos DB resource group
23+
if it is not removed by the teardown phase - Fixes [Issue #494](https://github.com/PlagueHO/CosmosDB/issues/494).
2024

2125
## [5.0.0] - 2024-06-07
2226

build.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ CopyPaths:
9292
- formats
9393
- en-US
9494
- types
95-
prefix: prefix.ps1
96-
suffix: suffix.ps1
95+
Prefix: prefix.ps1
96+
Suffix: suffix.ps1
9797
Encoding: UTF8
9898
VersionedOutputDirectory: true
9999

docs/New-CosmosDbCollection.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ Accept wildcard characters: False
322322
### -AutoscaleThroughput
323323
324324
The user specified autoscale throughput for the database expressed in RU/s.
325-
This can be between 4000 and 1,000,000 and should be specified in increments
325+
This can be between 1000 and 1,000,000 and should be specified in increments
326326
of 100 RU/s.
327327
This parameter can not be specified in OfferThroughput or OfferType is specified.
328328

docs/New-CosmosDbDatabase.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Accept wildcard characters: False
166166
### -AutoscaleThroughput
167167
168168
The user specified autoscale throughput for the database expressed in RU/s.
169-
This can be between 4000 and 1,000,000 and should be specified in increments
169+
This can be between 1000 and 1,000,000 and should be specified in increments
170170
of 100 RU/s.
171171
This parameter can not be specified in OfferThroughput is specified.
172172

source/Public/collections/New-CosmosDbCollection.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function New-CosmosDbCollection
7777
$UniqueKeyPolicy,
7878

7979
[Alias('AutopilotThroughput')]
80-
[ValidateRange(4000, 1000000)]
80+
[ValidateRange(1000, 1000000)]
8181
[System.Int32]
8282
$AutoscaleThroughput
8383
)

source/Public/databases/New-CosmosDbDatabase.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function New-CosmosDbDatabase
3737
$OfferThroughput,
3838

3939
[Alias('AutopilotThroughput','AutoscaleMaxThroughput','AutopilotMaxThroughput')]
40-
[ValidateRange(4000, 1000000)]
40+
[ValidateRange(1000, 1000000)]
4141
[System.Int32]
4242
$AutoscaleThroughput
4343
)

tests/Integration/CosmosDB.integration.Tests.ps1

+5-5
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ Describe 'Cosmos DB Module' -Tag 'Integration' {
528528

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

534534
It 'Should return expected object' {
@@ -553,9 +553,9 @@ Describe 'Cosmos DB Module' -Tag 'Integration' {
553553
$script:result.OfferType | Should -BeOfType [System.String]
554554
$script:result.OfferResourceId | Should -BeOfType [System.String]
555555
$script:result.Id | Should -BeOfType [System.String]
556-
$script:result.content.offerThroughput | Should -BeExactly 400
557-
$script:result.content.offerMinimumThroughputParameters.maxThroughputEverProvisioned | Should -BeExactly 4000
558-
$script:result.content.offerAutopilotSettings.maxThroughput | Should -BeExactly 4000
556+
$script:result.content.offerThroughput | Should -BeExactly 100
557+
$script:result.content.offerMinimumThroughputParameters.maxThroughputEverProvisioned | Should -BeExactly 1000
558+
$script:result.content.offerAutopilotSettings.maxThroughput | Should -BeExactly 1000
559559
}
560560
}
561561

@@ -1388,7 +1388,7 @@ Describe 'Cosmos DB Module' -Tag 'Integration' {
13881388
-Context $script:testContext `
13891389
-Id $script:testCollection `
13901390
-PartitionKey $script:testPartitionKey `
1391-
-AutoscaleThroughput 4000 `
1391+
-AutoscaleThroughput 1000 `
13921392
-Verbose
13931393
}
13941394

tests/TestHelper/TestHelper.psm1

+15-3
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,22 @@ function Remove-AzureTestCosmosDbResourceGroup
314314

315315
if ($PSCmdlet.ShouldProcess('Azure', ("Remove Azure Cosmos DB resource group '{0}'" -f $ResourceGroupName)))
316316
{
317-
$null = Remove-AzResourceGroup `
317+
Remove-AzResourceGroup `
318318
-Name $ResourceGroupName `
319-
-Force `
320-
-AsJob
319+
-Force
320+
321+
# Check if the resource group was removed
322+
$resourceGroup = Get-AzResourceGroup `
323+
-Name $ResourceGroupName `
324+
-ErrorAction SilentlyContinue
325+
326+
if ($null -ne $resourceGroup)
327+
{
328+
Write-Warning -Message ('Resource group {0} was not removed. Trying again.' -f $ResourceGroupName)
329+
Remove-AzResourceGroup `
330+
-Name $ResourceGroupName `
331+
-Force
332+
}
321333
}
322334
}
323335
catch [System.Exception]

tests/Unit/CosmosDB.accounts.Tests.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ InModuleScope $ProjectName {
124124

125125
Context 'When called with a valid name' {
126126
It 'Should return $true' {
127-
Assert-CosmosDbAccountNameValid -Name 'validaccountname' | Should -Be $true
127+
Assert-CosmosDbAccountNameValid -Name 'validaccountname' | Should -BeTrue
128128
}
129129
}
130130

@@ -196,7 +196,7 @@ InModuleScope $ProjectName {
196196

197197
Context 'When called with a valid resource group name' {
198198
It 'Should return $true' {
199-
Assert-CosmosDbResourceGroupNameValid -ResourceGroupName 'valid_resource-group.name123' | Should -Be $true
199+
Assert-CosmosDbResourceGroupNameValid -ResourceGroupName 'valid_resource-group.name123' | Should -BeTrue
200200
}
201201
}
202202

tests/Unit/CosmosDB.collections.Tests.ps1

+5-5
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ InModuleScope $ProjectName {
932932
$Method -eq 'Post' -and `
933933
$ResourceType -eq 'colls' -and `
934934
$BodyObject.id -eq $script:testCollection1 -and `
935-
$Headers.'x-ms-cosmos-offer-autopilot-settings' -eq "{`"maxThroughput`":4000}"
935+
$Headers.'x-ms-cosmos-offer-autopilot-settings' -eq "{`"maxThroughput`":1000}"
936936
}
937937

938938
Mock `
@@ -943,7 +943,7 @@ InModuleScope $ProjectName {
943943
$newCosmosDbCollectionParameters = @{
944944
Context = $script:testContext
945945
Id = $script:testCollection1
946-
AutoscaleThroughput = 4000
946+
AutoscaleThroughput = 1000
947947
PartitionKey = 'partitionkey'
948948
Verbose = $true
949949
}
@@ -972,7 +972,7 @@ InModuleScope $ProjectName {
972972
$newCosmosDbCollectionParameters = @{
973973
Context = $script:testContext
974974
Id = $script:testCollection1
975-
AutoscaleThroughput = 4000
975+
AutoscaleThroughput = 1000
976976
Verbose = $true
977977
}
978978

@@ -993,7 +993,7 @@ InModuleScope $ProjectName {
993993
Context = $script:testContext
994994
Id = $script:testCollection1
995995
OfferThroughput = 400
996-
AutoscaleThroughput = 4000
996+
AutoscaleThroughput = 1000
997997
Verbose = $true
998998
}
999999

@@ -1014,7 +1014,7 @@ InModuleScope $ProjectName {
10141014
Context = $script:testContext
10151015
Id = $script:testCollection1
10161016
OfferType = 'S1'
1017-
AutoscaleThroughput = 4000
1017+
AutoscaleThroughput = 1000
10181018
Verbose = $true
10191019
}
10201020

tests/Unit/CosmosDB.databases.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ InModuleScope $ProjectName {
3434
$script:testDatabase1 = 'testDatabase1'
3535
$script:testDatabase2 = 'testDatabase2'
3636
$script:testOfferThroughput = 2000
37-
$script:testAutoscaleThroughput = 4000
37+
$script:testAutoscaleThroughput = 1000
3838
$script:testJsonMulti = @'
3939
{
4040
"_rid": "",

0 commit comments

Comments
 (0)