Skip to content

Commit 4fd4461

Browse files
authored
Added function Start-TestSleep in autorest to avoid waiting during playback mode (#23625)
* Manually added Start-TestSleep function and replaced Start-Sleep with Start-TestSleep * Replaced Start-Sleep in SDK with Start-TestSleep
1 parent 2819148 commit 4fd4461

File tree

156 files changed

+3890
-808
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+3890
-808
lines changed

src/ADDomainServices/ADDomainServices.Autorest/test/Remove-AzADDomainService.Tests.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Describe 'Remove-AzADDomainService' {
2121
It 'DeleteViaIdentity' {
2222
$ReplicaSet = New-AzADDomainServiceReplicaSetObject -Location $env.Location -SubnetId $env.SubnetId
2323
$NewAdDomain = New-AzADDomainService -name $env.ADdomainName -ResourceGroupName $env.ResourceGroupName -DomainName $env.ADDomainNameCom -ReplicaSet $ReplicaSet
24-
# Start-Sleep -s 120
2524
$GetADDomainExample = Get-AzADDomainService -ResourceGroupName $env.ResourceGroupName -Name $env.ADdomainName
2625
Remove-AzADDomainService -InputObject $GetADDomainExample
2726
$GetADDomainList = Get-AzADDomainService

src/ADDomainServices/ADDomainServices.Autorest/test/Update-AzADDomainService.Tests.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Describe 'Update-AzADDomainService' {
1818
}
1919

2020
It 'UpdateViaIdentityExpanded' {
21-
# Start-Sleep -s 240
2221
$GetADDomainExample = Get-AzADDomainService -ResourceGroupName $env.ResourceGroupName -Name $env.ADdomainName
2322
$UpdateADDomain = Update-AzADDomainService -InputObject $GetADDomainExample -DomainSecuritySettingTlsV1 $env.TlsV1Status2
2423
$UpdateADDomain.DomainSecuritySettingTlsV1 | Should -Be $env.TlsV1Status2

src/ADDomainServices/ADDomainServices.Autorest/test/utils.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ function RandomString([bool]$allChars, [int32]$len) {
55
return -join ((48..57) + (97..122) | Get-Random -Count $len | % {[char]$_})
66
}
77
}
8+
function Start-TestSleep {
9+
[CmdletBinding(DefaultParameterSetName = 'SleepBySeconds')]
10+
param(
11+
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'SleepBySeconds')]
12+
[ValidateRange(0.0, 2147483.0)]
13+
[double] $Seconds,
14+
15+
[parameter(Mandatory = $true, ParameterSetName = 'SleepByMilliseconds')]
16+
[ValidateRange('NonNegative')]
17+
[Alias('ms')]
18+
[int] $Milliseconds
19+
)
20+
21+
if ($TestMode -ne 'playback') {
22+
switch ($PSCmdlet.ParameterSetName) {
23+
'SleepBySeconds' {
24+
Start-Sleep -Seconds $Seconds
25+
}
26+
'SleepByMilliseconds' {
27+
Start-Sleep -Milliseconds $Milliseconds
28+
}
29+
}
30+
}
31+
}
32+
833
$env = @{}
934
function setupEnv() {
1035
# Preload subscriptionId and tenant from context, which will be used in test

src/Advisor/Advisor.Autorest/test/utils.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ function RandomString([bool]$allChars, [int32]$len) {
55
return -join ((48..57) + (97..122) | Get-Random -Count $len | % {[char]$_})
66
}
77
}
8+
function Start-TestSleep {
9+
[CmdletBinding(DefaultParameterSetName = 'SleepBySeconds')]
10+
param(
11+
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'SleepBySeconds')]
12+
[ValidateRange(0.0, 2147483.0)]
13+
[double] $Seconds,
14+
15+
[parameter(Mandatory = $true, ParameterSetName = 'SleepByMilliseconds')]
16+
[ValidateRange('NonNegative')]
17+
[Alias('ms')]
18+
[int] $Milliseconds
19+
)
20+
21+
if ($TestMode -ne 'playback') {
22+
switch ($PSCmdlet.ParameterSetName) {
23+
'SleepBySeconds' {
24+
Start-Sleep -Seconds $Seconds
25+
}
26+
'SleepByMilliseconds' {
27+
Start-Sleep -Milliseconds $Milliseconds
28+
}
29+
}
30+
}
31+
}
32+
833
$env = @{}
934
if ($UsePreviousConfigForRecord) {
1035
$previousEnv = Get-Content (Join-Path $PSScriptRoot 'env.json') | ConvertFrom-Json

src/Aks/Aks.Autorest/test/utils.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ function RandomString([bool]$allChars, [int32]$len) {
55
return -join ((48..57) + (97..122) | Get-Random -Count $len | % {[char]$_})
66
}
77
}
8+
function Start-TestSleep {
9+
[CmdletBinding(DefaultParameterSetName = 'SleepBySeconds')]
10+
param(
11+
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'SleepBySeconds')]
12+
[ValidateRange(0.0, 2147483.0)]
13+
[double] $Seconds,
14+
15+
[parameter(Mandatory = $true, ParameterSetName = 'SleepByMilliseconds')]
16+
[ValidateRange('NonNegative')]
17+
[Alias('ms')]
18+
[int] $Milliseconds
19+
)
20+
21+
if ($TestMode -ne 'playback') {
22+
switch ($PSCmdlet.ParameterSetName) {
23+
'SleepBySeconds' {
24+
Start-Sleep -Seconds $Seconds
25+
}
26+
'SleepByMilliseconds' {
27+
Start-Sleep -Milliseconds $Milliseconds
28+
}
29+
}
30+
}
31+
}
32+
833
$env = @{}
934
function setupEnv() {
1035
# Preload subscriptionId and tenant from context, which will be used in test

src/Alb/Alb.Autorest/test/utils.ps1

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ function RandomString([bool]$allChars, [int32]$len) {
55
return -join ((48..57) + (97..122) | Get-Random -Count $len | % {[char]$_})
66
}
77
}
8+
function Start-TestSleep {
9+
[CmdletBinding(DefaultParameterSetName = 'SleepBySeconds')]
10+
param(
11+
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'SleepBySeconds')]
12+
[ValidateRange(0.0, 2147483.0)]
13+
[double] $Seconds,
14+
15+
[parameter(Mandatory = $true, ParameterSetName = 'SleepByMilliseconds')]
16+
[ValidateRange('NonNegative')]
17+
[Alias('ms')]
18+
[int] $Milliseconds
19+
)
20+
21+
if ($TestMode -ne 'playback') {
22+
switch ($PSCmdlet.ParameterSetName) {
23+
'SleepBySeconds' {
24+
Start-Sleep -Seconds $Seconds
25+
}
26+
'SleepByMilliseconds' {
27+
Start-Sleep -Milliseconds $Milliseconds
28+
}
29+
}
30+
}
31+
}
32+
833
$env = @{}
934
if ($UsePreviousConfigForRecord) {
1035
$previousEnv = Get-Content (Join-Path $PSScriptRoot 'env.json') | ConvertFrom-Json
@@ -42,7 +67,7 @@ function setupEnv() {
4267
# Build dependent resources
4368
New-AzResourceGroup -Name $env.resourceGroup -Location $env.region
4469
New-AzDeployment -TemplateFile "/src/Alb/test/prereqs.json" -Mode Complete -ResourceGroupName $env.resourceGroup -TemplateParameterObject @{}
45-
70+
4671
}
4772
function cleanupEnv() {
4873
# Clean resources you create for testing

src/AlertsManagement/PrometheusRuleGroups.Autorest/test/utils.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ function RandomString([bool]$allChars, [int32]$len) {
55
return -join ((48..57) + (97..122) | Get-Random -Count $len | % {[char]$_})
66
}
77
}
8+
function Start-TestSleep {
9+
[CmdletBinding(DefaultParameterSetName = 'SleepBySeconds')]
10+
param(
11+
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'SleepBySeconds')]
12+
[ValidateRange(0.0, 2147483.0)]
13+
[double] $Seconds,
14+
15+
[parameter(Mandatory = $true, ParameterSetName = 'SleepByMilliseconds')]
16+
[ValidateRange('NonNegative')]
17+
[Alias('ms')]
18+
[int] $Milliseconds
19+
)
20+
21+
if ($TestMode -ne 'playback') {
22+
switch ($PSCmdlet.ParameterSetName) {
23+
'SleepBySeconds' {
24+
Start-Sleep -Seconds $Seconds
25+
}
26+
'SleepByMilliseconds' {
27+
Start-Sleep -Milliseconds $Milliseconds
28+
}
29+
}
30+
}
31+
}
32+
833
$env = @{}
934
if ($UsePreviousConfigForRecord) {
1035
$previousEnv = Get-Content (Join-Path $PSScriptRoot 'env.json') | ConvertFrom-Json

src/App/App.Autorest/test/utils.ps1

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ function RandomString([bool]$allChars, [int32]$len) {
55
return -join ((48..57) + (97..122) | Get-Random -Count $len | % {[char]$_})
66
}
77
}
8+
function Start-TestSleep {
9+
[CmdletBinding(DefaultParameterSetName = 'SleepBySeconds')]
10+
param(
11+
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'SleepBySeconds')]
12+
[ValidateRange(0.0, 2147483.0)]
13+
[double] $Seconds,
14+
15+
[parameter(Mandatory = $true, ParameterSetName = 'SleepByMilliseconds')]
16+
[ValidateRange('NonNegative')]
17+
[Alias('ms')]
18+
[int] $Milliseconds
19+
)
20+
21+
if ($TestMode -ne 'playback') {
22+
switch ($PSCmdlet.ParameterSetName) {
23+
'SleepBySeconds' {
24+
Start-Sleep -Seconds $Seconds
25+
}
26+
'SleepByMilliseconds' {
27+
Start-Sleep -Milliseconds $Milliseconds
28+
}
29+
}
30+
}
31+
}
32+
833
$env = @{}
934
if ($UsePreviousConfigForRecord) {
1035
$previousEnv = Get-Content (Join-Path $PSScriptRoot 'env.json') | ConvertFrom-Json
@@ -93,7 +118,7 @@ function setupEnv() {
93118
$resourceGroupConnected = "azps_test_group_app" #"a" + (RandomString -allChars $false -len 6)
94119
$env.Add("resourceGroupManaged", $resourceGroupManaged)
95120
$env.Add("resourceGroupConnected", $resourceGroupConnected)
96-
121+
97122
write-host "Create ResourceGroup for managed env"
98123
New-AzResourceGroup -Name $env.resourceGroupManaged -Location $env.location
99124

@@ -126,12 +151,12 @@ function setupEnv() {
126151
$secretObject = New-AzContainerAppSecretObject -Name "redis-config" -Value "redis-password"
127152
$configuration = New-AzContainerAppConfigurationObject -IngressIPSecurityRestriction $iPSecurityRestrictionRule -IngressTraffic $trafficWeight -IngressExternal:$True -IngressTargetPort 80 -IngressClientCertificateMode "accept" -CorPolicyAllowedOrigin "https://a.test.com","https://b.test.com" -CorPolicyAllowedMethod "GET","POST" -CorPolicyAllowedHeader "HEADER1","HEADER2" -CorPolicyExposeHeader "HEADER3","HEADER4" -CorPolicyMaxAge 1234 -CorPolicyAllowCredentials:$True -DaprEnabled:$True -DaprAppPort 3000 -DaprAppProtocol "http" -DaprHttpReadBufferSize 30 -DaprHttpMaxRequestSize 10 -DaprLogLevel "debug" -DaprEnableApiLogging:$True -MaxInactiveRevision 10 -ServiceType "redis" -Secret $secretObject
128153
$serviceBind = New-AzContainerAppServiceBindObject -Name "redisService" -ServiceId "/subscriptions/$($env.SubscriptionId)/resourceGroups/$($env.resourceGroupManaged)/providers/Microsoft.App/containerApps/$($env.containerApp1)"
129-
154+
130155
$probeHttpGetHttpHeader = New-AzContainerAppProbeHeaderObject -Name "Custom-Header" -Value "Awesome"
131156
$probe = New-AzContainerAppProbeObject -Type "Liveness" -HttpGetPath "/health" -HttpGetPort 8080 -InitialDelaySecond 3 -PeriodSecond 3 -HttpGetHttpHeader $probeHttpGetHttpHeader
132157
$temp = New-AzContainerAppTemplateObject -Image "mcr.microsoft.com/k8se/quickstart-jobs:latest" -Name "simple-hello-world-container" -Probe $probe -ResourceCpu 0.25 -ResourceMemory "0.5Gi"
133158
$temp2 = New-AzContainerAppInitContainerTemplateObject -Image "mcr.microsoft.com/k8se/quickstart-jobs:latest" -Name "simple-hello-world-container2" -ResourceCpu 0.25 -ResourceMemory "0.5Gi" -Command "/bin/sh" -Arg "-c","echo hello; sleep 10;"
134-
159+
135160
write-host "Create container app for managed env"
136161
New-AzContainerApp -ResourceGroupName $env.resourceGroupManaged -Name $env.containerApp1 -Location $env.location -Configuration $configuration -TemplateContainer $temp -TemplateInitContainer $temp2 -TemplateServiceBind $serviceBind -EnvironmentId $EnvId
137162

@@ -156,12 +181,12 @@ function setupEnv() {
156181

157182
write-host "Create connected env cert"
158183
New-AzContainerAppConnectedEnvCert -Name $env.connectedEnvCert1 -ConnectedEnvironmentName $env.connectedEnv1 -ResourceGroupName $env.resourceGroupConnected -Location $env.location -InputFile ".\test\mypfx.pfx" -Password $mypwd
159-
184+
160185
$trafficWeight = New-AzContainerAppTrafficWeightObject -Label "production" -Weight 100 -LatestRevision:$True
161186
$configuration = New-AzContainerAppConfigurationObject -IngressTraffic $trafficWeight -IngressExternal:$True -IngressTargetPort 80
162187
$temp = New-AzContainerAppTemplateObject -Image "mcr.microsoft.com/k8se/quickstart-jobs:latest" -Name "simple-hello-world-container" -ResourceCpu 0.25 -ResourceMemory "0.5Gi"
163188
$temp2 = New-AzContainerAppInitContainerTemplateObject -Image "mcr.microsoft.com/k8se/quickstart-jobs:latest" -Name "simple-hello-world-container2" -ResourceCpu 0.25 -ResourceMemory "0.5Gi" -Command "/bin/sh" -Arg "-c","echo hello; sleep 10;"
164-
189+
165190
write-host "Create container app for connected env"
166191
New-AzContainerApp -ResourceGroupName $env.resourceGroupConnected -Name $env.containerApp2 -Location $env.location -Configuration $configuration -TemplateContainer $temp -TemplateInitContainer $temp2 -EnvironmentId $EnvId -ExtendedLocationName "/subscriptions/$($env.SubscriptionId)/resourceGroups/$($env.resourceGroupConnected)/providers/Microsoft.ExtendedLocation/customLocations/$($env.customLocation)" -ExtendedLocationType CustomLocation
167192

src/AppConfiguration/AppConfiguration.Autorest/test/utils.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ function RandomString([bool]$allChars, [int32]$len) {
55
return -join ((48..57) + (97..122) | Get-Random -Count $len | % {[char]$_})
66
}
77
}
8+
function Start-TestSleep {
9+
[CmdletBinding(DefaultParameterSetName = 'SleepBySeconds')]
10+
param(
11+
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'SleepBySeconds')]
12+
[ValidateRange(0.0, 2147483.0)]
13+
[double] $Seconds,
14+
15+
[parameter(Mandatory = $true, ParameterSetName = 'SleepByMilliseconds')]
16+
[ValidateRange('NonNegative')]
17+
[Alias('ms')]
18+
[int] $Milliseconds
19+
)
20+
21+
if ($TestMode -ne 'playback') {
22+
switch ($PSCmdlet.ParameterSetName) {
23+
'SleepBySeconds' {
24+
Start-Sleep -Seconds $Seconds
25+
}
26+
'SleepByMilliseconds' {
27+
Start-Sleep -Milliseconds $Milliseconds
28+
}
29+
}
30+
}
31+
}
32+
833
$env = @{}
934
if ($UsePreviousConfigForRecord) {
1035
$previousEnv = Get-Content (Join-Path $PSScriptRoot 'env.json') | ConvertFrom-Json

src/AppConfiguration/AppConfigurationData.Autorest/test/utils.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ function RandomString([bool]$allChars, [int32]$len) {
55
return -join ((48..57) + (97..122) | Get-Random -Count $len | % {[char]$_})
66
}
77
}
8+
function Start-TestSleep {
9+
[CmdletBinding(DefaultParameterSetName = 'SleepBySeconds')]
10+
param(
11+
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'SleepBySeconds')]
12+
[ValidateRange(0.0, 2147483.0)]
13+
[double] $Seconds,
14+
15+
[parameter(Mandatory = $true, ParameterSetName = 'SleepByMilliseconds')]
16+
[ValidateRange('NonNegative')]
17+
[Alias('ms')]
18+
[int] $Milliseconds
19+
)
20+
21+
if ($TestMode -ne 'playback') {
22+
switch ($PSCmdlet.ParameterSetName) {
23+
'SleepBySeconds' {
24+
Start-Sleep -Seconds $Seconds
25+
}
26+
'SleepByMilliseconds' {
27+
Start-Sleep -Milliseconds $Milliseconds
28+
}
29+
}
30+
}
31+
}
32+
833
$env = @{}
934
if ($UsePreviousConfigForRecord) {
1035
$previousEnv = Get-Content (Join-Path $PSScriptRoot 'env.json') | ConvertFrom-Json

0 commit comments

Comments
 (0)