Skip to content

Commit

Permalink
Make title uniqueness check thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Aug 12, 2022
1 parent f079ae9 commit 68fc8b0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/NScenario/TestScenarioFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ private static string GenerateScenarioTitle(string scenario)

private static readonly HashSet<string> ScenarioTitles = new HashSet<string>();

private static readonly object titleUniquenessLock = new object();
private static void EnsureTestScenarioTitleUniqueness(string scenarioTitle)
{
if (ScenarioTitles.Add(scenarioTitle) == false)
lock (titleUniquenessLock)
{
throw new InvalidOperationException("Test scenario with a given title was already created. If you are using test method with parameters, please specify test scenario title explicitly by setting 'title' parameter.");
if (ScenarioTitles.Add(scenarioTitle) == false)
{
throw new InvalidOperationException("Test scenario with a given title was already created. If you are using test method with parameters, please specify test scenario title explicitly by setting 'title' parameter.");
}
}
}

Expand Down

0 comments on commit 68fc8b0

Please sign in to comment.