Sha256: e58d7a5a8b6d2bb85416d5d2725f96217b56a56c9def7e31e445f559d836f55b

Contents?: true

Size: 898 Bytes

Versions: 12

Compression:

Stored size: 898 Bytes

Contents

require "spec_helper"

describe "Thread-Safety" do
  include Redistat::Database
  
  before(:each) do
    db.flushdb
  end
  
  #TODO should have more comprehensive thread-safe tests
  
  it "should incr in multiple threads" do
    threads = []
    50.times do
      threads << Thread.new {
        db.incr("spec:incr")
      }
    end
    threads.each { |t| t.join }
    db.get("spec:incr").should == "50"
  end
  
  it "should store event in multiple threads" do
    class ThreadSafetySpec
      include Redistat::Model
    end
    threads = []
    50.times do
      threads << Thread.new {
        ThreadSafetySpec.store("spec:threadsafe", {:count => 1, :rand => rand(5)})
      }
    end
    threads.each { |t| t.join }
    result = ThreadSafetySpec.fetch("spec:threadsafe", 5.hours.ago, 5.hours.from_now)
    result.total[:count].should == 50
    result.total[:rand].should <= 250
  end
  
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
redistat-0.3.0 spec/thread_safety_spec.rb
redistat-0.2.6 spec/thread_safety_spec.rb
redistat-0.2.5 spec/thread_safety_spec.rb
redistat-0.2.4 spec/thread_safety_spec.rb
redistat-0.2.3 spec/thread_safety_spec.rb
redistat-0.2.2 spec/thread_safety_spec.rb
redistat-0.2.1 spec/thread_safety_spec.rb
redistat-0.2.0 spec/thread_safety_spec.rb
redistat-0.1.1 spec/thread_safety_spec.rb
redistat-0.1.0 spec/thread_safety_spec.rb
redistat-0.0.9 spec/thread_safety_spec.rb
redistat-0.0.8 spec/thread_safety_spec.rb