Sha256: 96c65844310f8c52bd4a39238120a7dbfb94b9cbd3b6fe817de5652e9d780fec

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

require "spec_helper"

describe Wamp::Worker::Queue do
  let(:name) { :default }
  let(:queue) { described_class.new(name) }
  let(:queue_name) { "test:command" }
  let(:handle) { "test:response" }
  let(:params) { { temp: true } }

  it "general push/pop" do
    # Push the request
    queue.push queue_name, :call, params, handle

    # Pop the request
    descriptor = queue.pop(queue_name, wait: true)
    expect(descriptor.command).to eq(:call)
    expect(descriptor.handle).to eq(handle)
    expect(descriptor.params).to eq(params)

    # Check and make sure the key still exists
    expect(queue.redis.exists(queue_name)).to eq(true)
  end

  it "deletes on pop" do
    expect(queue.redis.exists(queue_name)).to eq(false)

    # Push the request
    queue.push queue_name, :call, params, handle

    expect(queue.redis.exists(queue_name)).to eq(true)

    # Pop the request
    descriptor = queue.pop(queue_name, delete: true)
    expect(descriptor.command).to eq(:call)
    expect(descriptor.handle).to eq(handle)
    expect(descriptor.params).to eq(params)

    expect(queue.redis.exists(queue_name)).to eq(false)
  end

  it "timeout" do
    # Pop the descriptor
    descriptor = queue.pop(queue_name, wait: true, timeout: 1)

    # It should be nil
    expect(descriptor).to eq(nil)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wamp-worker-0.1.1 spec/wamp/worker/queue_spec.rb
wamp-worker-0.1.0 spec/wamp/worker/queue_spec.rb