Skip to content

Commit

Permalink
Adds spec updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
randy-girard committed Jun 13, 2017
1 parent a818c91 commit 6f5fc81
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 20 deletions.
2 changes: 2 additions & 0 deletions lib/emque/consuming/adapters/rabbit_mq/manager.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "bunny"
require_relative "error_worker"
require_relative "delayed_message_worker"

module Emque
module Consuming
Expand Down
99 changes: 84 additions & 15 deletions spec/adapters/rabbit_mq/worker/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,95 @@
require "emque/consuming/adapters/rabbit_mq/worker"
require "pry"

module Emque
module Consuming
module Adapters
module RabbitMq
class Worker
def start
logger.info "#{log_prefix} starting..."
logger.info "RabbitMQ Worker: Skipping consuming during test."
logger.debug "#{log_prefix} started"
end
end
end
end
end
end

describe Emque::Consuming::Adapters::RabbitMq::Worker do
describe "#initialize" do
Dummy::Application.config.purge_queues_on_start = false
Dummy::Application.config.set_adapter(:rabbit_mq)
Dummy::Application.router.map do
topic "events" => EventsConsumer do
map "events.new" => "new_event"
end
before do
@connection = Bunny.new
@connection.start
@channel = @connection.create_channel
@channel.queue_delete("emque.dummy.spec")
@fanout = @channel.fanout("dummy.spec",
:durable => true,
:auto_delete => false
)
@queue = @channel
.queue("emque.dummy.spec", {
:durable => true,
:auto_delete => false,
:arguments => {
"x-dead-letter-exchange" => "dummy.error"
}
}).bind(@fanout)
@queue.publish(Oj.dump({
:metadata => {
:topic => "spec",
:type => "dummy.spec"
}
}))

end

app = Dummy::Application.new
connection = Bunny.new
connection.start
manager = Dummy::Application.config.adapter.manager.new
app.start
after do
@channel.queue_delete("emque.dummy.spec")
@connection.close
end

# expect(queue.message_count).to be eq(10)
it "should not purge queues on start" do
Dummy::Application.config.purge_queues_on_start = false
Dummy::Application.config.set_adapter(:rabbit_mq)
Dummy::Application.router.map do
topic "spec" => SpecConsumer do; end
end
app = Dummy::Application.new
connection = Bunny.new
connection.start
connection.with_channel do |channel|
@queue = channel.queue("emque.dummy.spec", :passive => true)
expect(@queue.message_count).to eq(1)
end
app.start
sleep 0.3
connection.with_channel do |channel|
@queue = channel.queue("emque.dummy.spec", :passive => true)
expect(@queue.message_count).to eq(1)
end
end

# app.manager.workers.first.last.first.send(:queue).publish("tsting", :routing_key => "events")
# app.manager.workers.first.last.first.send(:channel).default_exchange.publish("test")
# app.manager.workers.first.last.first.send(:queue).message_count
it "should purge queues on start" do
Dummy::Application.config.purge_queues_on_start = true
Dummy::Application.config.set_adapter(:rabbit_mq)
Dummy::Application.router.map do
topic "spec" => SpecConsumer do; end
end
app = Dummy::Application.new
connection = Bunny.new
connection.start
connection.with_channel do |channel|
@queue = channel.queue("emque.dummy.spec", :passive => true)
expect(@queue.message_count).to eq(1)
end
app.start
sleep 0.3
connection.with_channel do |channel|
@queue = channel.queue("emque.dummy.spec", :passive => true)
expect(@queue.message_count).to eq(0)
end
end
end
end
4 changes: 2 additions & 2 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ module Emque
module Consuming
module Adapters
module RabbitMq
def self.default_options; {}; end
def self.default_options; { :durable => true }; end
def self.load; end
def self.manager
Emque::Consuming::Adapters::RabbitMq::Manager
end
end
module TestAdapter
def self.default_options; {}; end
def self.default_options; { :durable => true }; end
def self.load; end
def self.manager
Emque::Consuming::Adapters::TestAdapter::Manager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class EventsConsumer
class SpecConsumer
include Emque::Consuming.consumer

def new_event(message)
def test(message)
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require "timecop"
require "fileutils"
require_relative "dummy/config/application"
require_relative "dummy/consumers/events_consumer"
require_relative "dummy/consumers/spec_consumer"

module VerifyAndResetHelpers
def verify(object)
Expand Down

0 comments on commit 6f5fc81

Please sign in to comment.