Commit 64289d42 authored by Marc Gravell's avatar Marc Gravell

booleans are hard

parent dccca67c
using System.Diagnostics; using System;
using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Xunit; using Xunit;
...@@ -29,20 +30,20 @@ public Massive_Delete(ITestOutputHelper output) : base(output) ...@@ -29,20 +30,20 @@ public Massive_Delete(ITestOutputHelper output) : base(output)
private const string todoKey = "todo"; private const string todoKey = "todo";
[Fact] [Fact]
public void ExecuteMassiveDelete() public async Task ExecuteMassiveDelete()
{ {
var watch = Stopwatch.StartNew(); var watch = Stopwatch.StartNew();
using (var muxer = GetUnsecuredConnection()) using (var muxer = GetUnsecuredConnection())
using (var throttle = new SemaphoreSlim(1)) using (var throttle = new SemaphoreSlim(1))
{ {
var conn = muxer.GetDatabase(db); var conn = muxer.GetDatabase(db);
var originallyTask = conn.SetLengthAsync(todoKey); var originally = await conn.SetLengthAsync(todoKey);
int keepChecking = 1; int keepChecking = 1;
Task last = null; Task last = null;
while (Volatile.Read(ref keepChecking) == 1) while (Volatile.Read(ref keepChecking) == 1)
{ {
throttle.Wait(); // acquire throttle.Wait(); // acquire
conn.SetPopAsync(todoKey).ContinueWith(task => var x = conn.SetPopAsync(todoKey).ContinueWith(task =>
{ {
throttle.Release(); throttle.Release();
if (task.IsCompleted) if (task.IsCompleted)
...@@ -57,14 +58,14 @@ public void ExecuteMassiveDelete() ...@@ -57,14 +58,14 @@ public void ExecuteMassiveDelete()
} }
} }
}); });
GC.KeepAlive(x);
} }
if (last != null) if (last != null)
{ {
conn.Wait(last); await last;
} }
watch.Stop(); watch.Stop();
long originally = conn.Wait(originallyTask), long remaining = await conn.SetLengthAsync(todoKey);
remaining = conn.SetLength(todoKey);
Output.WriteLine("From {0} to {1}; {2}ms", originally, remaining, Output.WriteLine("From {0} to {1}; {2}ms", originally, remaining,
watch.ElapsedMilliseconds); watch.ElapsedMilliseconds);
......
...@@ -46,7 +46,7 @@ public void TestMassivePublishWithWithoutFlush_Remote() ...@@ -46,7 +46,7 @@ public void TestMassivePublishWithWithoutFlush_Remote()
private void TestMassivePublish(ISubscriber conn, string channel, string caption) private void TestMassivePublish(ISubscriber conn, string channel, string caption)
{ {
const int loop = 100000; const int loop = 10000;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers(); GC.WaitForPendingFinalizers();
......
...@@ -42,13 +42,13 @@ public void ExplicitPublishMode() ...@@ -42,13 +42,13 @@ public void ExplicitPublishMode()
} }
[Theory] [Theory]
[InlineData(null, false)] [InlineData(null, false, "a")]
[InlineData("", false)] [InlineData("", false, "b")]
[InlineData("Foo:", false)] [InlineData("Foo:", false, "c")]
[InlineData(null, true)] [InlineData(null, true, "d")]
[InlineData("", true)] [InlineData("", true, "e")]
[InlineData("Foo:", true)] [InlineData("Foo:", true, "f")]
public void TestBasicPubSub(string channelPrefix, bool wildCard) public void TestBasicPubSub(string channelPrefix, bool wildCard, string breaker)
{ {
using (var muxer = Create(channelPrefix: channelPrefix)) using (var muxer = Create(channelPrefix: channelPrefix))
{ {
...@@ -57,8 +57,8 @@ public void TestBasicPubSub(string channelPrefix, bool wildCard) ...@@ -57,8 +57,8 @@ public void TestBasicPubSub(string channelPrefix, bool wildCard)
Ping(muxer, pub, sub); Ping(muxer, pub, sub);
HashSet<string> received = new HashSet<string>(); HashSet<string> received = new HashSet<string>();
int secondHandler = 0; int secondHandler = 0;
string subChannel = wildCard ? "a*c" : "abc"; string subChannel = (wildCard ? "a*c" : "abc") + breaker;
const string pubChannel = "abc"; string pubChannel = "abc" + breaker;
Action<RedisChannel, RedisValue> handler1 = (channel, payload) => Action<RedisChannel, RedisValue> handler1 = (channel, payload) =>
{ {
lock (received) lock (received)
......
...@@ -102,7 +102,7 @@ internal Task RemoveSubscription(RedisChannel channel, Action<RedisChannel, Redi ...@@ -102,7 +102,7 @@ internal Task RemoveSubscription(RedisChannel channel, Action<RedisChannel, Redi
{ {
lock (subscriptions) lock (subscriptions)
{ {
bool asAsync = ChannelMessageQueue.IsOneOf(handler); bool asAsync = !ChannelMessageQueue.IsOneOf(handler);
if (subscriptions.TryGetValue(channel, out Subscription sub) && sub.Remove(asAsync, handler)) if (subscriptions.TryGetValue(channel, out Subscription sub) && sub.Remove(asAsync, handler))
{ {
subscriptions.Remove(channel); subscriptions.Remove(channel);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment