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