Skip to content

Commit 0bde51e

Browse files
author
maddieclayton
authored
Merge pull request Azure#5017 from maddieclayton/fixcomptext1
Make timeout adjustable and rerecord test with longer timeout for completers
2 parents f197614 + fe9a17e commit 0bde51e

File tree

5 files changed

+68
-54
lines changed

5 files changed

+68
-54
lines changed

src/ResourceManager/Common/Commands.ResourceManager.Common/ArgumentCompleters/LocationCompleter.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class LocationCompleterAttribute : PSCompleterBaseAttribute
3535
private static IDictionary<int, IDictionary<string, ICollection<string>>> _resourceTypeLocationDictionary = new ConcurrentDictionary<int, IDictionary<string, ICollection<string>>>();
3636
private static readonly object _lock = new object();
3737
private static string[] _resourceTypes;
38+
private static int _timeout = 3;
3839

3940
protected static IDictionary<string, ICollection<string>> ResourceTypeLocationDictionary
4041
{
@@ -56,7 +57,7 @@ protected static IDictionary<string, ICollection<string>> ResourceTypeLocationDi
5657
instance.ClientFactory.GetCustomHandlers());
5758
client.SubscriptionId = context.Subscription.Id;
5859
var allProviders = client.Providers.ListAsync();
59-
if (allProviders.Wait(TimeSpan.FromSeconds(3)))
60+
if (allProviders.Wait(TimeSpan.FromSeconds(_timeout)))
6061
{
6162
if (allProviders.Result != null)
6263
{
@@ -114,6 +115,12 @@ public override string[] GetCompleterValues()
114115
return FindLocations(_resourceTypes);
115116
}
116117

118+
public static string[] FindLocations(string[] resourceTypes, int timeout)
119+
{
120+
_timeout = timeout;
121+
return FindLocations(resourceTypes);
122+
}
123+
117124
public static string[] FindLocations(string[] resourceTypes)
118125
{
119126
return FindLocations(resourceTypes, ResourceTypeLocationDictionary);

src/ResourceManager/Common/Commands.ResourceManager.Common/ArgumentCompleters/ResourceGroupCompleter.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class ResourceGroupCompleterAttribute : PSCompleterBaseAttribute
3333
{
3434
private static IDictionary<int, IList<String>> _resourceGroupNamesDictionary = new ConcurrentDictionary<int, IList<string>>();
3535
private static readonly object _lock = new object();
36+
public static int _timeout = 3;
3637

3738
protected static IList<String> ResourceGroupNames
3839
{
@@ -55,7 +56,7 @@ protected static IList<String> ResourceGroupNames
5556
client.SubscriptionId = context.Subscription.Id;
5657
// Retrieve only the first page of ResourceGroups to display to the user
5758
var resourceGroups = client.ResourceGroups.ListAsync();
58-
if (resourceGroups.Wait(TimeSpan.FromSeconds(5)))
59+
if (resourceGroups.Wait(TimeSpan.FromSeconds(_timeout)))
5960
{
6061
tempResourceGroupList = CreateResourceGroupList(resourceGroups.Result);
6162
if (resourceGroups.Result != null)
@@ -104,6 +105,12 @@ public override string[] GetCompleterValues()
104105
return GetResourceGroups();
105106
}
106107

108+
public static string[] GetResourceGroups(int timeout)
109+
{
110+
_timeout = timeout;
111+
return GetResourceGroups();
112+
}
113+
107114
public static string[] GetResourceGroups()
108115
{
109116
IAzureContext context = AzureRmProfileProvider.Instance.Profile.DefaultContext;

src/ResourceManager/Profile/Commands.Profile.Test/ArgumentCompleterTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function Test-LocationCompleter
2121
$filePath = Join-Path -Path $PSScriptRoot -ChildPath "\Microsoft.Azure.Commands.ResourceManager.Common.dll"
2222
$assembly = [System.Reflection.Assembly]::LoadFrom($filePath)
2323
$resourceTypes = @("Microsoft.Batch/operations")
24-
$locations = [Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.LocationCompleterAttribute]::FindLocations($resourceTypes)
24+
$locations = [Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.LocationCompleterAttribute]::FindLocations($resourceTypes, 60)
2525
$expectedResourceType = Get-AzureRmResourceProvider -ProviderNamespace "Microsoft.Batch" | Where-Object {$_.ResourceTypes.ResourceTypeName -eq "operations"}
2626
$expectedLocations = $expectedResourceType.Locations | ForEach-Object {"`"" + $_ + "`""}
2727
Assert-AreEqualArray $locations $expectedLocations
@@ -36,7 +36,7 @@ function Test-ResourceGroupCompleter
3636
{
3737
$filePath = Join-Path -Path $PSScriptRoot -ChildPath "\Microsoft.Azure.Commands.ResourceManager.Common.dll"
3838
$assembly = [System.Reflection.Assembly]::LoadFrom($filePath)
39-
$resourceGroups = [Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.ResourceGroupCompleterAttribute]::GetResourceGroups()
39+
$resourceGroups = [Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.ResourceGroupCompleterAttribute]::GetResourceGroups(60)
4040
$expectResourceGroups = Get-AzureRmResourceGroup | ForEach-Object {$_.ResourceGroupName}
4141
Assert-AreEqualArray $resourceGroups $expectResourceGroups
4242
}

src/ResourceManager/Profile/Commands.Profile.Test/SessionRecords/Microsoft.Azure.Commands.Profile.Test.ArgumentCompleterTests/TestLocationCompleter.json

Lines changed: 29 additions & 29 deletions
Large diffs are not rendered by default.

src/ResourceManager/Profile/Commands.Profile.Test/SessionRecords/Microsoft.Azure.Commands.Profile.Test.ArgumentCompleterTests/TestResourceGroupCompleter.json

Lines changed: 21 additions & 21 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)