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

Commit 8e47f56

Browse files
committed
Make ServiceStack.Redis.Tests compilable on .NET Core
1 parent 738d5c7 commit 8e47f56

14 files changed

+42
-14
lines changed

src/ServiceStack.Redis/RedisNativeClient_Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ protected T SendReceive<T>(byte[][] cmdWithBinaryArgs,
598598

599599
Interlocked.Increment(ref RedisState.TotalRetryCount);
600600
#if NETSTANDARD
601-
Task.Delay(GetBackOffMultiplier(++i));
601+
Task.Delay(GetBackOffMultiplier(++i)).Wait();
602602
#else
603603
Thread.Sleep(GetBackOffMultiplier(++i));
604604
#endif

src/ServiceStack.Redis/RedisPubSubServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ private void RunLoop()
335335
{
336336
if (WaitBeforeNextRestart != null)
337337
#if NETSTANDARD
338-
Task.Delay(WaitBeforeNextRestart.Value);
338+
Task.Delay(WaitBeforeNextRestart.Value).Wait();
339339
#else
340340
Thread.Sleep(WaitBeforeNextRestart.Value);
341341
#endif
@@ -474,7 +474,7 @@ private void SleepBackOffMultiplier(int continuousErrorsCount)
474474
Log.Debug("Sleeping for {0}ms after {1} continuous errors".Fmt(nextTry, continuousErrorsCount));
475475

476476
#if NETSTANDARD
477-
Task.Delay(nextTry);
477+
Task.Delay(nextTry).Wait();
478478
#else
479479
Thread.Sleep(nextTry);
480480
#endif

src/ServiceStack.Redis/RedisSentinel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ private RedisSentinelWorker GetValidSentinelWorker()
335335

336336
this.failures = 0; //reset
337337
#if NETSTANDARD
338-
Task.Delay(WaitBetweenFailedHosts);
338+
Task.Delay(WaitBetweenFailedHosts).Wait();
339339
#else
340340
Thread.Sleep(WaitBetweenFailedHosts);
341341
#endif

src/ServiceStack.Redis/RedisSentinelResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public virtual RedisClient CreateRedisClient(RedisEndpoint config, bool master)
152152

153153
sentinel.ForceMasterFailover();
154154
#if NETSTANDARD
155-
Task.Delay(sentinel.WaitBetweenFailedHosts);
155+
Task.Delay(sentinel.WaitBetweenFailedHosts).Wait();
156156
#else
157157
Thread.Sleep(sentinel.WaitBetweenFailedHosts);
158158
#endif

src/ServiceStack.Redis/Support/Locking/DistributedLock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public virtual long Lock(string key, int acquisitionTimeout, int lockTimeout, ou
4141
while (wasSet == 0 && count < tryCount && totalTime < acquisitionTimeout)
4242
{
4343
#if NETSTANDARD
44-
System.Threading.Tasks.Task.Delay(sleepIfLockSet);
44+
System.Threading.Tasks.Task.Delay(sleepIfLockSet).Wait();
4545
#else
4646
System.Threading.Thread.Sleep(sleepIfLockSet);
4747
#endif
@@ -83,7 +83,7 @@ public virtual long Lock(string key, int acquisitionTimeout, int lockTimeout, ou
8383
}
8484
if (wasSet != LOCK_NOT_ACQUIRED) break;
8585
#if NETSTANDARD
86-
System.Threading.Tasks.Task.Delay(sleepIfLockSet);
86+
System.Threading.Tasks.Task.Delay(sleepIfLockSet).Wait();
8787
#else
8888
System.Threading.Thread.Sleep(sleepIfLockSet);
8989
#endif

tests/ServiceStack.Redis.Tests/CultureInfoTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@ public class CultureInfoTests
1313
[TestFixtureSetUp]
1414
public void TestFixtureSetUp()
1515
{
16+
#if NETCORE
17+
previousCulture = CultureInfo.CurrentCulture;
18+
CultureInfo.CurrentCulture = new CultureInfo("fr-FR");
19+
#else
1620
previousCulture = Thread.CurrentThread.CurrentCulture;
1721
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
1822
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
23+
#endif
1924
}
2025

2126
[TestFixtureTearDown]
2227
public void TestFixtureTearDown()
2328
{
29+
#if NETCORE
30+
CultureInfo.CurrentCulture = previousCulture;
31+
#else
2432
Thread.CurrentThread.CurrentCulture = previousCulture;
33+
#endif
2534
}
2635

2736
[Test]

tests/ServiceStack.Redis.Tests/Issues/TransactionIssueTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private void CheckThisConnection()
107107
}
108108
}
109109

110-
private void CheckConnection()
110+
private void CheckConnection(object state)
111111
{
112112
Task.Factory.StartNew(CheckThisConnection);
113113
}

tests/ServiceStack.Redis.Tests/LicenseUsageTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NUnit.Framework;
88
using ServiceStack.Configuration;
99
using ServiceStack.Text;
10+
using System;
1011

1112
namespace ServiceStack.Redis.Tests
1213
{
@@ -76,7 +77,11 @@ public class RegisteredLicenseUsageTests : LicenseUsageTests
7677
[Test]
7778
public void Allows_access_of_21_types()
7879
{
80+
#if NETCORE
81+
Environment.GetEnvironmentVariable("SERVICESTACK_LICENSE");
82+
#else
7983
Licensing.RegisterLicense(new AppSettings().GetString("servicestack:license"));
84+
#endif
8085

8186
using (var client = new RedisClient(TestConfig.SingleHost))
8287
{
@@ -90,7 +95,11 @@ public void Allows_access_of_21_types()
9095
[Test, Explicit("Takes too long - but works!")]
9196
public void Allows_access_of_6100_operations()
9297
{
98+
#if NETCORE
99+
Environment.GetEnvironmentVariable("SERVICESTACK_LICENSE");
100+
#else
93101
Licensing.RegisterLicense(new AppSettings().GetString("servicestack:license"));
102+
#endif
94103

95104
using (var client = new RedisClient(TestConfig.SingleHost))
96105
{

tests/ServiceStack.Redis.Tests/RedisBenchmarkTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#if !NETCORE_SUPPORT
2+
using System;
23
using System.Diagnostics;
34
using NUnit.Framework;
45
using ServiceStack.Logging;
@@ -248,3 +249,4 @@ public void Benchmark_SET_raw_bytes_1k_Sider()
248249
}
249250

250251
}
252+
#endif

tests/ServiceStack.Redis.Tests/RedisCacheClientTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void Can_Set_and_Get_key_with_all_byte_values()
7272
Assert.That(resultValue, Is.EquivalentTo(value));
7373
}
7474

75+
#if !NETCORE_SUPPORT
7576
[Test]
7677
public void Can_Replace_By_Pattern()
7778
{
@@ -102,6 +103,7 @@ public void Can_Replace_By_Pattern()
102103
result2 = cacheClient.Get<string>("string1");
103104
Assert.That(result2, Is.Null);
104105
}
106+
#endif
105107

106108
[Test]
107109
public void Can_GetTimeToLive()

0 commit comments

Comments
 (0)