Sha256: 5e3c44a5921ca71cabbd2ba2ac72da20289f74fb5b8ecde747f5d4b3efc2d170

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

shared_examples_for 'JobQueue adapter basic' do
  it "should write onto queue and fetch stuff back off" do
    JobQueue.put("hello")

    JobQueue.subscribe do |job|
      @job = job
      throw :stop
    end

    @job.should == "hello"
  end

  it "should pull items off in the order the were added" do
    JobQueue.put("foo")
    JobQueue.put("bar")

    retrieved_jobs = []

    begin
      Timeout::timeout(0.5) do
        JobQueue.subscribe do |job|
          retrieved_jobs << job
        end
      end
    rescue Timeout::Error

    end

    retrieved_jobs[0].should == "foo"
    retrieved_jobs[1].should == "bar"
    retrieved_jobs[2].should == nil
  end
end

shared_examples_for "JobQueue adapter named queues" do
  it "should put jobs onto a named queue and only read off that queue" do
    JobQueue.put("hello", :queue => "test")
    lambda {
      Timeout.timeout(0.1) do
        JobQueue.subscribe(:queue => "foo") do |job|
          throw :stop
        end
      end
    }.should raise_error(Timeout::Error)
    should_not_timeout {
      JobQueue.subscribe(:queue => "test") do |body|
        body.should == 'hello'
        throw :stop
      end
    }
  end
end

shared_examples_for "JobQueue adapter queue length" do
  it "should report the length of the named queue" do
    JobQueue.queue_length('test').should == 0
    5.times { JobQueue.put("hello", :queue => "test") }
    JobQueue.queue_length('test').should == 5
    JobQueue.subscribe(:queue => "test") do |job|
      throw :stop
    end
    JobQueue.queue_length('test').should == 4
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
mloughran-job_queue-0.0.10 spec/common_adapter_spec.rb
mloughran-job_queue-0.0.11 spec/common_adapter_spec.rb
job_queue-0.0.12 spec/common_adapter_spec.rb
job_queue-0.0.11 spec/common_adapter_spec.rb
job_queue-0.0.10 spec/common_adapter_spec.rb