This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +60
-6
lines changed
tests/ServiceStack.Redis.Tests Expand file tree Collapse file tree 4 files changed +60
-6
lines changed Original file line number Diff line number Diff line change 4
4
using System . Threading ;
5
5
using NUnit . Framework ;
6
6
using ServiceStack . Text ;
7
+ #if NETCORE
8
+ using System . Threading . Tasks ;
9
+ #endif
7
10
8
11
namespace ServiceStack . Redis . Tests . Integration
9
12
{
@@ -51,18 +54,30 @@ protected void RunSimultaneously(
51
54
52
55
const int noOfConcurrentClients = 64 ; //WaitHandle.WaitAll limit is <= 64
53
56
57
+ #if NETCORE
58
+ List < Task > tasks = new List < Task > ( ) ;
59
+ #else
54
60
var clientAsyncResults = new List < IAsyncResult > ( ) ;
61
+ #endif
55
62
using ( var manager = clientManagerFactory ( TestConfig . MasterHosts , TestConfig . SlaveHosts ) )
56
63
{
57
64
for ( var i = 0 ; i < noOfConcurrentClients ; i ++ )
58
65
{
59
66
var clientNo = i ;
60
67
var action = ( Action ) ( ( ) => useClientFn ( manager , clientNo ) ) ;
68
+ #if NETCORE
69
+ tasks . Add ( Task . Run ( action ) ) ;
70
+ #else
61
71
clientAsyncResults . Add ( action . BeginInvoke ( null , null ) ) ;
72
+ #endif
62
73
}
63
74
}
64
75
76
+ #if NETCORE
77
+ Task . WaitAll ( tasks . ToArray ( ) ) ;
78
+ #else
65
79
WaitHandle . WaitAll ( clientAsyncResults . ConvertAll ( x => x . AsyncWaitHandle ) . ToArray ( ) ) ;
80
+ #endif
66
81
67
82
Debug . WriteLine ( String . Format ( "Time Taken: {0}" , ( Stopwatch . GetTimestamp ( ) - before ) / 1000 ) ) ;
68
83
}
Original file line number Diff line number Diff line change 5
5
using NUnit . Framework ;
6
6
using ServiceStack . Common . Tests . Models ;
7
7
using ServiceStack . Text ;
8
+ #if NETCORE
9
+ using System . Threading . Tasks ;
10
+ #endif
8
11
9
12
namespace ServiceStack . Redis . Tests . Integration
10
13
{
@@ -29,19 +32,29 @@ public void Can_support_64_threads_using_the_client_simultaneously()
29
32
30
33
const int noOfConcurrentClients = 64 ; //WaitHandle.WaitAll limit is <= 64
31
34
35
+ #if NETCORE
36
+ List < Task > tasks = new List < Task > ( ) ;
37
+ #else
32
38
var clientAsyncResults = new List < IAsyncResult > ( ) ;
39
+ #endif
33
40
using ( var redisClient = new RedisClient ( TestConfig . SingleHost ) )
34
41
{
35
42
for ( var i = 0 ; i < noOfConcurrentClients ; i ++ )
36
43
{
37
44
var clientNo = i ;
38
45
var action = ( Action ) ( ( ) => UseClientAsync ( redisClient , clientNo ) ) ;
46
+ #if NETCORE
47
+ tasks . Add ( Task . Run ( action ) ) ;
48
+ #else
39
49
clientAsyncResults . Add ( action . BeginInvoke ( null , null ) ) ;
50
+ #endif
40
51
}
41
52
}
42
-
53
+ #if NETCORE
54
+ Task . WaitAll ( tasks . ToArray ( ) ) ;
55
+ #else
43
56
WaitHandle . WaitAll ( clientAsyncResults . ConvertAll ( x => x . AsyncWaitHandle ) . ToArray ( ) ) ;
44
-
57
+ #endif
45
58
Debug . WriteLine ( String . Format ( "Time Taken: {0}" , ( Stopwatch . GetTimestamp ( ) - before ) / 1000 ) ) ;
46
59
}
47
60
Original file line number Diff line number Diff line change 5
5
using System . Threading ;
6
6
using NUnit . Framework ;
7
7
using ServiceStack . Text ;
8
+ #if NETCORE
9
+ using System . Threading . Tasks ;
10
+ #endif
8
11
9
12
namespace ServiceStack . Redis . Tests
10
13
{
@@ -306,7 +309,11 @@ public void Does_block_ReadWrite_clients_pool()
306
309
client4 . Dispose ( ) ;
307
310
} ;
308
311
312
+ #if NETCORE
313
+ Task . Run ( func ) ;
314
+ #else
309
315
func . BeginInvoke ( null , null ) ;
316
+ #endif
310
317
311
318
var start = DateTime . Now ;
312
319
@@ -338,9 +345,11 @@ public void Does_block_ReadOnly_clients_pool()
338
345
Thread . Sleep ( delay + TimeSpan . FromSeconds ( 0.5 ) ) ;
339
346
client3 . Dispose ( ) ;
340
347
} ;
341
-
348
+ #if NETCORE
349
+ Task . Run ( func ) ;
350
+ #else
342
351
func . BeginInvoke ( null , null ) ;
343
-
352
+ #endif
344
353
var start = DateTime . Now ;
345
354
346
355
var client4 = manager . GetReadOnlyClient ( ) ;
Original file line number Diff line number Diff line change 4
4
using System . Threading ;
5
5
using NUnit . Framework ;
6
6
using ServiceStack . Text ;
7
+ #if NETCORE
8
+ using System . Threading . Tasks ;
9
+ #endif
7
10
8
11
namespace ServiceStack . Redis . Tests
9
12
{
@@ -155,9 +158,11 @@ public void Does_not_block_ReadWrite_clients_pool()
155
158
Thread . Sleep ( delay + TimeSpan . FromSeconds ( 0.5 ) ) ;
156
159
client4 . Dispose ( ) ;
157
160
} ;
158
-
161
+ #if NETCORE
162
+ Task . Run ( func ) ;
163
+ #else
159
164
func . BeginInvoke ( null , null ) ;
160
-
165
+ #endif
161
166
var start = DateTime . Now ;
162
167
163
168
var client5 = manager . GetClient ( ) ;
@@ -180,18 +185,30 @@ public void Can_support_64_threads_using_the_client_simultaneously()
180
185
const int noOfConcurrentClients = 64 ; //WaitHandle.WaitAll limit is <= 64
181
186
var clientUsageMap = new Dictionary < string , int > ( ) ;
182
187
188
+ #if NETCORE
189
+ List < Task > tasks = new List < Task > ( ) ;
190
+ #else
183
191
var clientAsyncResults = new List < IAsyncResult > ( ) ;
192
+ #endif
184
193
using ( var manager = CreateManager ( ) )
185
194
{
186
195
for ( var i = 0 ; i < noOfConcurrentClients ; i ++ )
187
196
{
188
197
var clientNo = i ;
189
198
var action = ( Action ) ( ( ) => UseClient ( manager , clientNo , clientUsageMap ) ) ;
199
+ #if NETCORE
200
+ tasks . Add ( Task . Run ( action ) ) ;
201
+ #else
190
202
clientAsyncResults . Add ( action . BeginInvoke ( null , null ) ) ;
203
+ #endif
191
204
}
192
205
}
193
206
207
+ #if NETCORE
208
+ Task . WaitAll ( tasks . ToArray ( ) ) ;
209
+ #else
194
210
WaitHandle . WaitAll ( clientAsyncResults . ConvertAll ( x => x . AsyncWaitHandle ) . ToArray ( ) ) ;
211
+ #endif
195
212
196
213
Debug . WriteLine ( TypeSerializer . SerializeToString ( clientUsageMap ) ) ;
197
214
You can’t perform that action at this time.
0 commit comments