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 1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Threading ;
4
+ using System . Threading . Tasks ;
4
5
using NUnit . Framework ;
5
6
6
7
namespace NHibernate . Test . NHSpecificTest . NH2192
@@ -73,7 +74,9 @@ public void HqlIsThreadsafe_UsingThreads()
73
74
threads . ForEach ( t => t . Join ( ) ) ;
74
75
75
76
if ( exceptions . Count > 0 )
77
+ {
76
78
throw exceptions [ 0 ] ;
79
+ }
77
80
78
81
results . ForEach ( r => Assert . That ( r , Is . EqualTo ( 2 ) ) ) ;
79
82
}
@@ -83,25 +86,29 @@ public void HqlIsThreadsafe_UsingPool()
83
86
{
84
87
List < Exception > exceptions = new List < Exception > ( ) ;
85
88
Func < int > result = FetchRowResults ;
86
- List < IAsyncResult > results = new List < IAsyncResult > ( ) ;
89
+ List < Task < int > > tasks = new List < Task < int > > ( ) ;
87
90
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
+ }
90
95
91
- results . ForEach ( r =>
96
+ tasks . ForEach ( r =>
97
+ {
98
+ try
92
99
{
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
+ } ) ;
102
107
103
108
if ( exceptions . Count > 0 )
109
+ {
104
110
throw exceptions [ 0 ] ;
111
+ }
105
112
}
106
113
107
114
private int FetchRowResults ( )
Original file line number Diff line number Diff line change 3
3
using System . Collections . Generic ;
4
4
using System . Reflection ;
5
5
using System . Threading ;
6
+ using System . Threading . Tasks ;
6
7
7
8
using NHibernate . Engine . Query ;
8
9
using NHibernate . Linq ;
@@ -144,11 +145,11 @@ where personIds.Contains(person.Id)
144
145
}
145
146
} ;
146
147
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 ) ;
149
150
150
- queryExecutor . EndInvoke ( queryExecutorAsyncResult ) ;
151
- cacheCleaner . EndInvoke ( cacheCleanerAsyncResult ) ;
151
+ queryExecutorTask . Wait ( ) ;
152
+ cacheCleanerTask . Wait ( ) ;
152
153
153
154
Assert . IsTrue ( allLinqQueriesSucceeded ) ;
154
155
}
You can’t perform that action at this time.
0 commit comments