Skip to content

Commit

Permalink
Lock per-file instead of globally
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Nov 17, 2021
1 parent b0620f8 commit d0075ba
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -27,7 +28,7 @@ public class TestSqlLoggerFactory : ListLoggerFactory
private static readonly string _eol = Environment.NewLine;

private static readonly object _queryBaselineFileLock = new();
private static readonly object _queryBaselineRewritingLock = new();
private static readonly ConcurrentDictionary<string, object> _queryBaselineRewritingLocks = new();

public TestSqlLoggerFactory()
: this(_ => true)
Expand Down Expand Up @@ -131,7 +132,8 @@ public void AssertBaseline(string[] expected, bool assertOrder = true)

void RewriteSourceWithNewBaseline(string fileName, int lineNumber)
{
lock (_queryBaselineRewritingLock)
var fileLock = _queryBaselineRewritingLocks.GetOrAdd(fileName, _ => new());
lock (fileLock)
{
// Parse the file to find the line where the relevant AssertSql is
try
Expand Down

0 comments on commit d0075ba

Please sign in to comment.