Sha256: 4aae18227b8166fb354b64ea084803f8a5e35644372146458b237f7e386238b8

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'

require 'concurrent/goroutine'

module Concurrent

  describe NullThreadPool do

    subject { NullThreadPool.new }

    after(:all) do
      $GLOBAL_THREAD_POOL = FixedThreadPool.new(1)
    end

    context '#post' do

      it 'proxies a call without arguments' do
        thread = Thread.new{ nil }
        Thread.should_receive(:new).with(no_args()).and_return(thread)
        $GLOBAL_THREAD_POOL.should_not_receive(:post).with(any_args())
        subject.post{ nil }
      end

      it 'proxies a call with arguments' do
        thread = Thread.new{ nil }
        Thread.should_receive(:new).with(1,2,3).and_return(thread)
        $GLOBAL_THREAD_POOL.should_not_receive(:post).with(any_args())
        subject.post(1,2,3){ nil }
      end

      it 'aliases #<<' do
        thread = Thread.new{ nil }
        Thread.should_receive(:new).with(no_args()).and_return(thread)
        $GLOBAL_THREAD_POOL.should_not_receive(:post).with(any_args())
        subject << proc{ nil }
      end
    end

    context 'operation' do

      context 'goroutine' do

        it 'gets a new thread' do
          $GLOBAL_THREAD_POOL = subject

          t = Thread.new{ nil }

          Thread.should_receive(:new).with(no_args()).and_return(t)
          go{ nil }

          Thread.should_receive(:new).with(1,2,3).and_return(t)
          go(1,2,3){ nil }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
concurrent-ruby-0.2.1 spec/concurrent/null_thread_pool_spec.rb