Skip to content

Commit

Permalink
close the hot bunnies connection after the specs have run, and use a …
Browse files Browse the repository at this point in the history
…shared example for code reuse
  • Loading branch information
joshk committed Apr 27, 2012
1 parent 4438cb1 commit 5a881e6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
9 changes: 4 additions & 5 deletions spec/factory_spec.rb
@@ -1,11 +1,10 @@
require 'spec_helper'

describe Travis::Worker::Factory do
let(:connection) { HotBunnies.connect(:hostname => "127.0.0.1") }
let(:config) { Hashr.new({ :queues => %w(builds.php builds.python builds.perl) }) }
let(:factory) do
Travis::Worker::Factory.new('worker-name', config, connection)
end
include_context "hot_bunnies connection"

let(:config) { Hashr.new({ :queues => %w(builds.php builds.python builds.perl) }) }
let(:factory) { Travis::Worker::Factory.new('worker-name', config, connection) }
let(:worker) { factory.worker }

describe 'worker' do
Expand Down
5 changes: 2 additions & 3 deletions spec/pool_spec.rb
Expand Up @@ -2,10 +2,9 @@
require 'stringio'

describe Travis::Worker::Pool do
let(:names) { %w(worker-1 worker-2)}
let(:connection) { HotBunnies.connect(:hostname => "127.0.0.1") }

include_context "hot_bunnies connection"

let(:names) { %w(worker-1 worker-2)}
let(:pool) { Travis::Worker::Pool.new(names, Travis::Worker.config, connection) }
let(:workers) { names.map { |name| stub(name, :name => name, :boot => nil, :start => nil, :stop => nil) } }

Expand Down
21 changes: 7 additions & 14 deletions spec/reporters/log_streamer_spec.rb
@@ -1,29 +1,22 @@
require 'spec_helper'

describe Travis::Worker::Reporters::LogStreamer do
let(:connection) { HotBunnies.connect(:hostname => "127.0.0.1") }
let(:channel) { connection.create_channel }
let(:routing_key) do
"reporting.jobs.builds.jvmotp"
end
let(:queue) do
channel.queue(routing_key, :durable => true)
end
let(:reporting_exchange) do
channel.exchange("reporting", :type => :topic, :durable => true)
end
include_context "hot_bunnies connection"

let(:reporter) { described_class.new('staging-1', connection.create_channel, routing_key) }
let(:channel) { connection.create_channel }
let(:routing_key) { "reporting.jobs.builds.jvmotp" }
let(:queue) { channel.queue(routing_key, :durable => true) }
let(:reporting_exchange) { channel.exchange("reporting", :type => :topic, :durable => true) }
let(:reporter) { described_class.new('staging-1', connection.create_channel, routing_key) }

include Travis::Serialization


describe 'notify' do
before :each do
queue.purge

queue.bind(reporting_exchange, :routing_key => routing_key)
end

after :each do
connection.close
end
Expand Down
3 changes: 2 additions & 1 deletion spec/reporters/state_reporter_spec.rb
@@ -1,7 +1,8 @@
require 'spec_helper'

describe Travis::Worker::Reporters::StateReporter do
let(:connection) { HotBunnies.connect(:hostname => "127.0.0.1") }
include_context "hot_bunnies connection"

let(:reporter) { described_class.new('staging-1', connection.create_channel) }
let(:logger) { stub('logger', :before => nil, :after => nil) }
let(:io) { StringIO.new }
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -13,7 +13,7 @@
require 'stringio'

FIXTURES = {}
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| load f}
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| load f }

include Mocha::API

Expand Down
4 changes: 4 additions & 0 deletions spec/support/hot_bunnies.rb
@@ -0,0 +1,4 @@
shared_context "hot_bunnies connection" do
let(:connection) { HotBunnies.connect(:hostname => "127.0.0.1") }
after(:all) { connection.close }
end
3 changes: 2 additions & 1 deletion spec/worker_spec.rb
Expand Up @@ -4,12 +4,13 @@
require "hot_bunnies"

describe Travis::Worker do
include_context "hot_bunnies connection"

let(:vm) { stub('vm', :name => 'vm-name', :shell => nil, :prepare => nil) }
let(:reporter) { stub('reporter', :notify => nil) }
let(:queue_names) { %w(builds.php builds.python builds.perl) }
let(:config) { Hashr.new(:amqp => {}, :queues => queue_names) }

let(:connection) { HotBunnies.connect(:hostname => "127.0.0.1") }
let(:worker) { Travis::Worker.new('worker-1', vm, connection, queue_names, config) }

let(:metadata) { stub('metadata', :ack => nil, :routing_key => "builds.common") }
Expand Down

0 comments on commit 5a881e6

Please sign in to comment.