Sha256: 16a7cc7254406d3b260d3b0e7b8fb41f3ab423e8e82f9645c1a510232e11f0c4

Contents?: true

Size: 1.7 KB

Versions: 12

Compression:

Stored size: 1.7 KB

Contents

#
# Specifying rufus-scheduler
#
# Thu Jul 25 05:53:51 JST 2013
#

require 'spec_helper'


describe Rufus::Scheduler do

  before :each do
    @scheduler = Rufus::Scheduler.new
  end
  after :each do
    @scheduler.shutdown
  end

  context 'thread pool' do

    it 'starts with an empty thread pool' do

      expect(@scheduler.work_threads.size).to eq(0)
    end

    it 'does not cross the max_work_threads threshold' do

      #@scheduler.min_work_threads = 2
      @scheduler.max_work_threads = 5

      10.times do
        @scheduler.in '0s' do
          sleep 5
        end
      end

      sleep 0.5

      #@scheduler.job_threads.each do |t|
      #  p t.keys
      #  p t[:rufus_scheduler_job].class
      #end

      expect(@scheduler.work_threads.size).to eq(5)
    end

    it 'does not cross the max_work_threads threshold (overlap: false)' do

      #@scheduler.min_work_threads = 2
      @scheduler.max_work_threads = 5

      10.times do
        @scheduler.in '0s', :overlap => false do
          sleep 5
        end
      end

      sleep 0.5

      #@scheduler.job_threads.each do |t|
      #  p t.keys
      #  p t[:rufus_scheduler_job].class
      #end

      expect(@scheduler.work_threads.size).to eq(5)
    end

    it 'does not execute unscheduled jobs' do

      @scheduler.max_work_threads = 1

      counter = 0

      job0 =
        @scheduler.schedule_in '0.3s' do
          counter += 1
          sleep 1
        end
      job1 =
        @scheduler.schedule_in '0.35s' do
          counter += 1
          sleep 1
        end

      sleep(0.1) while counter < 1
      sleep(0.1) while @scheduler.work_queue.size < 1
      job1.unschedule

      sleep(2)

      expect(counter).to eq(1)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rufus-scheduler-3.1.9 spec/threads_spec.rb
rufus-scheduler-3.1.8 spec/threads_spec.rb
rufus-scheduler-3.1.7 spec/threads_spec.rb
rufus-scheduler-3.1.6 spec/threads_spec.rb
rufus-scheduler-3.1.5 spec/threads_spec.rb
rufus-scheduler-3.1.4 spec/threads_spec.rb
rufus-scheduler-3.1.3 spec/threads_spec.rb
rufus-scheduler-3.1.2 spec/threads_spec.rb
rufus-scheduler-3.1.1 spec/threads_spec.rb
rufus-scheduler-3.1.0 spec/threads_spec.rb
rufus-scheduler-3.0.9 spec/threads_spec.rb
rufus-scheduler-3.0.8 spec/threads_spec.rb