Sha256: 0afb9f89ce7d2d06887ac78590776e86d746cf5b4d624589fccd4b9f0a8da595

Contents?: true

Size: 1.57 KB

Versions: 9

Compression:

Stored size: 1.57 KB

Contents

# Generated by generate-specs
require 'helper'

describe_moneta "mutex" do
  def features
    []
  end

  def new_store
    Moneta.new(:Memory, :logger => {:file => File.join(make_tempdir, 'mutex.log')})
  end

  def load_value(value)
    Marshal.load(value)
  end

  include_context 'setup_store'

  it 'should have #lock' do
    mutex = Moneta::Mutex.new(store, 'mutex')
    mutex.lock.should be_true
    mutex.locked?.should be_true
    expect do
     mutex.lock
    end.to raise_error(RuntimeError)
    expect do
     mutex.try_lock
    end.to raise_error(RuntimeError)
    mutex.unlock.should be_nil
    mutex.locked?.should be_false
  end

  it 'should have #enter' do
    mutex = Moneta::Mutex.new(store, 'mutex')
    mutex.enter.should be_true
    mutex.locked?.should be_true
    expect do
     mutex.enter
    end.to raise_error(RuntimeError)
    expect do
     mutex.try_enter
    end.to raise_error(RuntimeError)
    mutex.leave.should be_nil
    mutex.locked?.should be_false
  end

  it 'should lock with #lock' do
    a = Moneta::Mutex.new(store, 'mutex')
    b = Moneta::Mutex.new(store, 'mutex')
    a.lock.should be_true
    b.try_lock.should be_false
    a.unlock.should be_nil
  end

  it 'should have lock timeout' do
    a = Moneta::Mutex.new(store, 'mutex')
    b = Moneta::Mutex.new(store, 'mutex')
    a.lock.should be_true
    b.lock(1).should be_false
    a.unlock.should be_nil
  end

  it 'should have #synchronize' do
    mutex = Moneta::Mutex.new(store, 'mutex')
    mutex.synchronize do
      mutex.locked?.should be_true
    end
    mutex.locked?.should be_false
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
moneta-0.7.19 spec/moneta/mutex_spec.rb
moneta-0.7.18 spec/moneta/mutex_spec.rb
moneta-0.7.17 spec/moneta/mutex_spec.rb
moneta-0.7.16 spec/moneta/mutex_spec.rb
moneta-0.7.15 spec/moneta/mutex_spec.rb
moneta-0.7.14 spec/moneta/mutex_spec.rb
moneta-0.7.13 spec/moneta/mutex_spec.rb
moneta-0.7.12 spec/moneta/mutex_spec.rb
moneta-0.7.11 spec/moneta/mutex_spec.rb