Skip to content

Commit f1c88c2

Browse files
fredericDelaportehazzik
authored andcommitted
Fix a flaky test (#2255)
See #1594
1 parent f35874a commit f1c88c2

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/NHibernate.Test/Async/NHSpecificTest/GH1594/Fixture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ public async Task ExecutionContextLocalValuesLeakAsync()
6262
{
6363
await (RunInTransactionAsync(session));
6464
var localValuesCountAfterFirstCall = ExecutionContext.Capture().LocalValuesCount();
65+
if (!localValuesCountAfterFirstCall.HasValue)
66+
Assert.Ignore("Unable to get async local values count");
6567
await (RunInTransactionAsync(session));
6668
var localValuesCountAfterSecondCall = ExecutionContext.Capture().LocalValuesCount();
69+
if (!localValuesCountAfterSecondCall.HasValue)
70+
Assert.Ignore("Unable to get async local values count");
71+
6772
Assert.AreEqual(localValuesCountAfterFirstCall, localValuesCountAfterSecondCall);
6873
}
6974
}

src/NHibernate.Test/NHSpecificTest/GH1594/ExecutionContextExtensions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ namespace NHibernate.Test.NHSpecificTest.GH1594
55
{
66
public static class ExecutionContextExtensions
77
{
8-
public static int LocalValuesCount(this ExecutionContext c)
8+
public static int? LocalValuesCount(this ExecutionContext c)
99
{
1010
#if NETFX
1111
const string localValuesFieldName = "_localValues";
1212
#else
1313
const string localValuesFieldName = "m_localValues";
1414
#endif
1515
var f = typeof(ExecutionContext).GetField(localValuesFieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
16-
var d = (IDictionary) f.GetValue(c);
17-
return d?.Count ?? 0;
16+
// The property value may not implement IDictionary, especially when there is less than 4 values, but not only.
17+
// So we may not be able to know anything about this count.
18+
var d = f.GetValue(c) as IDictionary;
19+
return d?.Count;
1820
}
1921
}
2022
}

src/NHibernate.Test/NHSpecificTest/GH1594/Fixture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ public void ExecutionContextLocalValuesLeak()
5050
{
5151
RunInTransaction(session);
5252
var localValuesCountAfterFirstCall = ExecutionContext.Capture().LocalValuesCount();
53+
if (!localValuesCountAfterFirstCall.HasValue)
54+
Assert.Ignore("Unable to get async local values count");
5355
RunInTransaction(session);
5456
var localValuesCountAfterSecondCall = ExecutionContext.Capture().LocalValuesCount();
57+
if (!localValuesCountAfterSecondCall.HasValue)
58+
Assert.Ignore("Unable to get async local values count");
59+
5560
Assert.AreEqual(localValuesCountAfterFirstCall, localValuesCountAfterSecondCall);
5661
}
5762
}

0 commit comments

Comments
 (0)