Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid deadlock in tests #17155

Merged
merged 1 commit into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions test/EFCore.Specification.Tests/Query/AsyncSimpleQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,22 @@ public virtual async Task Throws_on_concurrent_query_list()
{
var blockingTask = Task.Run(
() =>
context.Customers.Select(
c => Process(c, synchronizationEvent, blockingSemaphore)).ToList());
{
try
{
context.Customers.Select(
c => Process(c, synchronizationEvent, blockingSemaphore)).ToList();
}
finally
{
synchronizationEvent.Set();
}
});

var throwingTask = Task.Run(
async () =>
{
synchronizationEvent.Wait();
synchronizationEvent.Wait(TimeSpan.FromMinutes(5));

Assert.Equal(
CoreStrings.ConcurrentMethodInvocation,
Expand Down Expand Up @@ -309,13 +318,22 @@ public virtual async Task Throws_on_concurrent_query_first()
{
var blockingTask = Task.Run(
() =>
context.Customers.Select(
c => Process(c, synchronizationEvent, blockingSemaphore)).ToList());
{
try
{
context.Customers.Select(
c => Process(c, synchronizationEvent, blockingSemaphore)).ToList();
}
finally
{
synchronizationEvent.Set();
}
});

var throwingTask = Task.Run(
async () =>
{
synchronizationEvent.Wait();
synchronizationEvent.Wait(TimeSpan.FromMinutes(5));

Assert.Equal(
CoreStrings.ConcurrentMethodInvocation,
Expand All @@ -336,7 +354,7 @@ public virtual async Task Throws_on_concurrent_query_first()
private static Customer Process(Customer c, ManualResetEventSlim e, SemaphoreSlim s)
{
e.Set();
s.Wait();
s.Wait(TimeSpan.FromMinutes(5));
s.Release(1);
return c;
}
Expand Down
40 changes: 29 additions & 11 deletions test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3714,24 +3714,33 @@ public virtual void Throws_on_concurrent_query_list()
{
var blockingTask = Task.Run(
() =>
context.Customers.Select(
c => Process(c, synchronizationEvent, blockingSemaphore)).ToList());
{
try
{
context.Customers.Select(
c => Process(c, synchronizationEvent, blockingSemaphore)).ToList();
}
finally
{
synchronizationEvent.Set();
}
});

var throwingTask = Task.Run(
() =>
{
synchronizationEvent.Wait();
synchronizationEvent.Wait(TimeSpan.FromMinutes(5));
Assert.Equal(
CoreStrings.ConcurrentMethodInvocation,
Assert.Throws<InvalidOperationException>(
() => context.Customers.ToList()).Message);
});

throwingTask.Wait();
throwingTask.Wait(TimeSpan.FromMinutes(5));

blockingSemaphore.Release(1);

blockingTask.Wait();
blockingTask.Wait(TimeSpan.FromMinutes(5));
}
}
}
Expand All @@ -3750,24 +3759,33 @@ public virtual void Throws_on_concurrent_query_first()
{
var blockingTask = Task.Run(
() =>
context.Customers.Select(
c => Process(c, synchronizationEvent, blockingSemaphore)).ToList());
{
try
{
context.Customers.Select(
c => Process(c, synchronizationEvent, blockingSemaphore)).ToList();
}
finally
{
synchronizationEvent.Set();
}
});

var throwingTask = Task.Run(
() =>
{
synchronizationEvent.Wait();
synchronizationEvent.Wait(TimeSpan.FromMinutes(5));
Assert.Equal(
CoreStrings.ConcurrentMethodInvocation,
Assert.Throws<InvalidOperationException>(
() => context.Customers.First()).Message);
});

throwingTask.Wait();
throwingTask.Wait(TimeSpan.FromMinutes(5));

blockingSemaphore.Release(1);

blockingTask.Wait();
blockingTask.Wait(TimeSpan.FromMinutes(5));
}
}
}
Expand All @@ -3776,7 +3794,7 @@ public virtual void Throws_on_concurrent_query_first()
private static Customer Process(Customer c, ManualResetEventSlim e, SemaphoreSlim s)
{
e.Set();
s.Wait();
s.Wait(TimeSpan.FromMinutes(5));
s.Release(1);
return c;
}
Expand Down