Merge in 'release/6.0.2xx' changes

This commit is contained in:
dotnet-bot 2022-03-24 13:32:51 +00:00
commit 54d7bf5f29
9 changed files with 112 additions and 30 deletions

View file

@ -87,11 +87,11 @@ steps:
set -x
# Use installer repo's NuGet.config during online testing to utilize internal feeds
rm -f ${{ parameters.tarballDir }}/test/Microsoft.DotNet.SourceBuild.SmokeTests/assets/smoke-tests/online.NuGet.Config
cp $(Build.SourcesDirectory)/NuGet.config ${{ parameters.tarballDir }}/test/Microsoft.DotNet.SourceBuild.SmokeTests/assets/smoke-tests/online.NuGet.Config
rm -f ${{ parameters.tarballDir }}/test/Microsoft.DotNet.SourceBuild.SmokeTests/assets/online.NuGet.Config
cp $(Build.SourcesDirectory)/NuGet.config ${{ parameters.tarballDir }}/test/Microsoft.DotNet.SourceBuild.SmokeTests/assets/online.NuGet.Config
dockerVolumeArgs="-v ${{ parameters.tarballDir }}:/tarball"
dockerEnvArgs="-e SMOKE_TESTS_EXCLUDE_OMNISHARP=${{ parameters.excludeOmniSharpTests}}"
dockerEnvArgs="-e SMOKE_TESTS_EXCLUDE_OMNISHARP=${{ parameters.excludeOmniSharpTests}} -e SMOKE_TESTS_WARN_SDK_CONTENT_DIFFS=true"
if [[ '${{ parameters.isBootstrapped }}' != 'true' && '${{ parameters.installerBuildResourceId }}' != 'current' ]]; then
dockerVolumeArgs+=" -v $(PIPELINE.WORKSPACE)/${{ parameters.installerBuildResourceId }}/BlobArtifacts/:/BlobArtifacts"
@ -99,7 +99,7 @@ steps:
dockerEnvArgs+=" -e SMOKE_TESTS_MSFT_SDK_TARBALL_PATH=/BlobArtifacts/$msftSdkTarballName"
fi
docker run --rm $dockerVolumeArgs -w /tarball $dockerEnvArgs ${{ parameters.container }} ./build.sh --run-smoke-test ${{ parameters.additionalBuildArgs }}
docker run --rm $dockerVolumeArgs -w /tarball $dockerEnvArgs ${{ parameters.container }} ./build.sh --run-smoke-test ${{ parameters.additionalBuildArgs }} -- /p:SmokeTestConsoleVerbosity=detailed
displayName: Run Tests
# Don't use CopyFiles@2 as it encounters permissions issues because it indexes all files in the source directory graph.

View file

@ -93,9 +93,11 @@
<PropertyGroup>
<SdkTarballPath>%(SdkTarballItem.Identity)</SdkTarballPath>
<SmokeTestConsoleVerbosity Condition="'$(SmokeTestConsoleVerbosity)' == ''">normal</SmokeTestConsoleVerbosity>
</PropertyGroup>
<Exec Command="$(DotnetToolCommand) test $(SmokeTestsDir) --logger:trx -c $(Configuration)"
<!-- Multiple loggers are specified so that results are captured in trx and pipelines can fail with AzDO pipeline warnings -->
<Exec Command="$(DotnetToolCommand) test $(SmokeTestsDir) --logger:trx --logger:'console;verbosity=$(SmokeTestConsoleVerbosity)' -c $(Configuration)"
EnvironmentVariables="
SMOKE_TESTS_SDK_TARBALL_PATH=$(SdkTarballPath);
SMOKE_TESTS_TARGET_RID=$(TargetRid);

View file

@ -114,14 +114,14 @@ restoredPackagesDir="$SCRIPT_ROOT/packages/restored"
if [ -d "$SCRIPT_ROOT/packages/archive" ]; then
sourceBuiltArchive=`find $SCRIPT_ROOT/packages/archive -maxdepth 1 -name 'Private.SourceBuilt.Artifacts*.tar.gz'`
if [ -f "$sourceBuiltArchive" ]; then
if [ -f "$SCRIPT_ROOT/packages/previously-source-built/PackageVersions.props" ]; then
packageVersionsPath=$SCRIPT_ROOT/packages/previously-source-built/PackageVersions.props
elif [ -f "$sourceBuiltArchive" ]; then
tar -xzf "$sourceBuiltArchive" -C /tmp PackageVersions.props
packageVersionsPath=/tmp/PackageVersions.props
fi
else
if [ -f "$CUSTOM_PREVIOUSLY_BUILT_PACKAGES_DIR/PackageVersions.props" ]; then
packageVersionsPath="$CUSTOM_PREVIOUSLY_BUILT_PACKAGES_DIR/PackageVersions.props"
fi
elif [ -f "$CUSTOM_PREVIOUSLY_BUILT_PACKAGES_DIR/PackageVersions.props" ]; then
packageVersionsPath="$CUSTOM_PREVIOUSLY_BUILT_PACKAGES_DIR/PackageVersions.props"
fi
if [ ! -f "$packageVersionsPath" ]; then

