Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartheek Penagamuri committed Dec 13, 2022
1 parent 54063e7 commit bb27126
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/NuGet.Core.Tests/NuGet.Common.Test/MigrationRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,32 @@ public void Run_WhenExecutedInParallelThenOnlyOneMigrationFileIsCreated_Success(
public void Run_WhenAThreadAbandonsMutexThenNextMigrationRunReleasesMutexAndCreatesMigrationFile_Success()
{
Mutex _orphan = new Mutex(false, "NuGet-Migrations");
bool signal = false;

// Arrange
Thread t = new Thread(new ThreadStart(AbandonMutex));
t.Start();
t.Join();

string directory = MigrationRunner.GetMigrationsDirectory();
if (Directory.Exists(directory))
Directory.Delete(path: directory, recursive: true);
if (signal)
{
string directory = MigrationRunner.GetMigrationsDirectory();
if (Directory.Exists(directory))
Directory.Delete(path: directory, recursive: true);

// Act
MigrationRunner.Run();
// Act
MigrationRunner.Run();

// Assert
Assert.True(Directory.Exists(directory));
var files = Directory.GetFiles(directory);
Assert.Equal(1, files.Length);
Assert.Equal(Path.Combine(directory, "1"), files[0]);
// Assert
Assert.True(Directory.Exists(directory));
var files = Directory.GetFiles(directory);
Assert.Equal(1, files.Length);
Assert.Equal(Path.Combine(directory, "1"), files[0]);
}

void AbandonMutex()
{
_ = _orphan.WaitOne(TimeSpan.FromMinutes(1), false);
signal = _orphan.WaitOne(TimeSpan.FromMinutes(1), false);
// Abandon the mutex by exiting the method without releasing
}
}
Expand Down

0 comments on commit bb27126

Please sign in to comment.