File tree Expand file tree Collapse file tree 2 files changed +25
-17
lines changed
src/NHibernate.Test/NHSpecificTest Expand file tree Collapse file tree 2 files changed +25
-17
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
33using System . Threading ;
4+ using System . Threading . Tasks ;
45using NUnit . Framework ;
56
67namespace NHibernate . Test . NHSpecificTest . NH2192
@@ -73,7 +74,9 @@ public void HqlIsThreadsafe_UsingThreads()
7374 threads . ForEach ( t => t . Join ( ) ) ;
7475
7576 if ( exceptions . Count > 0 )
77+ {
7678 throw exceptions [ 0 ] ;
79+ }
7780
7881 results . ForEach ( r => Assert . That ( r , Is . EqualTo ( 2 ) ) ) ;
7982 }
@@ -83,25 +86,29 @@ public void HqlIsThreadsafe_UsingPool()
8386 {
8487 List < Exception > exceptions = new List < Exception > ( ) ;
8588 Func < int > result = FetchRowResults ;
86- List < IAsyncResult > results = new List < IAsyncResult > ( ) ;
89+ List < Task < int > > tasks = new List < Task < int > > ( ) ;
8790
88- for ( int i = 0 ; i < _threadCount ; i ++ )
89- results . Add ( result . BeginInvoke ( null , null ) ) ;
91+ for ( int i = 0 ; i < _threadCount ; i ++ )
92+ {
93+ tasks . Add ( Task . Run < int > ( result ) ) ;
94+ }
9095
91- results . ForEach ( r =>
96+ tasks . ForEach ( r =>
97+ {
98+ try
9299 {
93- try
94- {
95- Assert . That ( result . EndInvoke ( r ) , Is . EqualTo ( 2 ) ) ;
96- }
97- catch ( Exception e )
98- {
99- exceptions . Add ( e ) ;
100- }
101- } ) ;
100+ Assert . That ( r . Result , Is . EqualTo ( 2 ) ) ;
101+ }
102+ catch ( Exception e )
103+ {
104+ exceptions . Add ( e ) ;
105+ }
106+ } ) ;
102107
103108 if ( exceptions . Count > 0 )
109+ {
104110 throw exceptions [ 0 ] ;
111+ }
105112 }
106113
107114 private int FetchRowResults ( )
Original file line number Diff line number Diff line change 33using System . Collections . Generic ;
44using System . Reflection ;
55using System . Threading ;
6+ using System . Threading . Tasks ;
67
78using NHibernate . Engine . Query ;
89using NHibernate . Linq ;
@@ -144,11 +145,11 @@ where personIds.Contains(person.Id)
144145 }
145146 } ;
146147
147- var queryExecutorAsyncResult = queryExecutor . BeginInvoke ( null , null ) ;
148- var cacheCleanerAsyncResult = cacheCleaner . BeginInvoke ( null , null ) ;
148+ var queryExecutorTask = Task . Run ( queryExecutor ) ;
149+ var cacheCleanerTask = Task . Run ( cacheCleaner ) ;
149150
150- queryExecutor . EndInvoke ( queryExecutorAsyncResult ) ;
151- cacheCleaner . EndInvoke ( cacheCleanerAsyncResult ) ;
151+ queryExecutorTask . Wait ( ) ;
152+ cacheCleanerTask . Wait ( ) ;
152153
153154 Assert . IsTrue ( allLinqQueriesSucceeded ) ;
154155 }
You can’t perform that action at this time.
0 commit comments