Skip to content

Commit 9b0b3f8

Browse files
committed
Adding infrastructure to manage flaky check-in tests and applying to one flaky test
1 parent 17a3330 commit 9b0b3f8

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/Commands.ScenarioTests.ResourceManager.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
<Compile Include="PowerShellExtensions.cs" />
164164
<Compile Include="Properties\AssemblyInfo.cs" />
165165
<Compile Include="RMTestBase.cs" />
166+
<Compile Include="TestExecutionHelpers.cs" />
166167
<Compile Include="XunitTracingInterceptor.cs" />
167168
</ItemGroup>
168169
<ItemGroup>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
17+
18+
namespace Microsoft.Azure.Commands.ScenarioTest
19+
{
20+
public static class TestExecutionHelpers
21+
{
22+
/// <summary>
23+
/// Retry an action until it succeeds - use for flaky tests
24+
/// </summary>
25+
/// <param name="testAction">Action tor etry</param>
26+
/// <param name="maxTries">The maximum number of times to try the action</param>
27+
public static void RetryAction(Action testAction, int maxTries = 3)
28+
{
29+
var tries = 0;
30+
var succeeded = false;
31+
do
32+
{
33+
try
34+
{
35+
testAction();
36+
succeeded = true;
37+
}
38+
catch (Exception)
39+
{
40+
if (++tries < maxTries)
41+
{
42+
TestMockSupport.Delay(TimeSpan.FromSeconds(1));
43+
}
44+
else
45+
{
46+
throw;
47+
}
48+
}
49+
} while (!succeeded);
50+
}
51+
}
52+
}

src/ResourceManager/Resources/Commands.Resources.Test/Models.ResourceGroups/GalleryTemplatesClientTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System.Linq;
2727
using System.Management.Automation;
2828
using System.Security;
29+
using Microsoft.Azure.Commands.ScenarioTest;
2930
using Newtonsoft.Json.Linq;
3031
using Xunit;
3132
using Xunit.Abstractions;
@@ -498,10 +499,14 @@ public void HandlesInvalidTemplateFiles()
498499
[Trait(Category.AcceptanceType, Category.CheckIn)]
499500
public void ParseTemplateParameterFileContents_DeserializeWithCorrectType()
500501
{
501-
Dictionary<string, TemplateFileParameterV1> result =
502-
TemplateUtility.ParseTemplateParameterFileContents(@"Resources\WebSite.param.dev.json");
503-
Assert.Equal(true, result["isWorker"].Value);
504-
Assert.Equal((System.Int64)1, result["numberOfWorker"].Value);
502+
// Add up to 3 retries for flaky test
503+
TestExecutionHelpers.RetryAction(() =>
504+
{
505+
Dictionary<string, TemplateFileParameterV1> result =
506+
TemplateUtility.ParseTemplateParameterFileContents(@"Resources\WebSite.param.dev.json");
507+
Assert.Equal(true, result["isWorker"].Value);
508+
Assert.Equal((System.Int64) 1, result["numberOfWorker"].Value);
509+
});
505510
}
506511
}
507512
}

src/ResourceManager/Resources/Resources.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio 2013
3-
VisualStudioVersion = 12.0.31101.0
2+
# Visual Studio 14
3+
VisualStudioVersion = 14.0.25123.0
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{95C16AED-FD57-42A0-86C3-2CF4300A4817}"
66
EndProject

0 commit comments

Comments
 (0)