Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit e38119e

Browse files
committed
Fix 10 tests on .NET Core
1 parent e464e46 commit e38119e

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

tests/ServiceStack.Redis.Tests/Integration/IntegrationTestBase.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
using System.Threading;
55
using NUnit.Framework;
66
using ServiceStack.Text;
7+
#if NETCORE
8+
using System.Threading.Tasks;
9+
#endif
710

811
namespace 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
}

tests/ServiceStack.Redis.Tests/Integration/MultiThreadedRedisClientIntegrationTests.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
using NUnit.Framework;
66
using ServiceStack.Common.Tests.Models;
77
using ServiceStack.Text;
8+
#if NETCORE
9+
using System.Threading.Tasks;
10+
#endif
811

912
namespace 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

tests/ServiceStack.Redis.Tests/PooledRedisClientManagerTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
using System.Threading;
66
using NUnit.Framework;
77
using ServiceStack.Text;
8+
#if NETCORE
9+
using System.Threading.Tasks;
10+
#endif
811

912
namespace 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();

tests/ServiceStack.Redis.Tests/RedisManagerPoolTests.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
using System.Threading;
55
using NUnit.Framework;
66
using ServiceStack.Text;
7+
#if NETCORE
8+
using System.Threading.Tasks;
9+
#endif
710

811
namespace 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

0 commit comments

Comments
 (0)