View file

@ -34,17 +34,17 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
Assert.Null(message);
}
public static void CompareContents(string baselineFileName, string actualContents, ITestOutputHelper outputHelper)
public static void CompareContents(string baselineFileName, string actualContents, ITestOutputHelper outputHelper, bool warnOnDiffs = false)
{
string baselineFilePath = GetBaselineFilePath(baselineFileName);
string actualFilePath = Path.Combine(Environment.CurrentDirectory, $"{baselineFileName}");
File.WriteAllText(actualFilePath, actualContents);
CompareFiles(baselineFilePath, actualFilePath, outputHelper);
CompareFiles(baselineFilePath, actualFilePath, outputHelper, warnOnDiffs);
}
public static void CompareFiles(string baselineFilePath, string actualFilePath, ITestOutputHelper outputHelper)
public static void CompareFiles(string baselineFilePath, string actualFilePath, ITestOutputHelper outputHelper, bool warnOnDiffs = false)
{
string baselineFileText = File.ReadAllText(baselineFilePath);
string actualFileText = File.ReadAllText(actualFilePath);
@ -55,11 +55,21 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
{
// Retrieve a diff in order to provide a UX which calls out the diffs.
string diff = DiffFiles(baselineFilePath, actualFilePath, outputHelper);
message = $"{Environment.NewLine}Baseline '{baselineFilePath}' does not match actual '{actualFilePath}`. {Environment.NewLine}"
string prefix = warnOnDiffs ? "##vso[task.logissue type=warning;]" : string.Empty;
message = $"{Environment.NewLine}{prefix}Baseline '{baselineFilePath}' does not match actual '{actualFilePath}`. {Environment.NewLine}"
+ $"{diff}{Environment.NewLine}";
if (warnOnDiffs)
{
outputHelper.WriteLine(message);
outputHelper.WriteLine("##vso[task.complete result=SucceededWithIssues;]");
}
}
Assert.Null(message);
if (!warnOnDiffs)
{
Assert.Null(message);
}
}
public static string DiffFiles(string file1Path, string file2Path, ITestOutputHelper outputHelper)

View file

@ -15,6 +15,7 @@ internal static class Config
public const string PrereqsPathEnv = "SMOKE_TESTS_PREREQS_PATH";
public const string SdkTarballPathEnv = "SMOKE_TESTS_SDK_TARBALL_PATH";
public const string TargetRidEnv = "SMOKE_TESTS_TARGET_RID";
public const string WarnSdkContentDiffsEnv = "SMOKE_TESTS_WARN_SDK_CONTENT_DIFFS";
public static string DotNetDirectory { get; } =
Environment.GetEnvironmentVariable(DotNetDirectoryEnv) ?? Path.Combine(Directory.GetCurrentDirectory(), ".dotnet");
@ -23,4 +24,6 @@ internal static class Config
public static string? SdkTarballPath { get; } = Environment.GetEnvironmentVariable(SdkTarballPathEnv);
public static string TargetRid { get; } = Environment.GetEnvironmentVariable(TargetRidEnv) ??
throw new InvalidOperationException($"'{Config.TargetRidEnv}' must be specified");
public static bool WarnOnSdkContentDiffs { get; } =
bool.TryParse(Environment.GetEnvironmentVariable(WarnSdkContentDiffsEnv), out bool excludeOnlineTests) && excludeOnlineTests;
}

View file

