Skip to content

Commit

Permalink
Port Error on duplicate test output dirs #16521
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoslund committed Apr 7, 2021
1 parent 7118f5b commit f28a004
Showing 65 changed files with 252 additions and 201 deletions.
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@
<DisableImplicitPackageTargetFallback>true</DisableImplicitPackageTargetFallback>

<!-- <ArtifactsShippingSymbolsDir>$(ArtifactsDir)symbols\$(Configuration)\Shipping</ArtifactsShippingSymbolsDir> -->

<DefineConstants Condition="'$(ContinuousIntegrationBuild)' == 'true'">$(DefineConstants);CI_BUILD</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
Original file line number Diff line number Diff line change
@@ -104,9 +104,9 @@ public GivenAnSlnFile(ITestOutputHelper log) : base(log)
{
}

private string CreateFile([CallerMemberName] string callerName = null)
private string CreateFile([CallerMemberName] string callerName = null, string identifier = null)
{
var folder = _testAssetsManager.CreateTestDirectory(testName: callerName);
var folder = _testAssetsManager.CreateTestDirectory(testName: callerName + identifier);
var filename = Path.Combine(folder.Path, Guid.NewGuid().ToString() + ".tmp");
using (new FileStream(filename, FileMode.CreateNew)) { }
return filename;
@@ -324,7 +324,7 @@ public void WhenGivenAValidSlnFileItModifiesSavesAndVerifiesContents()
[InlineData("First Line\nSecondLine\nMicrosoft Visual Studio Solution File, Format Version \nFourth Line", 3)]
public void WhenGivenASolutionWithMissingHeaderVersionItThrows(string fileContents, int lineNum)
{
var tmpFile = CreateFile();
var tmpFile = CreateFile(identifier: fileContents.GetHashCode().ToString());
File.WriteAllText(tmpFile, fileContents);

Action action = () =>
@@ -342,7 +342,7 @@ public void WhenGivenASolutionWithMissingHeaderVersionItThrows(string fileConten
[InlineData("Microsoft Visual\nStudio Solution File,\nFormat Version ")]
public void WhenGivenASolutionWithMissingHeaderItThrows(string fileContents)
{
var tmpFile = CreateFile();
var tmpFile = CreateFile(identifier: fileContents.GetHashCode().ToString());
File.WriteAllText(tmpFile, fileContents);

Action action = () =>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Net;
using System.Runtime.CompilerServices;
using System.Threading;
using FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
@@ -19,16 +20,11 @@ public class SenderTests : SdkTest

private Mock<BaseStorageService> StorageBaseMock { get; }

private SenderUnderTest Sender { get; }

public SenderTests(ITestOutputHelper log) : base(log)
{
StorageBaseMock = new Mock<BaseStorageService>();
TransmissionMock = new Mock<StorageTransmission>(string.Empty, new Uri("http://some/url"), new byte[] { },
string.Empty, string.Empty);
StorageService storageService = CreateStorageService();
PersistenceTransmitter transmitter = new PersistenceTransmitter(storageService, 0);
Sender = new SenderUnderTest(StorageBaseMock.Object, transmitter);
_deleteCount = 0;
StorageBaseMock.Setup(storage => storage.Delete(It.IsAny<StorageTransmission>()))
.Callback(() => _deleteCount++);
@@ -37,6 +33,7 @@ public SenderTests(ITestOutputHelper log) : base(log)
[Fact]
public void WhenServerReturn503TransmissionWillBeRetried()
{
var Sender = GetSenderUnderTest();
int peekCounts = 0;

// Setup transmission.SendAsync() to throw WebException that has 503 status Code
@@ -63,6 +60,7 @@ public void WhenServerReturn503TransmissionWillBeRetried()
[Fact]
public void WhenServerReturn400IntervalWillBe10Seconds()
{
var Sender = GetSenderUnderTest();
int peekCounts = 0;

// Setup transmission.SendAsync() to throw WebException that has 400 status Code
@@ -104,6 +102,7 @@ public void DisposeDoesNotThrow()
[Fact]
public void WhenServerReturnDnsErrorRequestWillBeRetried()
{
var Sender = GetSenderUnderTest();
int peekCounts = 0;

// Setup transmission.SendAsync() to throw WebException with ProxyNameResolutionFailure failure
@@ -170,12 +169,19 @@ protected override bool Send(StorageTransmission transmission, ref TimeSpan next
}
}

private StorageService CreateStorageService()
private StorageService CreateStorageService([CallerMemberName] string testName = null)
{
string tempPath = Path.Combine(_testAssetsManager.CreateTestDirectory("TestStorageService").Path, Path.GetTempFileName());
string tempPath = Path.Combine(_testAssetsManager.CreateTestDirectory("TestStorageService", identifier: testName).Path, Path.GetTempFileName());
StorageService storageService = new StorageService();
storageService.Init(tempPath);
return storageService;
}

private SenderUnderTest GetSenderUnderTest([CallerMemberName] string testName = null)
{
StorageService storageService = CreateStorageService(testName);
PersistenceTransmitter transmitter = new PersistenceTransmitter(storageService, 0);
return new SenderUnderTest(StorageBaseMock.Object, transmitter);
}
}
}
Original file line number Diff line number Diff line change
@@ -27,17 +27,14 @@ namespace Microsoft.DotNet.ShellShim.Tests
{
public class ShellShimRepositoryTests : SdkTest
{
private Lazy<FilePath> _reusedHelloWorldExecutableDll;

public ShellShimRepositoryTests(ITestOutputHelper output) : base(output)
{
_reusedHelloWorldExecutableDll = new Lazy<FilePath>(() => MakeHelloWorldExecutableDll("reused"));
}

[Fact]
public void GivenAnExecutablePathItCanGenerateShimFile()
{
var outputDll = _reusedHelloWorldExecutableDll.Value;
var outputDll = MakeHelloWorldExecutableDll();
var pathToShim = GetNewCleanFolderUnderTempRoot();
ShellShimRepository shellShimRepository = ConfigBasicTestDependencyShellShimRepository(pathToShim);
var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName();
@@ -53,7 +50,7 @@ public void GivenAnExecutablePathItCanGenerateShimFile()
[Fact]
public void GivenAnExecutableAndRelativePathToShimPathItCanGenerateShimFile()
{
var outputDll = MakeHelloWorldExecutableDll("GivenAnExecutableAndRelativePath");
var outputDll = MakeHelloWorldExecutableDll();
// To reproduce the bug, dll need to be nested under the shim
var parentPathAsShimPath = outputDll.GetDirectoryPath().GetParentPath().GetParentPath().Value;
var relativePathToShim = Path.GetRelativePath(
@@ -80,7 +77,7 @@ private static ShellShimRepository ConfigBasicTestDependencyShellShimRepository(
[Fact]
public void GivenAnExecutablePathItCanGenerateShimFileInTransaction()
{
var outputDll = _reusedHelloWorldExecutableDll.Value;
var outputDll = MakeHelloWorldExecutableDll();
var pathToShim = GetNewCleanFolderUnderTempRoot();
var shellShimRepository = ConfigBasicTestDependencyShellShimRepository(pathToShim);
var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName();
@@ -101,7 +98,7 @@ public void GivenAnExecutablePathItCanGenerateShimFileInTransaction()
[Fact]
public void GivenAnExecutablePathDirectoryThatDoesNotExistItCanGenerateShimFile()
{
var outputDll = _reusedHelloWorldExecutableDll.Value;
var outputDll = MakeHelloWorldExecutableDll();
var testFolder = _testAssetsManager.CreateTestDirectory().Path;
var extraNonExistDirectory = Path.GetRandomFileName();
var shellShimRepository = new ShellShimRepository(new DirectoryPath(Path.Combine(testFolder, extraNonExistDirectory)), GetAppHostTemplateFromStage2());
@@ -118,7 +115,7 @@ public void GivenAnExecutablePathDirectoryThatDoesNotExistItCanGenerateShimFile(
[InlineData(" \"arg with ' quote\" ", new[] { "arg with ' quote" })]
public void GivenAShimItPassesThroughArguments(string arguments, string[] expectedPassThru)
{
var outputDll = _reusedHelloWorldExecutableDll.Value;
var outputDll = MakeHelloWorldExecutableDll(identifier: arguments);
var pathToShim = GetNewCleanFolderUnderTempRoot();
var shellShimRepository = ConfigBasicTestDependencyShellShimRepository(pathToShim);
var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName();
@@ -202,7 +199,7 @@ public void GivenAnExceptionItWillRollback(bool testMockBehaviorIsInSync)
TransactionScopeOption.Required,
TimeSpan.Zero))
{
FilePath targetExecutablePath = _reusedHelloWorldExecutableDll.Value;
FilePath targetExecutablePath = MakeHelloWorldExecutableDll(identifier: testMockBehaviorIsInSync.ToString());
shellShimRepository.CreateShim(targetExecutablePath, new ToolCommandName(shellCommandName));

intendedError();
@@ -259,7 +256,7 @@ public void GivenAnInstalledShimRemoveDeletesTheShimFiles(bool testMockBehaviorI

Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty();

FilePath targetExecutablePath = _reusedHelloWorldExecutableDll.Value;
FilePath targetExecutablePath = MakeHelloWorldExecutableDll(identifier: testMockBehaviorIsInSync.ToString());
shellShimRepository.CreateShim(targetExecutablePath, new ToolCommandName(shellCommandName));

Directory.EnumerateFileSystemEntries(pathToShim).Should().NotBeEmpty();
@@ -289,7 +286,7 @@ public void GivenAnInstalledShimRemoveRollsbackIfTransactionIsAborted(bool testM

Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty();

FilePath targetExecutablePath = _reusedHelloWorldExecutableDll.Value;
FilePath targetExecutablePath = MakeHelloWorldExecutableDll(identifier: testMockBehaviorIsInSync.ToString());
shellShimRepository.CreateShim(targetExecutablePath, new ToolCommandName(shellCommandName));

Directory.EnumerateFileSystemEntries(pathToShim).Should().NotBeEmpty();
@@ -326,7 +323,7 @@ public void GivenAnInstalledShimRemoveCommitsIfTransactionIsCompleted(bool testM

Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty();

FilePath targetExecutablePath = _reusedHelloWorldExecutableDll.Value;
FilePath targetExecutablePath = MakeHelloWorldExecutableDll(identifier: testMockBehaviorIsInSync.ToString());
shellShimRepository.CreateShim(targetExecutablePath, new ToolCommandName(shellCommandName));

Directory.EnumerateFileSystemEntries(pathToShim).Should().NotBeEmpty();
@@ -471,18 +468,11 @@ private static string GetAppHostTemplateFromStage2()
return stage2AppHostTemplateDirectory;
}

private FilePath MakeHelloWorldExecutableDll(string instanceName = null)
private FilePath MakeHelloWorldExecutableDll([CallerMemberName] string callingMethod = "", string identifier = null)
{
const string testAppName = "TestAppSimple";
const string emptySpaceToTestSpaceInPath = " ";
const string directoryNamePostFix = "Test";

if (instanceName == null)
{
instanceName = testAppName + emptySpaceToTestSpaceInPath + directoryNamePostFix;
}

var testInstance = _testAssetsManager.CopyTestAsset(testAppName, callingMethod: instanceName)
var testInstance = _testAssetsManager.CopyTestAsset(testAppName, callingMethod: callingMethod, identifier: identifier)
.WithSource();

new BuildCommand(testInstance)
Original file line number Diff line number Diff line change
@@ -101,7 +101,8 @@ public void GivenNugetConfigInstallSucceeds(bool testMockBehaviorIsInSync)

var (store, storeQuery, installer, uninstaller, reporter, fileSystem) = Setup(
useMock: testMockBehaviorIsInSync,
writeLocalFeedToNugetConfig: nugetConfigPath);
writeLocalFeedToNugetConfig: nugetConfigPath,
identiifer: testMockBehaviorIsInSync.ToString());

var package = installer.InstallPackage(new PackageLocation(nugetConfig: nugetConfigPath),
packageId: TestPackageId,
@@ -511,7 +512,8 @@ public void GivenAnInstalledPackageUninstallRemovesThePackage(bool testMockBehav

var (store, storeQuery, installer, uninstaller, reporter, fileSystem) = Setup(
useMock: testMockBehaviorIsInSync,
feeds: GetMockFeedsForSource(source));
feeds: GetMockFeedsForSource(source),
identiifer: testMockBehaviorIsInSync.ToString());

var package = installer.InstallPackage(new PackageLocation(additionalFeeds: new[] { source }),
packageId: TestPackageId,
@@ -875,9 +877,10 @@ private static List<MockFeed> GetOfflineMockFeed()
FilePath? tempProject = null,
DirectoryPath? offlineFeed = null,
FilePath? writeLocalFeedToNugetConfig = null,
[CallerMemberName] string callingMethod = "")
[CallerMemberName] string callingMethod = "",
string identiifer = null)
{
var root = new DirectoryPath(_testAssetsManager.CreateTestDirectory(callingMethod, identifier: useMock.ToString()).Path);
var root = new DirectoryPath(_testAssetsManager.CreateTestDirectory(callingMethod, identifier: useMock.ToString() + identiifer).Path);
var reporter = new BufferedReporter();

IFileSystem fileSystem;
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
using Microsoft.NET.TestFramework.Utilities;
using Microsoft.NET.TestFramework;
using Xunit.Abstractions;
using System.Runtime.CompilerServices;

namespace Microsoft.DotNet.ToolPackage.Tests
{
@@ -35,7 +36,8 @@ public void GivenAnInstalledPackageUninstallRemovesThePackage(bool testMockBehav

var (store, storeQuery, installer, uninstaller, reporter, fileSystem) = Setup(
useMock: testMockBehaviorIsInSync,
feeds: GetMockFeedsForSource(source));
feeds: GetMockFeedsForSource(source),
identifier: testMockBehaviorIsInSync.ToString());

var package = installer.InstallPackage(new PackageLocation(additionalFeeds: new[] { source }),
packageId: TestPackageId,
@@ -84,9 +86,11 @@ private static List<MockFeed> GetMockFeedsForSource(string source)
bool useMock,
List<MockFeed> feeds = null,
FilePath? tempProject = null,
DirectoryPath? offlineFeed = null)
DirectoryPath? offlineFeed = null,
[CallerMemberName] string testName = "",
string identifier = null)
{
var root = new DirectoryPath(_testAssetsManager.CreateTestDirectory("root").Path);
var root = new DirectoryPath(_testAssetsManager.CreateTestDirectory(testName, identifier).Path);
var reporter = new BufferedReporter();

IFileSystem fileSystem;
2 changes: 1 addition & 1 deletion src/Tests/Microsoft.NET.Build.Tests/AppHostTests.cs
Original file line number Diff line number Diff line change
@@ -137,7 +137,7 @@ public void It_uses_an_apphost_based_on_platform_target(string target)
var targetFramework = "netcoreapp3.0";

var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld")
.CopyTestAsset("HelloWorld", identifier: target)
.WithSource();

var buildCommand = new BuildCommand(testAsset);
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using Microsoft.NET.TestFramework.ProjectConstruction;
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;

namespace Microsoft.NET.Build.Tests
@@ -17,9 +18,9 @@ public class ConstantStringValues
public static string NetstandardTargetFrameworkIdentifier = ".NETStandard";
public static string DependencyDirectoryNamePrefix = "D_";

public static string ConstructNuGetPackageReferencePath(TestProject dependencyProject)
public static string ConstructNuGetPackageReferencePath(TestProject dependencyProject, string identifier, [CallerMemberName] string callingMethod = null)
{
return TestAssetsManager.GetTestDestinationDirectoryPath(dependencyProject.Name, TestDirectoriesNamePrefix, NuGetSharedDirectoryNamePostfix);
return TestAssetsManager.GetTestDestinationDirectoryPath(dependencyProject.Name, callingMethod, identifier);
}
}

2 changes: 1 addition & 1 deletion src/Tests/Microsoft.NET.Build.Tests/DepsFileSkipTests.cs
Original file line number Diff line number Diff line change
@@ -168,7 +168,7 @@ public void ResourceAssetFromPackageCanBeSkipped()

private void TestSkippingFile(TestProject testProject, string filenameToSkip, string assetType)
{
var testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name)
var testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name, identifier: filenameToSkip + assetType)
.WithProjectChanges(project => AddSkipTarget(project, filenameToSkip));

var buildCommand = new BuildCommand(testAsset);
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ public void Multiple_frameworks_are_written_to_runtimeconfig_for_self_contained_

testProject.SourceFiles.Add("Program.cs", FrameworkReferenceEmptyProgramSource);

TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject)
TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: tfm)
.Restore(Log, testProject.Name);

var buildCommand = new BuildCommand(testAsset);
@@ -346,7 +346,7 @@ public void RollForwardCanBeSpecifiedViaProperty(string rollForwardValue, string

testProject.AdditionalProperties["RollForward"] = rollForwardValue;

var testAsset = _testAssetsManager.CreateTestProject(testProject);
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: rollForwardValue + tfm);

var buildCommand = new BuildCommand(testAsset);

@@ -395,7 +395,7 @@ public void RollForwardIsNotSupportedOn22(string rollForwardValue, bool valid)

testProject.AdditionalProperties["RollForward"] = rollForwardValue;

var testAsset = _testAssetsManager.CreateTestProject(testProject);
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: rollForwardValue.GetHashCode().ToString());

var buildCommand = new BuildCommand(testAsset);

Loading

0 comments on commit f28a004

Please sign in to comment.