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 44using System . Threading ;
55using NUnit . Framework ;
66using ServiceStack . Text ;
7+ #if NETCORE
8+ using System . Threading . Tasks ;
9+ #endif
710
811namespace ServiceStack . Redis . Tests . Integration
912{
@@ -51,18 +54,30 @@ protected void RunSimultaneously(
5154
5255 const int noOfConcurrentClients = 64 ; //WaitHandle.WaitAll limit is <= 64
5356
57+ #if NETCORE
58+ List < Task > tasks = new List < Task > ( ) ;
59+ #else
5460 var clientAsyncResults = new List < IAsyncResult > ( ) ;
61+ #endif
5562 using ( var manager = clientManagerFactory ( TestConfig . MasterHosts , TestConfig . SlaveHosts ) )
5663 {
5764 for ( var i = 0 ; i < noOfConcurrentClients ; i ++ )
5865 {
5966 var clientNo = i ;
6067 var action = ( Action ) ( ( ) => useClientFn ( manager , clientNo ) ) ;
68+ #if NETCORE
69+ tasks . Add ( Task . Run ( action ) ) ;
70+ #else
6171 clientAsyncResults . Add ( action . BeginInvoke ( null , null ) ) ;
72+ #endif
6273 }
6374 }
6475
76+ #if NETCORE
77+ Task . WaitAll ( tasks . ToArray ( ) ) ;
78+ #else
6579 WaitHandle . WaitAll ( clientAsyncResults . ConvertAll ( x => x . AsyncWaitHandle ) . ToArray ( ) ) ;
80+ #endif
6681
6782 Debug . WriteLine ( String . Format ( "Time Taken: {0}" , ( Stopwatch . GetTimestamp ( ) - before ) / 1000 ) ) ;
6883 }
Original file line number Diff line number Diff line change 55using NUnit . Framework ;
66using ServiceStack . Common . Tests . Models ;
77using ServiceStack . Text ;
8+ #if NETCORE
9+ using System . Threading . Tasks ;
10+ #endif
811
912namespace ServiceStack . Redis . Tests . Integration
1013{
@@ -29,19 +32,29 @@ public void Can_support_64_threads_using_the_client_simultaneously()
2932
3033 const int noOfConcurrentClients = 64 ; //WaitHandle.WaitAll limit is <= 64
3134
35+ #if NETCORE
36+ List < Task > tasks = new List < Task > ( ) ;
37+ #else
3238 var clientAsyncResults = new List < IAsyncResult > ( ) ;
39+ #endif
3340 using ( var redisClient = new RedisClient ( TestConfig . SingleHost ) )
3441 {
3542 for ( var i = 0 ; i < noOfConcurrentClients ; i ++ )
3643 {
3744 var clientNo = i ;
3845 var action = ( Action ) ( ( ) => UseClientAsync ( redisClient , clientNo ) ) ;
46+ #if NETCORE
47+ tasks . Add ( Task . Run ( action ) ) ;
48+ #else
3949 clientAsyncResults . Add ( action . BeginInvoke ( null , null ) ) ;
50+ #endif
4051 }
4152 }
42-
53+ #if NETCORE
54+ Task . WaitAll ( tasks . ToArray ( ) ) ;
55+ #else
4356 WaitHandle . WaitAll ( clientAsyncResults . ConvertAll ( x => x . AsyncWaitHandle ) . ToArray ( ) ) ;
44-
57+ #endif
4558 Debug . WriteLine ( String . Format ( "Time Taken: {0}" , ( Stopwatch . GetTimestamp ( ) - before ) / 1000 ) ) ;
4659 }
4760
Original file line number Diff line number Diff line change 55using System . Threading ;
66using NUnit . Framework ;
77using ServiceStack . Text ;
8+ #if NETCORE
9+ using System . Threading . Tasks ;
10+ #endif
811
912namespace ServiceStack . Redis . Tests
1013{
@@ -306,7 +309,11 @@ public void Does_block_ReadWrite_clients_pool()
306309 client4 . Dispose ( ) ;
307310 } ;
308311
312+ #if NETCORE
313+ Task . Run ( func ) ;
314+ #else
309315 func . BeginInvoke ( null , null ) ;
316+ #endif
310317
311318 var start = DateTime . Now ;
312319
@@ -338,9 +345,11 @@ public void Does_block_ReadOnly_clients_pool()
338345 Thread . Sleep ( delay + TimeSpan . FromSeconds ( 0.5 ) ) ;
339346 client3 . Dispose ( ) ;
340347 } ;
341-
348+ #if NETCORE
349+ Task . Run ( func ) ;
350+ #else
342351 func . BeginInvoke ( null , null ) ;
343-
352+ #endif
344353 var start = DateTime . Now ;
345354
346355 var client4 = manager . GetReadOnlyClient ( ) ;
Original file line number Diff line number Diff line change 44using System . Threading ;
55using NUnit . Framework ;
66using ServiceStack . Text ;
7+ #if NETCORE
8+ using System . Threading . Tasks ;
9+ #endif
710
811namespace ServiceStack . Redis . Tests
912{
@@ -155,9 +158,11 @@ public void Does_not_block_ReadWrite_clients_pool()
155158 Thread . Sleep ( delay + TimeSpan . FromSeconds ( 0.5 ) ) ;
156159 client4 . Dispose ( ) ;
157160 } ;
158-
161+ #if NETCORE
162+ Task . Run ( func ) ;
163+ #else
159164 func . BeginInvoke ( null , null ) ;
160-
165+ #endif
161166 var start = DateTime . Now ;
162167
163168 var client5 = manager . GetClient ( ) ;
@@ -180,18 +185,30 @@ public void Can_support_64_threads_using_the_client_simultaneously()
180185 const int noOfConcurrentClients = 64 ; //WaitHandle.WaitAll limit is <= 64
181186 var clientUsageMap = new Dictionary < string , int > ( ) ;
182187
188+ #if NETCORE
189+ List < Task > tasks = new List < Task > ( ) ;
190+ #else
183191 var clientAsyncResults = new List < IAsyncResult > ( ) ;
192+ #endif
184193 using ( var manager = CreateManager ( ) )
185194 {
186195 for ( var i = 0 ; i < noOfConcurrentClients ; i ++ )
187196 {
188197 var clientNo = i ;
189198 var action = ( Action ) ( ( ) => UseClient ( manager , clientNo , clientUsageMap ) ) ;
199+ #if NETCORE
200+ tasks . Add ( Task . Run ( action ) ) ;
201+ #else
190202 clientAsyncResults . Add ( action . BeginInvoke ( null , null ) ) ;
203+ #endif
191204 }
192205 }
193206
207+ #if NETCORE
208+ Task . WaitAll ( tasks . ToArray ( ) ) ;
209+ #else
194210 WaitHandle . WaitAll ( clientAsyncResults . ConvertAll ( x => x . AsyncWaitHandle ) . ToArray ( ) ) ;
211+ #endif
195212
196213 Debug . WriteLine ( TypeSerializer . SerializeToString ( clientUsageMap ) ) ;
197214
You can’t perform that action at this time.
0 commit comments