@ -79,14 +79,25 @@ internal class DotNetHelper
}
}
public void ExecuteCmd(string args, string? workingDirectory = null)
public void ExecuteCmd(string args, string? workingDirectory = null, Action<Process>? additionalProcessConfigCallback = null, int expectedExitCode = 0, int millisecondTimeout = -1)
{
Action<Process, string?> configureProcess = (Process process, string? workingDirectory) => {
ConfigureProcess(process, workingDirectory);
if (additionalProcessConfigCallback != null)
{
additionalProcessConfigCallback(process);
}
};
(Process Process, string StdOut, string StdErr) executeResult = ExecuteHelper.ExecuteProcess(
DotNetPath,
args,
OutputHelper,
configure: (process) => ConfigureProcess(process, workingDirectory));
ExecuteHelper.ValidateExitCode(executeResult);
configure: (process) => configureProcess(process, workingDirectory),
millisecondTimeout: millisecondTimeout);
ExecuteHelper.ValidateExitCode(executeResult, expectedExitCode);
}
public static void ConfigureProcess(Process process, string? workingDirectory, bool setPath = false)
@ -170,18 +181,14 @@ internal class DotNetHelper
public void ExecuteRunWeb(string projectName)
{
(Process Process, string StdOut, string StdErr) executeResult = ExecuteHelper.ExecuteProcess(
DotNetPath,
ExecuteCmd(
$"run {GetBinLogOption(projectName, "run")}",
OutputHelper,
configure: configureProcess,
GetProjectDirectory(projectName),
additionalProcessConfigCallback: processConfigCallback,
millisecondTimeout: 30000);
ExecuteHelper.ValidateExitCode(executeResult);
void configureProcess(Process process)
void processConfigCallback(Process process)
{
ConfigureProcess(process, GetProjectDirectory(projectName));
process.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
if (e.Data?.Contains("Application started. Press Ctrl+C to shut down.") ?? false)

View file

@ -0,0 +1,60 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using System.IO;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
public class DotNetWatchTests : SmokeTests
{
public DotNetWatchTests(ITestOutputHelper outputHelper) : base(outputHelper) { }
[Fact]
public void WatchTests()
{
string projectDirectory = DotNetHelper.ExecuteNew(DotNetTemplate.Console.GetName(), nameof(DotNetWatchTests));
bool outputChanged = false;
// We expect an exit code of 143 (128 + 15, i.e. SIGTERM) because we are killing the process manually
DotNetHelper.ExecuteCmd(
"watch run",
workingDirectory: projectDirectory,
additionalProcessConfigCallback: processConfigCallback,
expectedExitCode: 143,
millisecondTimeout: 30000);
Assert.True(outputChanged);
void processConfigCallback(Process process)
{
const string waitingString = "Waiting for a file to change before restarting dotnet...";
const string expectedString = "Hello from dotnet watch!";
bool fileChanged = false;
process.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
if (e.Data?.Contains(waitingString) ?? false)
{
if (!fileChanged) {
OutputHelper.WriteLine("Program started, changing file on disk to trigger restart...");
File.WriteAllText(
Path.Combine(projectDirectory, "Program.cs"),
File.ReadAllText(Path.Combine(projectDirectory, "Program.cs")).Replace("Hello, World!", expectedString));
fileChanged = true;
}
}
else if (e.Data?.Contains(expectedString) ?? false)
{
outputChanged = true;
OutputHelper.WriteLine("Successfully re-ran program after code change.");
ExecuteHelper.ExecuteProcessValidateExitCode("kill", $"-s TERM {process.Id}", OutputHelper);
}
});
}
}
}

View file

@ -84,9 +84,9 @@ internal static class ExecuteHelper
return result.StdOut;
}
public static void ValidateExitCode((Process Process, string StdOut, string StdErr) result)
public static void ValidateExitCode((Process Process, string StdOut, string StdErr) result, int expectedExitCode = 0)
{
if (result.Process.ExitCode != 0)
if (result.Process.ExitCode != expectedExitCode)
{
ProcessStartInfo startInfo = result.Process.StartInfo;
string msg = $"Failed to execute {startInfo.FileName} {startInfo.Arguments}" +

View file

@ -22,7 +22,7 @@ public class SdkContentTests : SmokeTests
/// This makes the baseline durable between releases. This does mean however, entries
/// in the baseline may appear identical if the diff is version specific.
/// </Summary>
[SkippableFact(new[] { Config.MsftSdkTarballPathEnv, Config.MsftSdkTarballPathEnv }, skipOnNullOrWhiteSpace: true)]
[SkippableFact(new[] { Config.MsftSdkTarballPathEnv, Config.SdkTarballPathEnv }, skipOnNullOrWhiteSpace: true)]
public void CompareMsftToSb()
{
const string msftFileListingFileName = "msftSdkFiles.txt";
@ -34,7 +34,7 @@ public class SdkContentTests : SmokeTests
diff = RemoveVersionedPaths(diff);
diff = RemoveDiffMarkers(diff);
diff = RemoveRids(diff);
BaselineHelper.CompareContents("MsftToSbSdk.diff", diff, OutputHelper);
BaselineHelper.CompareContents("MsftToSbSdk.diff", diff, OutputHelper, Config.WarnOnSdkContentDiffs);
}
private void WriteTarballFileList(string? tarballPath, string outputFileName)