-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
RabbitMQ * Implement retry for Harmoniser::Connection#start * Prevent Harmoniser::Connection#close to raise exception. Prefer log to error the exception and terminate gracefully
- Loading branch information
Showing
8 changed files
with
106 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
harmoniser (0.7.0) | ||
harmoniser (0.8.0) | ||
bunny (~> 2.22) | ||
|
||
GEM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Harmoniser | ||
VERSION = "0.7.0" | ||
VERSION = "0.8.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,13 +20,60 @@ | |
expect(subject).to respond_to(:recovering_from_network_failure?) | ||
end | ||
|
||
it "responds to start" do | ||
expect(subject).to respond_to(:start) | ||
end | ||
|
||
describe "#to_s" do | ||
it "returns a string representation of the connection" do | ||
expect(subject.to_s).to eq("<Harmoniser::Connection>: [email protected]:5672, connection_name = `wadus`, vhost = `/`") | ||
end | ||
end | ||
|
||
describe "#start" do | ||
let(:bunny) { subject.instance_variable_get(:@bunny) } | ||
|
||
it "retries establishing connection until succeeding" do | ||
allow(Harmoniser.logger).to receive(:error) | ||
allow(subject).to receive(:sleep) | ||
allow(bunny).to receive(:start) do | ||
@retries ||= 0 | ||
if @retries < 2 | ||
@retries += 1 | ||
raise "Error" | ||
end | ||
end | ||
|
||
subject.start | ||
|
||
expect(Harmoniser.logger).to have_received(:error).with(/Connection attempt failed: retries = `.*`, error_class = `RuntimeError`, error_message = `Error`/).twice | ||
end | ||
end | ||
|
||
describe "#close" do | ||
let(:bunny) { subject.instance_variable_get(:@bunny) } | ||
|
||
it "returns true" do | ||
allow(bunny).to receive(:close) | ||
|
||
result = subject.close | ||
|
||
expect(result).to eq(true) | ||
end | ||
|
||
context "when closing connection fails" do | ||
it "returns false" do | ||
allow(bunny).to receive(:close).and_raise("Error") | ||
|
||
result = subject.close | ||
|
||
expect(result).to eq(false) | ||
end | ||
|
||
it "log with error severity is output" do | ||
allow(bunny).to receive(:close).and_raise("Error") | ||
allow(Harmoniser.logger).to receive(:error) | ||
|
||
subject.close | ||
|
||
expect(Harmoniser.logger).to have_received(:error).with(/Connection#close failed: error_class = `RuntimeError`, error_message = `Error`/) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters