Sha256: 69debca3bf3ce5b3c6915445b167b6e979cb18b197127d566d55c3b0cc74c273
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
require 'spec_helper' describe 'acquire_lock' do it "acquires the lock if it does not exist" do @redis.send(:acquire_lock, "test").should == true end it "acquires the lock if it is expired" do @redis.send(:acquire_lock, "test", 0.1).should == true sleep(1) @redis.send(:acquire_lock, "test").should == true end it "raise errors when acquiring the lock takes too long" do @redis.send(:acquire_lock, "test", 60, 60).should == true lambda { @redis.send(:acquire_lock, "test", 60, 1) }.should raise_error end it "waits until the other thread finishes and acquire lock" do start_time = Time.now.to_i @redis.send(:acquire_lock, "test", 60, 60).should == true Thread.new { Thread.current.join(1) sleep(5) @redis.send(:release_lock, "test", 60).should == true } Thread.current.join(1) @redis.send(:acquire_lock, "test", 60, 20).should == true (Time.now.to_i - start_time).should be > 4 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby_redis_lock-0.1.0 | spec/acquire_lock_spec.rb |