Sha256: e132fabbda5df714a10a770eafcd2a8ca7dcccfef5db21174b92c71468d6e44c

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 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 "BLPOP" do |r|
  r.lpush("foo", "s1")
  r.lpush("foo", "s2")

  thread = Thread.new do
    redis = Redis::Distributed.new(NODES)
    sleep 0.3
    redis.lpush("foo", "s3")
  end

  assert ["foo", "s2"] == r.blpop("foo", 1)
  assert ["foo", "s1"] == r.blpop("foo", 1)
  assert ["foo", "s3"] == r.blpop("foo", 1)

  thread.join
end

test "BRPOP" do |r|
  r.rpush("foo", "s1")
  r.rpush("foo", "s2")

  t = Thread.new do
    redis = Redis::Distributed.new(NODES)
    sleep 0.3
    redis.rpush("foo", "s3")
  end

  assert ["foo", "s2"] == r.brpop("foo", 1)
  assert ["foo", "s1"] == r.brpop("foo", 1)
  assert ["foo", "s3"] == r.brpop("foo", 1)

  t.join
end

test "BRPOP should unset a configured socket timeout" do |r|
  r = Redis::Distributed.new(NODES, :timeout => 1)

  assert_nothing_raised do
    r.brpop("foo", 2)
  end # Errno::EAGAIN raised if socket times out before redis command times out

  assert r.nodes.all? { |node| node.client.timeout == 1 }
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
modesty-0.1.0 vendor/redis-rb/test/distributed_blocking_commands_test.rb