File tree 3 files changed +15
-3
lines changed
Async/NHSpecificTest/GH1594 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -62,8 +62,13 @@ public async Task ExecutionContextLocalValuesLeakAsync()
62
62
{
63
63
await ( RunInTransactionAsync ( session ) ) ;
64
64
var localValuesCountAfterFirstCall = ExecutionContext . Capture ( ) . LocalValuesCount ( ) ;
65
+ if ( ! localValuesCountAfterFirstCall . HasValue )
66
+ Assert . Ignore ( "Unable to get async local values count" ) ;
65
67
await ( RunInTransactionAsync ( session ) ) ;
66
68
var localValuesCountAfterSecondCall = ExecutionContext . Capture ( ) . LocalValuesCount ( ) ;
69
+ if ( ! localValuesCountAfterSecondCall . HasValue )
70
+ Assert . Ignore ( "Unable to get async local values count" ) ;
71
+
67
72
Assert . AreEqual ( localValuesCountAfterFirstCall , localValuesCountAfterSecondCall ) ;
68
73
}
69
74
}
Original file line number Diff line number Diff line change @@ -5,16 +5,18 @@ namespace NHibernate.Test.NHSpecificTest.GH1594
5
5
{
6
6
public static class ExecutionContextExtensions
7
7
{
8
- public static int LocalValuesCount ( this ExecutionContext c )
8
+ public static int ? LocalValuesCount ( this ExecutionContext c )
9
9
{
10
10
#if NETFX
11
11
const string localValuesFieldName = "_localValues" ;
12
12
#else
13
13
const string localValuesFieldName = "m_localValues" ;
14
14
#endif
15
15
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 ;
18
20
}
19
21
}
20
22
}
Original file line number Diff line number Diff line change @@ -50,8 +50,13 @@ public void ExecutionContextLocalValuesLeak()
50
50
{
51
51
RunInTransaction ( session ) ;
52
52
var localValuesCountAfterFirstCall = ExecutionContext . Capture ( ) . LocalValuesCount ( ) ;
53
+ if ( ! localValuesCountAfterFirstCall . HasValue )
54
+ Assert . Ignore ( "Unable to get async local values count" ) ;
53
55
RunInTransaction ( session ) ;
54
56
var localValuesCountAfterSecondCall = ExecutionContext . Capture ( ) . LocalValuesCount ( ) ;
57
+ if ( ! localValuesCountAfterSecondCall . HasValue )
58
+ Assert . Ignore ( "Unable to get async local values count" ) ;
59
+
55
60
Assert . AreEqual ( localValuesCountAfterFirstCall , localValuesCountAfterSecondCall ) ;
56
61
}
57
62
}
You can’t perform that action at this time.
0 commit comments