File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed
Async/NHSpecificTest/GH1594 Expand file tree Collapse file tree 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()
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 }
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments