Skip to content

Commit

Permalink
unit test that fails due to a bug in Redis 3.9.11 :
Browse files Browse the repository at this point in the history
When you subscribe to a message with a wildcard pattern,
when the onmessage should return the message, but returns the topic instead.
  • Loading branch information
stevegraygh committed Sep 20, 2012
1 parent 8262897 commit ff59b47
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion tests/ServiceStack.Redis.Tests/RedisPubSubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,56 @@ public void Can_Subscribe_and_Publish_single_message()
Assert.That(Redis.Get<int>(key), Is.EqualTo(2));
}

[Test]
[Test]
public void Can_Subscribe_and_Publish_single_message_using_wildcard()
{
var channelWildcard = PrefixedKey("CHANNEL.*");
var channelName = PrefixedKey("CHANNEL.1");
const string message = "Hello, World!";
var key = PrefixedKey("Can_Subscribe_and_Publish_single_message");

Redis.IncrementValue(key);

using (var subscription = Redis.CreateSubscription())
{
subscription.OnSubscribe = channel =>
{
Log("Subscribed to '{0}'", channelWildcard);
Assert.That(channel, Is.EqualTo(channelWildcard));
};
subscription.OnUnSubscribe = channel =>
{
Log("UnSubscribed from '{0}'", channelWildcard);
Assert.That(channel, Is.EqualTo(channelWildcard));
};
subscription.OnMessage = (channel, msg) =>
{
Log("Received '{0}' from channel '{1}'", msg, channel);
Assert.That(channel, Is.EqualTo(channelWildcard));
Assert.That(msg, Is.EqualTo(message), "we should get the message, not the channel");
subscription.UnSubscribeFromAllChannels();
};

ThreadPool.QueueUserWorkItem(x =>
{
Thread.Sleep(100); // to be sure that we have subscribers
using (var redisClient = CreateRedisClient())
{
Log("Publishing '{0}' to '{1}'", message, channelName);
redisClient.PublishMessage(channelName, message);
}
});

Log("Start Listening On " + channelName);
subscription.SubscribeToChannelsMatching(channelWildcard); //blocking
}

Log("Using as normal client again...");
Redis.IncrementValue(key);
Assert.That(Redis.Get<int>(key), Is.EqualTo(2));
}

[Test]
public void Can_Subscribe_and_Publish_multiple_message()
{
var channelName = PrefixedKey("CHANNEL2");
Expand Down

0 comments on commit ff59b47

Please sign in to comment.