From d012a11237e5cc152d9ad91af1b6061c9465894c Mon Sep 17 00:00:00 2001 From: Patrick Mahoney Date: Thu, 23 Feb 2012 21:37:19 -0600 Subject: [PATCH] Add LockBehavior to semaphore spec. --- spec/process_shared/mutex_spec.rb | 2 -- spec/process_shared/semaphore_spec.rb | 19 +++++++++++++++++++ spec/spec_helper.rb | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/process_shared/mutex_spec.rb b/spec/process_shared/mutex_spec.rb index 07744c7..31e167e 100644 --- a/spec/process_shared/mutex_spec.rb +++ b/spec/process_shared/mutex_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' require 'process_shared' -require 'process_shared/lock_behavior' - module ProcessShared describe Mutex do diff --git a/spec/process_shared/semaphore_spec.rb b/spec/process_shared/semaphore_spec.rb index 52ba259..c6afad1 100644 --- a/spec/process_shared/semaphore_spec.rb +++ b/spec/process_shared/semaphore_spec.rb @@ -5,6 +5,25 @@ require 'process_shared' module ProcessShared 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 nprocs = 4 # number of processes nincrs = 1000 # each process increments nincrs times diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 98ea4ef..cbcdfea 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,7 @@ require 'minitest/autorun' require 'minitest/matchers' require 'process_shared' +require 'process_shared/lock_behavior' class RangeMatcher def initialize(operator, limit)