Sha256: 17438f2c8600009817c2f659e4738e92966a7c0cb89d04ebf1c70922bc899324

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

# encoding: UTF-8

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

class TestThreadSafety < Test::Unit::TestCase

  include Helper::Client

  driver(:ruby, :hiredis) do
    def test_thread_safety
      redis = Redis.new(OPTIONS)
      redis.set "foo", 1
      redis.set "bar", 2

      sample = 100

      t1 = Thread.new do
        $foos = Array.new(sample) { redis.get "foo" }
      end

      t2 = Thread.new do
        $bars = Array.new(sample) { redis.get "bar" }
      end

      t1.join
      t2.join

      assert_equal ["1"], $foos.uniq
      assert_equal ["2"], $bars.uniq
    end

    def test_thread_safety_queue_commit
      redis = Redis.new(OPTIONS)
      redis.set "foo", 1
      redis.set "bar", 2

      sample = 100

      t1 = Thread.new do
        sample.times do
          r.queue("get", "foo")
        end

        $foos = r.commit
      end

      t2 = Thread.new do
        sample.times do
          r.queue("get", "bar")
        end

        $bars = r.commit
      end

      t1.join
      t2.join

      assert_equal ["1"], $foos.uniq
      assert_equal ["2"], $bars.uniq
    end
  end
end

Version data entries

14 entries across 13 versions & 6 rubygems

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