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

Share SingleFileTest publishing between test classes #45523

Merged
merged 5 commits into from
Dec 8, 2020
Merged
Changes from 1 commit
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
27 changes: 18 additions & 9 deletions src/installer/tests/TestUtils/TestArtifact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ public virtual void Dispose()
{
if (!PreserveTestRuns() && Directory.Exists(Location))
{
Directory.Delete(Location, true);
try
{
Directory.Delete(Location, true);

// Delete lock file last
Debug.Assert(!Directory.Exists(Location));
var lockPath = Directory.GetParent(Location) + ".lock";
File.Delete(lockPath);
} catch {}
agocke marked this conversation as resolved.
Show resolved Hide resolved
}

foreach (TestArtifact copy in _copies)
Expand All @@ -70,22 +78,23 @@ public virtual void Dispose()

protected static string GetNewTestArtifactPath(string artifactName)
{
var rand = new Random();

string path;
while (true)
{
path = Path.Combine(TestArtifactsPath, Path.GetRandomFileName(), artifactName);
Directory.CreateDirectory(path);
var lockPath = Path.Combine(path, ".lock");
var parentPath = Path.Combine(TestArtifactsPath, Path.GetRandomFileName());
// Create a lock file next to the target folder
var lockPath = parentPath + ".lock";
var artifactPath = Path.Combine(parentPath, artifactName);
try
{
File.Open(lockPath, FileMode.CreateNew, FileAccess.Write).Dispose();
return path;
} catch
}
catch
{
// Lock file cannot be created, potential collision
agocke marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
Directory.CreateDirectory(artifactPath);
return artifactPath;
}
}

Expand Down