Sha256: 4763e844416d727d91d96a247ec82d0dc0f70d4229733ea4ac78678c996d5bf7

Contents?: true

Size: 1.22 KB

Versions: 323

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

def run_in_two_threads(proc1, proc2)
  t1 = Thread.new &proc1
  sleep test_latency # t1 must run before t2
  t2 = Thread.new { proc2.call; Thread.kill t1 }
  t2.join(test_latency * 2)
ensure
  Thread.kill t1 if t1
  Thread.kill t2 if t2
end

describe Listen::Turnstile do
  before { @called = false }

  describe '#wait' do
    context 'without a signal' do
      it 'blocks one thread indefinitely' do
        run_in_two_threads lambda {
          subject.wait
          @called = true
        }, lambda {
          sleep test_latency
        }
        @called.should be_false
      end
    end

    context 'with a signal' do
      it 'blocks one thread until it recieves a signal from another thread' do
        run_in_two_threads lambda {
          subject.wait
          @called = true
        }, lambda {
          subject.signal
          sleep test_latency
        }
        @called.should be_true
      end
    end
  end

  describe '#signal' do
    context 'without a wait-call before' do
      it 'does nothing' do
        run_in_two_threads lambda {
          subject.signal
          @called = true
        }, lambda {
          sleep test_latency
        }
        @called.should be_true
      end
    end
  end
end

Version data entries

323 entries across 224 versions & 13 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-4.4.0 bundle/ruby/2.5.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-4.3.1 bundle/ruby/2.5.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-4.3.0 bundle/ruby/2.5.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-4.2.1 bundle/ruby/2.5.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-4.2.0 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-4.1.1 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-4.1.0 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-4.0.1 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-4.0.1.pre1 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-4.0.0 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-3.7.2 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-3.7.1 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/spec/listen/turnstile_spec.rb
sass-3.4.25 vendor/listen/spec/listen/turnstile_spec.rb
brakeman-3.7.0 bundle/ruby/2.3.0/gems/sass-3.4.24/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-3.6.2 bundle/ruby/2.3.0/gems/sass-3.4.24/vendor/listen/spec/listen/turnstile_spec.rb
sass-3.4.24 vendor/listen/spec/listen/turnstile_spec.rb
brakeman-3.6.1 bundle/ruby/2.3.0/gems/sass-3.4.23/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-3.6.0 bundle/ruby/2.3.0/gems/sass-3.4.23/vendor/listen/spec/listen/turnstile_spec.rb
brakeman-3.5.0 bundle/ruby/2.3.0/gems/sass-3.4.23/vendor/listen/spec/listen/turnstile_spec.rb