Skip to content

Commit

Permalink
Better test coverage for interceptors and Diagnostics registered at t…
Browse files Browse the repository at this point in the history
…he same time

Fixes #16352
  • Loading branch information
ajcvickers committed Jun 29, 2019
1 parent 2a3a0e1 commit 6d7e175
Show file tree
Hide file tree
Showing 10 changed files with 744 additions and 294 deletions.
308 changes: 194 additions & 114 deletions test/EFCore.Relational.Specification.Tests/CommandInterceptionTestBase.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,34 @@ public virtual async Task Intercept_connection_passively(bool async)
connection.Close();
}

if (async)
using (var listener = Fixture.SubscribeToDiagnosticListener(context.ContextIds.Id))
{
await context.Database.OpenConnectionAsync();
}
else
{
context.Database.OpenConnection();
}
if (async)
{
await context.Database.OpenConnectionAsync();
}
else
{
context.Database.OpenConnection();
}

AssertNormalOpen(context, interceptor, async);
AssertNormalOpen(context, interceptor, async);

interceptor.Reset();
interceptor.Reset();

if (async)
{
await context.Database.CloseConnectionAsync();
}
else
{
context.Database.CloseConnection();
}
if (async)
{
await context.Database.CloseConnectionAsync();
}
else
{
context.Database.CloseConnection();
}

AssertNormalClose(context, interceptor, async);
AssertNormalClose(context, interceptor, async);

AsertOpenCloseEvents(listener);
}

if (startedOpen)
{
Expand All @@ -81,29 +86,34 @@ public virtual async Task Intercept_connection_to_override_opening(bool async)
connection.Close();
}

if (async)
using (var listener = Fixture.SubscribeToDiagnosticListener(context.ContextIds.Id))
{
await context.Database.OpenConnectionAsync();
}
else
{
context.Database.OpenConnection();
}
if (async)
{
await context.Database.OpenConnectionAsync();
}
else
{
context.Database.OpenConnection();
}

AssertNormalOpen(context, interceptor, async);
AssertNormalOpen(context, interceptor, async);

interceptor.Reset();
interceptor.Reset();

if (async)
{
await context.Database.CloseConnectionAsync();
}
else
{
context.Database.CloseConnection();
}
if (async)
{
await context.Database.CloseConnectionAsync();
}
else
{
context.Database.CloseConnection();
}

AssertNormalClose(context, interceptor, async);
AssertNormalClose(context, interceptor, async);

AsertOpenCloseEvents(listener);
}

if (startedOpen)
{
Expand Down Expand Up @@ -139,38 +149,43 @@ public virtual async Task Intercept_connection_with_multiple_interceptors(bool a
connection.Close();
}

if (async)
using (var listener = Fixture.SubscribeToDiagnosticListener(context.ContextIds.Id))
{
await context.Database.OpenConnectionAsync();
}
else
{
context.Database.OpenConnection();
}
if (async)
{
await context.Database.OpenConnectionAsync();
}
else
{
context.Database.OpenConnection();
}

AssertNormalOpen(context, interceptor1, async);
AssertNormalOpen(context, interceptor2, async);
AssertNormalOpen(context, interceptor3, async);
AssertNormalOpen(context, interceptor4, async);
AssertNormalOpen(context, interceptor1, async);
AssertNormalOpen(context, interceptor2, async);
AssertNormalOpen(context, interceptor3, async);
AssertNormalOpen(context, interceptor4, async);

interceptor1.Reset();
interceptor2.Reset();
interceptor3.Reset();
interceptor4.Reset();
interceptor1.Reset();
interceptor2.Reset();
interceptor3.Reset();
interceptor4.Reset();

if (async)
{
await context.Database.CloseConnectionAsync();
}
else
{
context.Database.CloseConnection();
}
if (async)
{
await context.Database.CloseConnectionAsync();
}
else
{
context.Database.CloseConnection();
}

AssertNormalClose(context, interceptor1, async);
AssertNormalClose(context, interceptor2, async);
AssertNormalClose(context, interceptor3, async);
AssertNormalClose(context, interceptor4, async);

AssertNormalClose(context, interceptor1, async);
AssertNormalClose(context, interceptor2, async);
AssertNormalClose(context, interceptor3, async);
AssertNormalClose(context, interceptor4, async);
AsertOpenCloseEvents(listener);
}

if (startedOpen)
{
Expand Down Expand Up @@ -492,5 +507,12 @@ private static void AssertErrorOnOpen(DbContext context, ConnectionInterceptor i
Assert.True(interceptor.FailedCalled);
Assert.Same(context, interceptor.Context);
}

private static void AsertOpenCloseEvents(ITestDiagnosticListener listener)
=> listener.AssertEventsInOrder(
RelationalEventId.ConnectionOpening.Name,
RelationalEventId.ConnectionOpened.Name,
RelationalEventId.ConnectionClosing.Name,
RelationalEventId.ConnectionClosed.Name);
}
}
Loading

0 comments on commit 6d7e175

Please sign in to comment.