Sha256: 12bf5e4b221a176185340cbf5e29c05b65ca9eab28853dc54582f51d09694424

Contents?: true

Size: 1.94 KB

Versions: 21

Compression:

Stored size: 1.94 KB

Contents

# encoding: UTF-8

require File.expand_path("helper", File.dirname(__FILE__))

class TestDistributedPublishSubscribe < Test::Unit::TestCase

  include Helper::Distributed

  def test_subscribe_and_unsubscribe
    assert_raise Redis::Distributed::CannotDistribute do
      r.subscribe("foo", "bar") { }
    end

    assert_raise Redis::Distributed::CannotDistribute do
      r.subscribe("{qux}foo", "bar") { }
    end
  end

  def test_subscribe_and_unsubscribe_with_tags
    @subscribed = false
    @unsubscribed = false

    wire = Wire.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

    # Wait until the subscription is active before publishing
    Wire.pass while !@subscribed

    Redis::Distributed.new(NODES).publish("foo", "s1")

    wire.join

    assert @subscribed
    assert_equal 1, @t1
    assert @unsubscribed
    assert_equal 0, @t2
    assert_equal "s1", @message
  end

  def test_subscribe_within_subscribe
    @channels = []

    wire = Wire.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

    wire.join

    assert_equal ["foo", "bar"], @channels
  end

  def test_other_commands_within_a_subscribe
    assert_raise Redis::CommandError do
      r.subscribe("foo") do |on|
        on.subscribe do |channel, total|
          r.set("bar", "s2")
        end
      end
    end
  end

  def test_subscribe_without_a_block
    assert_raise LocalJumpError do
      r.subscribe("foo")
    end
  end
end

Version data entries

21 entries across 20 versions & 7 rubygems

Version Path
finsync_redis-3.3.5 test/distributed_publish_subscribe_test.rb
redis-3.3.5 test/distributed_publish_subscribe_test.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/distributed_publish_subscribe_test.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/distributed_publish_subscribe_test.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/distributed_publish_subscribe_test.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/distributed_publish_subscribe_test.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/redis-3.3.3/test/distributed_publish_subscribe_test.rb
redis-3.3.3 test/distributed_publish_subscribe_test.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.1/test/distributed_publish_subscribe_test.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.2/test/distributed_publish_subscribe_test.rb
redis-3.3.2 test/distributed_publish_subscribe_test.rb
redis-3.3.1 test/distributed_publish_subscribe_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/test/distributed_publish_subscribe_test.rb
redis-3.3.0 test/distributed_publish_subscribe_test.rb
discourse-redis-3.2.2 test/distributed_publish_subscribe_test.rb
redis-3.2.2 test/distributed_publish_subscribe_test.rb
redis-3.2.1 test/distributed_publish_subscribe_test.rb
redis-3.2.0 test/distributed_publish_subscribe_test.rb
redis-3.1.0 test/distributed_publish_subscribe_test.rb
redis-3.0.7 test/distributed_publish_subscribe_test.rb