Skip to content

Commit 5661c41

Browse files
authored
Add baseline version test (#7627)
1 parent 4f2a0ed commit 5661c41

File tree

5 files changed

+206
-0
lines changed

5 files changed

+206
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.IO;
6+
using McMaster.Extensions.CommandLineUtils;
7+
8+
namespace Microsoft.Extensions.Tools.Internal
9+
{
10+
public class ConsoleReporter : IReporter
11+
{
12+
private object _writeLock = new object();
13+
14+
public ConsoleReporter(IConsole console)
15+
: this(console, verbose: false, quiet: false)
16+
{ }
17+
18+
public ConsoleReporter(IConsole console, bool verbose, bool quiet)
19+
{
20+
Console = console;
21+
IsVerbose = verbose;
22+
IsQuiet = quiet;
23+
}
24+
25+
protected IConsole Console { get; }
26+
public bool IsVerbose { get; }
27+
public bool IsQuiet { get; }
28+
29+
protected virtual void WriteLine(TextWriter writer, string message, ConsoleColor? color)
30+
{
31+
lock (_writeLock)
32+
{
33+
if (color.HasValue)
34+
{
35+
Console.ForegroundColor = color.Value;
36+
}
37+
38+
writer.WriteLine(message);
39+
40+
if (color.HasValue)
41+
{
42+
Console.ResetColor();
43+
}
44+
}
45+
}
46+
47+
public virtual void Error(string message)
48+
=> WriteLine(Console.Error, message, ConsoleColor.Red);
49+
public virtual void Warn(string message)
50+
=> WriteLine(Console.Out, message, ConsoleColor.Yellow);
51+
52+
public virtual void Output(string message)
53+
{
54+
if (IsQuiet)
55+
{
56+
return;
57+
}
58+
WriteLine(Console.Out, message, color: null);
59+
}
60+
61+
public virtual void Verbose(string message)
62+
{
63+
if (!IsVerbose)
64+
{
65+
return;
66+
}
67+
68+
WriteLine(Console.Out, message, ConsoleColor.DarkGray);
69+
}
70+
}
71+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using McMaster.Extensions.CommandLineUtils;
7+
8+
namespace TriageBuildFailures
9+
{
10+
internal static class RetryHelpers
11+
{
12+
/// <summary>
13+
/// Constrain the exponential back-off to this many minutes.
14+
/// </summary>
15+
private const int MaxRetryMinutes = 15;
16+
17+
private static int TotalRetriesUsed;
18+
19+
public static int GetTotalRetriesUsed()
20+
{
21+
return TotalRetriesUsed;
22+
}
23+
24+
public static async Task RetryAsync(Func<Task> action, IReporter reporter)
25+
{
26+
await RetryAsync<object>(
27+
async () =>
28+
{
29+
await action();
30+
return null;
31+
},
32+
reporter);
33+
}
34+
35+
public static async Task<T> RetryAsync<T>(Func<Task<T>> action, IReporter reporter)
36+
{
37+
Exception firstException = null;
38+
39+
var retriesRemaining = 10;
40+
var retryDelayInMinutes = 1;
41+
42+
while (retriesRemaining > 0)
43+
{
44+
try
45+
{
46+
return await action();
47+
}
48+
catch (Exception e)
49+
{
50+
firstException = firstException ?? e;
51+
reporter.Output($"Exception thrown! {e.Message}");
52+
reporter.Output($"Waiting {retryDelayInMinutes} minute(s) to retry ({retriesRemaining} left)...");
53+
await Task.Delay(retryDelayInMinutes * 60 * 1000);
54+
55+
// Do exponential back-off, but limit it (1, 2, 4, 8, 15, 15, 15, ...)
56+
// With MaxRetryMinutes=15 and MaxRetries=10, this will delay a maximum of 105 minutes
57+
retryDelayInMinutes = Math.Min(2 * retryDelayInMinutes, MaxRetryMinutes);
58+
retriesRemaining--;
59+
TotalRetriesUsed++;
60+
}
61+
}
62+
throw new InvalidOperationException("Max exception retries reached, giving up.", firstException);
63+
}
64+
}
65+
}

test/SharedFx.UnitTests/SharedFx.UnitTests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<_Parameter1>MicrosoftNETCoreAppPackageVersion</_Parameter1>
2727
<_Parameter2>$(RuntimeFrameworkVersion)</_Parameter2>
2828
</AssemblyAttribute>
29+
<AssemblyAttribute Include="Microsoft.AspNetCore.TestData">
30+
<_Parameter1>PreviousAspNetCoreReleaseVersion</_Parameter1>
31+
<_Parameter2>$(PreviousAspNetCoreReleaseVersion)</_Parameter2>
32+
</AssemblyAttribute>
2933
</ItemGroup>
3034

3135
<ItemGroup>
@@ -34,6 +38,7 @@
3438
<PackageReference Include="xunit" Version="$(XunitPackageVersion)" />
3539
<PackageReference Include="xunit.analyzers" Version="$(XunitAnalyzersPackageVersion)" />
3640
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualstudioPackageVersion)" />
41+
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.2.2" />
3742
</ItemGroup>
3843

3944
</Project>

test/SharedFx.UnitTests/SharedFxTests.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,77 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
5+
using System.Collections.Generic;
46
using System.IO;
7+
using System.IO.Compression;
8+
using System.Net;
9+
using System.Reflection;
10+
using System.Threading.Tasks;
11+
using McMaster.Extensions.CommandLineUtils;
512
using Newtonsoft.Json.Linq;
13+
using TriageBuildFailures;
614
using Xunit;
715

816
namespace Microsoft.AspNetCore
917
{
1018
public class SharedFxTests
1119
{
20+
21+
[Theory]
22+
[MemberData(nameof(GetSharedFxConfig))]
23+
public async Task BaselineTest(SharedFxConfig config)
24+
{
25+
var previousVersion = TestData.GetPreviousAspNetCoreReleaseVersion();
26+
var url = new Uri($"https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/" + previousVersion + "/aspnetcore-runtime-internal-" + previousVersion + "-win-x64.zip");
27+
var zipName = "assemblies.zip";
28+
var nugetAssemblyVersions = new Dictionary<string, Version>();
29+
var root = TestData.GetDotNetRoot();
30+
var dir = Path.Combine(root, "shared", config.Name, config.Version);
31+
32+
using (var testClient = new WebClient())
33+
{
34+
var reporter = new ConsoleReporter(PhysicalConsole.Singleton);
35+
await RetryHelpers.RetryAsync(async () => await testClient.DownloadFileTaskAsync(url, zipName), reporter);
36+
}
37+
38+
var zipPath = Path.Combine(AppContext.BaseDirectory, zipName);
39+
40+
if (!Directory.Exists(AppContext.BaseDirectory + "unzipped"))
41+
{
42+
ZipFile.ExtractToDirectory(AppContext.BaseDirectory, "unzipped");
43+
}
44+
45+
var nugetAssembliesPath = Path.Combine(AppContext.BaseDirectory, "unzipped", "shared", config.Name, previousVersion);
46+
47+
var files = Directory.GetFiles(nugetAssembliesPath, "*.dll");
48+
foreach (var file in files)
49+
{
50+
try
51+
{
52+
var assemblyVersion = AssemblyName.GetAssemblyName(file).Version;
53+
var dllName = Path.GetFileName(file);
54+
nugetAssemblyVersions.Add(dllName, assemblyVersion);
55+
}
56+
catch (BadImageFormatException) { }
57+
}
58+
59+
files = Directory.GetFiles(dir, "*.dll");
60+
61+
Assert.All(files, file =>
62+
{
63+
try
64+
{
65+
var localAssemblyVersion = AssemblyName.GetAssemblyName(file).Version;
66+
var dllName = Path.GetFileName(file);
67+
Assert.True(nugetAssemblyVersions.ContainsKey(dllName), $"Expected {dllName} to be in the downloaded dlls");
68+
Assert.True(localAssemblyVersion.CompareTo(nugetAssemblyVersions[dllName]) >= 0, $"Expected the local version of {dllName} to be greater than or equal to the already released version.");
69+
}
70+
catch (BadImageFormatException) { }
71+
72+
});
73+
}
74+
1275
[Theory]
1376
[MemberData(nameof(GetSharedFxConfig))]
1477
public void ItContainsValidRuntimeConfigFile(SharedFxConfig config)

test/SharedFx.UnitTests/TestData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class TestData
1010
{
1111
public static string GetPackageVersion() => GetTestDataValue("PackageVersion");
1212

13+
public static string GetPreviousAspNetCoreReleaseVersion() => GetTestDataValue("PreviousAspNetCoreReleaseVersion");
14+
1315
public static string GetMicrosoftNETCoreAppPackageVersion() => GetTestDataValue("MicrosoftNETCoreAppPackageVersion");
1416

1517
public static string GetDotNetRoot() => GetTestDataValue("DotNetRoot");

0 commit comments

Comments
 (0)