Skip to content

Commit

Permalink
fix same file access exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ntovas committed Feb 15, 2022
1 parent 17cf142 commit 1a700a4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,30 @@ private void PopulateHtmlFile()
private string GetFilePath(string fileExtension, string fileName)
{
var fullFileFormat = $".{fileExtension}";
return Path.Combine(TestResultsDirPath, string.Concat("TestResult_", fileName, fullFileFormat));
string fullFilePath;
for (short i = 0; i < short.MaxValue; i++)
{
fileName = i == 0 ? fileName : GetNextIterationFile(fileName, i);
fullFilePath = Path.Combine(TestResultsDirPath, string.Concat("TestResult_", fileName, fullFileFormat));
if (!File.Exists(fullFilePath))
{
return fullFilePath;
}
}

throw new Exception($"Cannot generate unique filename for: {fileName}");
}

private string FormatDateTimeForRunName(DateTime timeStamp)
{
return timeStamp.ToString("yyyyMMdd_HHmmss", DateTimeFormatInfo.InvariantInfo);
}

private string GetNextIterationFile(string baseName, short iteration)
{
return $"{Path.GetFileNameWithoutExtension(baseName)}[{iteration}]{(Path.HasExtension(baseName) ? Path.GetExtension(baseName) : string.Empty)}";
}

/// <summary>
/// Gives the parent execution id of a TestResult.
/// </summary>
Expand Down

0 comments on commit 1a700a4

Please sign in to comment.