Skip to content

Fix a flaky test for #1594 #2255

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

Merged
merged 1 commit into from
Oct 21, 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
5 changes: 5 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/GH1594/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ public async Task ExecutionContextLocalValuesLeakAsync()
{
await (RunInTransactionAsync(session));
var localValuesCountAfterFirstCall = ExecutionContext.Capture().LocalValuesCount();
if (!localValuesCountAfterFirstCall.HasValue)
Assert.Ignore("Unable to get async local values count");
await (RunInTransactionAsync(session));
var localValuesCountAfterSecondCall = ExecutionContext.Capture().LocalValuesCount();
if (!localValuesCountAfterSecondCall.HasValue)
Assert.Ignore("Unable to get async local values count");

Assert.AreEqual(localValuesCountAfterFirstCall, localValuesCountAfterSecondCall);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ namespace NHibernate.Test.NHSpecificTest.GH1594
{
public static class ExecutionContextExtensions
{
public static int LocalValuesCount(this ExecutionContext c)
public static int? LocalValuesCount(this ExecutionContext c)
{
#if NETFX
const string localValuesFieldName = "_localValues";
#else
const string localValuesFieldName = "m_localValues";
#endif
var f = typeof(ExecutionContext).GetField(localValuesFieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var d = (IDictionary) f.GetValue(c);
return d?.Count ?? 0;
// The property value may not implement IDictionary, especially when there is less than 4 values, but not only.
// So we may not be able to know anything about this count.
var d = f.GetValue(c) as IDictionary;
return d?.Count;
}
}
}
5 changes: 5 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH1594/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ public void ExecutionContextLocalValuesLeak()
{
RunInTransaction(session);
var localValuesCountAfterFirstCall = ExecutionContext.Capture().LocalValuesCount();
if (!localValuesCountAfterFirstCall.HasValue)
Assert.Ignore("Unable to get async local values count");
RunInTransaction(session);
var localValuesCountAfterSecondCall = ExecutionContext.Capture().LocalValuesCount();
if (!localValuesCountAfterSecondCall.HasValue)
Assert.Ignore("Unable to get async local values count");

Assert.AreEqual(localValuesCountAfterFirstCall, localValuesCountAfterSecondCall);
}
}
Expand Down