Add LockBehavior to semaphore spec.

This commit is contained in:
Patrick Mahoney 2012-02-23 21:37:19 -06:00
parent 5dc3c7299e
commit d012a11237
3 changed files with 20 additions and 2 deletions

View File

@ -1,8 +1,6 @@
require 'spec_helper' require 'spec_helper'
require 'process_shared' require 'process_shared'
require 'process_shared/lock_behavior'
module ProcessShared module ProcessShared
describe Mutex do describe Mutex do

View File

@ -5,6 +5,25 @@ require 'process_shared'
module ProcessShared module ProcessShared
describe Semaphore do describe Semaphore do
describe 'As Lock' do
include LockBehavior
before :each do
@lock = Semaphore.new
class << @lock
alias_method :lock, :wait
alias_method :unlock, :post
end
end
after :each do
@lock.close
end
end
it 'coordinates access to shared object' do it 'coordinates access to shared object' do
nprocs = 4 # number of processes nprocs = 4 # number of processes
nincrs = 1000 # each process increments nincrs times nincrs = 1000 # each process increments nincrs times

View File

@ -5,6 +5,7 @@ require 'minitest/autorun'
require 'minitest/matchers' require 'minitest/matchers'
require 'process_shared' require 'process_shared'
require 'process_shared/lock_behavior'
class RangeMatcher class RangeMatcher
def initialize(operator, limit) def initialize(operator, limit)