FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix DisableRecording carrying over to later pooled leases by SimonCropp · Pull Request #1072 · VerifyTests/Verify.EntityFramework · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (2) .txt  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
ef: {
Type: QueryAsync,
Text:
DbSet<Company>()
.Where(_ => _.Name == "Title")
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,37 @@ await data
await Verify();
}

// a pooled context keeps its InstanceId, so disabling was carried over to every later lease
[Test]
public async Task DisableRecordingPooled()
{
var builder = new DbContextOptionsBuilder<SampleDbContext>();
builder.UseInMemoryDatabase(nameof(DisableRecordingPooled));
builder.EnableRecording();
var factory = new PooledDbContextFactory<SampleDbContext>(builder.Options);

SampleDbContext disabled;
await using (var data = factory.CreateDbContext())
{
disabled = data;
data.DisableRecording();
}

await using (var data = factory.CreateDbContext())
{
Assert.That(data, Is.SameAs(disabled));

Recording.Start();

await data
.Companies
.Where(_ => _.Name == "Title")
.ToListAsync();

await Verify();
}
}

[Test]
public async Task Identifier()
{
Expand Down
8 changes: 5 additions & 3 deletions src/Verify.EntityFramework/VerifyEntityFramework.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,15 @@ public static DbContextOptionsBuilder<TContext> EnableRecording<TContext>(this D
return builder.AddInterceptors(interceptor);
}

static ConcurrentBag<Guid> recordingDisabledContextIds = [];
// Keyed on the whole ContextId, since a pooled context keeps its InstanceId and only increments its Lease.
// A dictionary, since ConcurrentBag.Contains copies the bag, under a lock, for every command.
static ConcurrentDictionary<DbContextId, byte> recordingDisabledContextIds = [];

public static void DisableRecording<TContext>(this TContext context)
where TContext : DbContext =>
recordingDisabledContextIds.Add(context.ContextId.InstanceId);
recordingDisabledContextIds.TryAdd(context.ContextId, 0);

internal static bool IsRecordingDisabled<TContext>(this TContext context)
where TContext : DbContext =>
recordingDisabledContextIds.Contains(context.ContextId.InstanceId);
recordingDisabledContextIds.ContainsKey(context.ContextId);
}
Loading

Back | FazBrowse Home | New Git URL