Skip to content

Commit

Permalink
Fix a Race in Installer Test Infrastructure (#38143)
Browse files Browse the repository at this point in the history
* Re-enable Apphost.Bundle.Tests.BundleRename test

* Remove StaticHostApp

StaticHostTest used the StaticHostApp (which is effectively a copy of StandaloneApp) as a work-around for synchronization problems.
Remove this work-around.

* Synchronize GetNewTestArtifactPath()

Add locking around GetNewTestArtifactPath() so that multiple threads attempting to create new copies of a TextFixture don't collide and work on the same path.
  • Loading branch information
swaroop-sridhar authored Jun 23, 2020
1 parent e84507a commit a755e74
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 43 deletions.
16 changes: 0 additions & 16 deletions src/installer/tests/Assets/TestProjects/StaticHostApp/Program.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public BundleRename(SharedTestState fixture)
}

[Theory]
[ActiveIssue("https://github.com/dotnet/runtime/issues/38013")]
[InlineData(true)] // Test renaming the single-exe when contents are extracted
[InlineData(false)] // Test renaming the single-exe when contents are not extracted
private void Bundle_can_be_renamed_while_running(bool testExtraction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class SharedTestState : IDisposable
public SharedTestState()
{
RepoDirectories = new RepoDirectoriesProvider();
TestFixture = new TestProjectFixture("StaticHostApp", RepoDirectories);
TestFixture = new TestProjectFixture("StandaloneApp", RepoDirectories);
TestFixture
.EnsureRestoredForRid(TestFixture.CurrentRid, RepoDirectories.CorehostPackages)
.PublishProject(runtime: TestFixture.CurrentRid,
Expand Down
3 changes: 0 additions & 3 deletions src/installer/tests/TestUtils/TestApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.DotNet.CoreSetup.Test.HostActivation;
using System.IO;

namespace Microsoft.DotNet.CoreSetup.Test
Expand Down Expand Up @@ -37,8 +36,6 @@ public TestApp(TestApp source)
public static TestApp CreateEmpty(string name)
{
string location = GetNewTestArtifactPath(name);
FileUtils.EnsureDirectoryExists(location);

return new TestApp(location);
}

Expand Down
21 changes: 12 additions & 9 deletions src/installer/tests/TestUtils/TestArtifact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.DotNet.CoreSetup.Test.HostActivation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;

namespace Microsoft.DotNet.CoreSetup.Test
{
Expand Down Expand Up @@ -67,25 +69,26 @@ public virtual void Dispose()
_copies.Clear();
}

private static readonly object _pathCountLock = new object();
protected static string GetNewTestArtifactPath(string artifactName)
{
int projectCount = 0;
string projectDirectory = Path.Combine(TestArtifactsPath, projectCount.ToString(), artifactName);
string projectCountDir() => Path.Combine(TestArtifactsPath, projectCount.ToString(), artifactName);

while (Directory.Exists(projectDirectory))
for (; Directory.Exists(projectCountDir()); projectCount++);

lock (_pathCountLock)
{
projectDirectory = Path.Combine(TestArtifactsPath, (++projectCount).ToString(), artifactName);
string projectDirectory;
for (; Directory.Exists(projectDirectory = projectCountDir()); projectCount++);
FileUtils.EnsureDirectoryExists(projectDirectory);
return projectDirectory;
}

return projectDirectory;
}

protected static void CopyRecursive(string sourceDirectory, string destinationDirectory, bool overwrite = false)
{
if (!Directory.Exists(destinationDirectory))
{
Directory.CreateDirectory(destinationDirectory);
}
FileUtils.EnsureDirectoryExists(destinationDirectory);

foreach (var dir in Directory.EnumerateDirectories(sourceDirectory))
{
Expand Down

0 comments on commit a755e74

Please sign in to comment.