Skip to content

Commit 563a488

Browse files
mikaelm12dougbu
authored andcommitted
Add baseline test (#7988)
- mostly matching what's in `release/2.2`
1 parent e8feafa commit 563a488

File tree

5 files changed

+213
-0
lines changed

5 files changed

+213
-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+
}

src/Framework/Framework.UnitTests/Framework.UnitTests.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@
2323
<_Parameter1>MicrosoftNETCoreAppPackageVersion</_Parameter1>
2424
<_Parameter2>$(RuntimeFrameworkVersion)</_Parameter2>
2525
</AssemblyAttribute>
26+
<AssemblyAttribute Include="Microsoft.AspNetCore.TestData">
27+
<_Parameter1>PreviousAspNetCoreReleaseVersion</_Parameter1>
28+
<_Parameter2>$(PreviousAspNetCoreReleaseVersion)</_Parameter2>
29+
</AssemblyAttribute>
2630
</ItemGroup>
2731

2832
<ItemGroup>
2933
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
34+
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.2.2" />
3035
</ItemGroup>
3136

3237
<ItemGroup>
@@ -42,6 +47,10 @@
4247
<_Parameter1>SharedFxMetadataOutput:%(_ResolvedFrameworkReference.SharedFxName)</_Parameter1>
4348
<_Parameter2>%(_ResolvedFrameworkReference.MetadataOutputPath)</_Parameter2>
4449
</AssemblyAttribute>
50+
<AssemblyAttribute Include="Microsoft.AspNetCore.TestData" Condition="'%(_ResolvedFrameworkReference.Identity)' != ''">
51+
<_Parameter1>RuntimeAssetsOutputPath:%(_ResolvedFrameworkReference.SharedFxName)</_Parameter1>
52+
<_Parameter2>%(_ResolvedFrameworkReference.RuntimeAssetsOutputPath)</_Parameter2>
53+
</AssemblyAttribute>
4554
</ItemGroup>
4655
</Target>
4756

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+
}

src/Framework/Framework.UnitTests/SharedFxTests.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,80 @@
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+
[Theory]
21+
[MemberData(nameof(GetSharedFxConfig))]
22+
public async Task BaselineTest(SharedFxConfig config)
23+
{
24+
var previousVersion = TestData.GetPreviousAspNetCoreReleaseVersion();
25+
var url = new Uri($"https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/" + previousVersion + "/aspnetcore-runtime-internal-" + previousVersion + "-win-x64.zip");
26+
var zipName = "assemblies.zip";
27+
var nugetAssemblyVersions = new Dictionary<string, Version>();
28+
var dir = TestData.GetTestDataValue($"RuntimeAssetsOutputPath:{config.Name}");
29+
30+
using (var testClient = new WebClient())
31+
{
32+
var reporter = new ConsoleReporter(PhysicalConsole.Singleton);
33+
await RetryHelpers.RetryAsync(async () => await testClient.DownloadFileTaskAsync(url, zipName), reporter);
34+
}
35+
36+
var zipPath = Path.Combine(AppContext.BaseDirectory, zipName);
37+
var tempDirectoryPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
38+
try
39+
{
40+
Directory.CreateDirectory(tempDirectoryPath);
41+
ZipFile.ExtractToDirectory(zipPath, tempDirectoryPath);
42+
var nugetAssembliesPath = Path.Combine(tempDirectoryPath, "shared", config.Name, previousVersion);
43+
44+
45+
var files = Directory.GetFiles(nugetAssembliesPath, "*.dll");
46+
foreach (var file in files)
47+
{
48+
try
49+
{
50+
var assemblyVersion = AssemblyName.GetAssemblyName(file).Version;
51+
var dllName = Path.GetFileName(file);
52+
nugetAssemblyVersions.Add(dllName, assemblyVersion);
53+
}
54+
catch (BadImageFormatException) { }
55+
}
56+
57+
files = Directory.GetFiles(dir, "*.dll");
58+
59+
Assert.All(files, file =>
60+
{
61+
try
62+
{
63+
var localAssemblyVersion = AssemblyName.GetAssemblyName(file).Version;
64+
var dllName = Path.GetFileName(file);
65+
Assert.Contains(dllName, nugetAssemblyVersions.Keys);
66+
Assert.InRange(localAssemblyVersion.CompareTo(nugetAssemblyVersions[dllName]), 0, int.MaxValue);
67+
}
68+
catch (BadImageFormatException) { }
69+
70+
});
71+
}
72+
finally
73+
{
74+
Directory.Delete(tempDirectoryPath, true);
75+
}
76+
}
77+
1278
[Theory]
1379
[MemberData(nameof(GetSharedFxConfig))]
1480
public void ItContainsValidRuntimeConfigFile(SharedFxConfig config)

src/Framework/Framework.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 GetRepositoryCommit() => GetTestDataValue("RepositoryCommit");

0 commit comments

Comments
 (0)