Sha256: 5dd50d1067f0dcfbfe235fff079c9d917c3e1cf49bb9af69cc2da2419be32c2b
Contents?: true
Size: 1.05 KB
Versions: 6
Compression:
Stored size: 1.05 KB
Contents
require_relative "helper" 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
6 entries across 6 versions & 1 rubygems