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

Fixed TRX file overwrite in certain circumstances #2508

Merged
16 commits merged into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
PR recommendations fixed.. v3
  • Loading branch information
Haplois committed Aug 4, 2020
commit 6c7ea2a9f4369bfb2ae384a0d32673072599a312
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ private static string GetNextIterationNameHelper(
Debug.Assert(!string.IsNullOrEmpty(originalName), "originalName is Null");
Debug.Assert(helper != null, "helper is null");

var rng = new Random();
uint iteration = 0;
do
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public class TrxLoggerTests
private Dictionary<string, string> parameters;
private static string DefaultTestRunDirectory = Path.GetTempPath();
private static string DefaultLogFileNameParameterValue = "logfilevalue.trx";
private static string DefaultLogFilePrefixParameterValue = "log_prefix-";
private const string DefaultLogFilePrefixParameterValue = "log_prefix";

private const int MultipleLoggerInstanceCount = 10;

[TestInitialize]
public void Initialize()
Expand Down Expand Up @@ -640,7 +642,14 @@ public void DefaultTrxFileShouldIterateIfLogFileNameParameterNotPassed()
{
this.parameters.Remove(TrxLoggerConstants.LogFileNameKey);

var loggers = new TestableTrxLogger[10];
var files = TestMultipleTrxLoggers(MultipleLoggerInstanceCount);

Assert.IsTrue(files.Length == MultipleLoggerInstanceCount, "All logger instances should get a seperate file name!");
}

private string[] TestMultipleTrxLoggers(int count)
{
var loggers = new TestableTrxLogger[count];
for (int i = 0; i < loggers.Length; i++)
{
loggers[i] = new TestableTrxLogger();
Expand All @@ -660,7 +669,7 @@ public void DefaultTrxFileShouldIterateIfLogFileNameParameterNotPassed()

files = loggers.Select(l => l.trxFile).Distinct().ToArray();

Assert.IsTrue(files.Length == loggers.Length, "All logger instances should get a seperate file name!");
return files;
}
finally
{
Expand All @@ -680,41 +689,10 @@ public void DefaultTrxFileShouldIterateIfLogFileNameParameterNotPassed()
[TestMethod]
public void TrxFileNameShouldNotIterate()
{
var loggers = new TestableTrxLogger[10];
for (int i = 0; i < loggers.Length; i++)
{
loggers[i] = new TestableTrxLogger();
loggers[i].Initialize(this.events.Object, this.parameters);
}

string[] files = null;
try
{
loggers.AsParallel().ForAll(l =>
{
var pass = TrxLoggerTests.CreatePassTestResultEventArgsMock();
l.TestResultHandler(new object(), pass.Object);
var testRunCompleteEventArgs = TrxLoggerTests.CreateTestRunCompleteEventArgs();
l.TestRunCompleteHandler(new object(), testRunCompleteEventArgs);
});
var files = TestMultipleTrxLoggers(MultipleLoggerInstanceCount);

files = loggers.Select(l => l.trxFile).Distinct().ToArray();
Assert.IsTrue(files.Length == 1, "All logger instances should get the same file name!");

Assert.IsTrue(files.Length == 1, "All logger instances should get the same file name!");
}
finally
{
if (files != null)
{
foreach (var file in files)
{
if (!string.IsNullOrEmpty(file) && File.Exists(file))
{
File.Delete(file);
}
}
}
}
}

[TestMethod]
Expand All @@ -723,41 +701,9 @@ public void TrxPrefixFileNameShouldIterate()
this.parameters.Remove(TrxLoggerConstants.LogFileNameKey);
this.parameters[TrxLoggerConstants.LogFilePrefixKey] = DefaultLogFilePrefixParameterValue;

var loggers = new TestableTrxLogger[10];
for (int i = 0; i < loggers.Length; i++)
{
loggers[i] = new TestableTrxLogger();
loggers[i].Initialize(this.events.Object, this.parameters);
}

string[] files = null;
try
{
loggers.AsParallel().ForAll(l =>
{
var pass = TrxLoggerTests.CreatePassTestResultEventArgsMock();
l.TestResultHandler(new object(), pass.Object);
var testRunCompleteEventArgs = TrxLoggerTests.CreateTestRunCompleteEventArgs();
l.TestRunCompleteHandler(new object(), testRunCompleteEventArgs);
});

files = loggers.Select(l => l.trxFile).Distinct().ToArray();
var files = TestMultipleTrxLoggers(MultipleLoggerInstanceCount);

Assert.IsTrue(files.Length == 10, "All logger instances should get the same file name!");
}
finally
{
if (files != null)
{
foreach (var file in files)
{
if (!string.IsNullOrEmpty(file) && File.Exists(file))
{
File.Delete(file);
}
}
}
}
Assert.IsTrue(files.Length == MultipleLoggerInstanceCount, "All logger instances should get the same file name!");
Haplois marked this conversation as resolved.
Show resolved Hide resolved
}

[TestMethod]
Expand Down