Sha256: e3b37406f0539e3b7488058d4e37b05b0851dbae17e41d5203e396683632ef72
Contents?: true
Size: 1.77 KB
Versions: 1
Compression:
Stored size: 1.77 KB
Contents
# encoding: UTF-8 require File.expand_path("./helper", File.dirname(__FILE__)) require "redis/distributed" setup do log = StringIO.new init Redis::Distributed.new(NODES, :logger => ::Logger.new(log)) end test "SUBSCRIBE and UNSUBSCRIBE" do |r| assert_raise Redis::Distributed::CannotDistribute do r.subscribe("foo", "bar") { } end assert_raise Redis::Distributed::CannotDistribute do r.subscribe("{qux}foo", "bar") { } end end test "SUBSCRIBE and UNSUBSCRIBE with tags" do |r| thread = Thread.new do r.subscribe("foo") do |on| on.subscribe do |channel, total| @subscribed = true @t1 = total end on.message do |channel, message| if message == "s1" r.unsubscribe @message = message end end on.unsubscribe do |channel, total| @unsubscribed = true @t2 = total end end end Redis::Distributed.new(NODES).publish("foo", "s1") thread.join assert @subscribed assert 1 == @t1 assert @unsubscribed assert 0 == @t2 assert "s1" == @message end test "SUBSCRIBE within SUBSCRIBE" do |r| @channels = [] thread = Thread.new do r.subscribe("foo") do |on| on.subscribe do |channel, total| @channels << channel r.subscribe("bar") if channel == "foo" r.unsubscribe if channel == "bar" end end end Redis::Distributed.new(NODES).publish("foo", "s1") thread.join assert ["foo", "bar"] == @channels end test "other commands within a SUBSCRIBE" do |r| assert_raise RuntimeError do r.subscribe("foo") do |on| on.subscribe do |channel, total| r.set("bar", "s2") end end end end test "SUBSCRIBE without a block" do |r| assert_raise LocalJumpError do r.subscribe("foo") end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
modesty-0.1.0 | vendor/redis-rb/test/distributed_publish_subscribe_test.rb |