Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on duplicate test output dirs #16521

Merged
merged 2 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -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'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = () =>
Expand All @@ -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 = () =>
Expand Down
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;
Expand All @@ -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++);
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -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();
Expand All @@ -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(
Expand All @@ -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();
Expand All @@ -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());
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Microsoft.NET.Build.Tests/AppHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Microsoft.NET.Build.Tests/DepsFileSkipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Loading