Skip to content

Commit ca5a272

Browse files
authored
Merge pull request #6200 from maddieclayton/fixAC
Fix flaky ArgumentCompleter tests
2 parents 6de551a + 2575c01 commit ca5a272

File tree

8 files changed

+118
-63
lines changed

8 files changed

+118
-63
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,23 @@ protected static IDictionary<string, ICollection<string>> ResourceTypeLocationDi
5151
{
5252
IResourceManagementClient client = AzureSession.Instance.ClientFactory.CreateArmClient<ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);
5353
var allProviders = client.Providers.ListAsync();
54-
if (allProviders.Wait(TimeSpan.FromSeconds(_timeout)))
54+
if (_timeout == -1)
55+
{
56+
allProviders.Wait();
57+
if (allProviders.Result != null)
58+
{
59+
_resourceTypeLocationDictionary[contextHash] = CreateLocationDictionary(allProviders.Result.ToList());
60+
output = _resourceTypeLocationDictionary[contextHash];
61+
}
62+
else
63+
{
64+
output = CreateLocationDictionary(new List<Provider>());
65+
#if DEBUG
66+
throw new InvalidOperationException("Result from client.Providers is null");
67+
#endif
68+
}
69+
}
70+
else if (allProviders.Wait(TimeSpan.FromSeconds(_timeout)))
5571
{
5672
if (allProviders.Result != null)
5773
{

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,17 @@ protected static IList<String> ResourceGroupNames
5151
var client = AzureSession.Instance.ClientFactory.CreateArmClient<ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);
5252
// Retrieve only the first page of ResourceGroups to display to the user
5353
var resourceGroups = client.ResourceGroups.ListAsync();
54-
if (resourceGroups.Wait(TimeSpan.FromSeconds(_timeout)))
54+
55+
if (_timeout == -1)
56+
{
57+
resourceGroups.Wait();
58+
tempResourceGroupList = CreateResourceGroupList(resourceGroups.Result);
59+
if (resourceGroups.Result != null)
60+
{
61+
_resourceGroupNamesDictionary[contextHash] = tempResourceGroupList;
62+
}
63+
}
64+
else if (resourceGroups.Wait(TimeSpan.FromSeconds(_timeout)))
5565
{
5666
tempResourceGroupList = CreateResourceGroupList(resourceGroups.Result);
5767
if (resourceGroups.Result != null)

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ protected static IList<String> ResourceTypes
5858
while (!string.IsNullOrEmpty(page.NextPageLink))
5959
{
6060
task = client.Providers.ListNextAsync(page.NextPageLink);
61-
if (task.Wait(TimeSpan.FromSeconds(_timeout)))
61+
62+
if (_timeout == -1)
63+
{
64+
task.Wait();
65+
page = task.Result;
66+
resourceTypes.AddRange(page);
67+
}
68+
else if (task.Wait(TimeSpan.FromSeconds(_timeout)))
6269
{
6370
page = task.Result;
6471
resourceTypes.AddRange(page);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ protected static IList<String> Scopes
4848
var client = AzureSession.Instance.ClientFactory.CreateArmClient<ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);
4949
// Retrieve only the first page of ResourceGroups to use for scopes
5050
var resourceGroups = client.ResourceGroups.ListAsync();
51-
if (resourceGroups.Wait(TimeSpan.FromSeconds(_timeout)))
51+
52+
if (_timeout == -1)
53+
{
54+
resourceGroups.Wait();
55+
tempScopeList = CreateScopeList(resourceGroups.Result, context.Subscription.Id);
56+
_scopeDictionary[contextHash] = tempScopeList;
57+
}
58+
else if (resourceGroups.Wait(TimeSpan.FromSeconds(_timeout)))
5259
{
5360
tempScopeList = CreateScopeList(resourceGroups.Result, context.Subscription.Id);
5461
_scopeDictionary[contextHash] = tempScopeList;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public ArgumentCompleterTests(ITestOutputHelper output)
3636
}
3737

3838
[Fact]
39-
[Trait(Category.AcceptanceType, Category.Flaky)]
39+
[Trait(Category.AcceptanceType, Category.CheckIn)]
4040
public void TestLocationCompleter()
4141
{
4242
ProfileController.NewInstance.RunPsTest(xunitLogger, "72f988bf-86f1-41af-91ab-2d7cd011db47", "Test-LocationCompleter");
4343
}
4444

4545
[Fact]
46-
[Trait(Category.AcceptanceType, Category.Flaky)]
46+
[Trait(Category.AcceptanceType, Category.CheckIn)]
4747
public void TestResourceGroupCompleter()
4848
{
4949
ProfileController.NewInstance.RunPsTest(xunitLogger, "72f988bf-86f1-41af-91ab-2d7cd011db47", "Test-ResourceGroupCompleter");

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, 60)
24+
$locations = [Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.LocationCompleterAttribute]::FindLocations($resourceTypes, -1)
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(60)
39+
$resourceGroups = [Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.ResourceGroupCompleterAttribute]::GetResourceGroups(-1)
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: 41 additions & 32 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)