hutch 0.25.0.pre.rc1-java → 2.0.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +402 -5
- data/LICENSE +1 -0
- data/README.md +157 -47
- data/bin/ci/before_build.sh +20 -0
- data/bin/ci/before_build_docker.sh +15 -0
- data/bin/ci/install_on_debian.sh +46 -0
- data/lib/hutch/acknowledgements/nack_on_all_failures.rb +1 -1
- data/lib/hutch/adapters/bunny.rb +29 -1
- data/lib/hutch/adapters/march_hare.rb +24 -0
- data/lib/hutch/broker.rb +122 -36
- data/lib/hutch/cli.rb +23 -12
- data/lib/hutch/config.rb +45 -13
- data/lib/hutch/consumer.rb +63 -4
- data/lib/hutch/error_handlers/airbrake.rb +20 -2
- data/lib/hutch/error_handlers/base.rb +15 -0
- data/lib/hutch/error_handlers/bugsnag.rb +30 -0
- data/lib/hutch/error_handlers/honeybadger.rb +11 -3
- data/lib/hutch/error_handlers/logger.rb +7 -2
- data/lib/hutch/error_handlers/rollbar.rb +28 -0
- data/lib/hutch/error_handlers/sentry.rb +13 -11
- data/lib/hutch/error_handlers.rb +2 -1
- data/lib/hutch/publisher.rb +1 -1
- data/lib/hutch/serializers/json.rb +3 -3
- data/lib/hutch/tracers/datadog.rb +18 -0
- data/lib/hutch/tracers.rb +1 -1
- data/lib/hutch/version.rb +1 -2
- data/lib/hutch/waiter.rb +1 -1
- data/lib/hutch/worker.rb +74 -8
- data/lib/hutch.rb +8 -4
- data/lib/yard-settings/yard-settings.rb +2 -2
- data/spec/hutch/broker_spec.rb +222 -10
- data/spec/hutch/cli_spec.rb +25 -9
- data/spec/hutch/config_spec.rb +84 -12
- data/spec/hutch/consumer_spec.rb +93 -4
- data/spec/hutch/error_handlers/airbrake_spec.rb +23 -1
- data/spec/hutch/error_handlers/bugsnag_spec.rb +56 -0
- data/spec/hutch/error_handlers/honeybadger_spec.rb +22 -1
- data/spec/hutch/error_handlers/logger_spec.rb +12 -1
- data/spec/hutch/error_handlers/rollbar_spec.rb +45 -0
- data/spec/hutch/error_handlers/sentry_spec.rb +27 -2
- data/spec/hutch/message_spec.rb +1 -1
- data/spec/hutch/tracers/datadog_spec.rb +46 -0
- data/spec/hutch/waiter_spec.rb +2 -2
- data/spec/hutch/worker_spec.rb +139 -25
- data/spec/integration/channel_recovery_spec.rb +187 -0
- data/spec/integration/publish_consume_spec.rb +47 -0
- metadata +35 -61
- data/.gitignore +0 -10
- data/.rspec +0 -1
- data/.travis.yml +0 -19
- data/.yardopts +0 -5
- data/Gemfile +0 -33
- data/Guardfile +0 -14
- data/Rakefile +0 -21
- data/examples/consumer.rb +0 -13
- data/examples/producer.rb +0 -10
- data/hutch.gemspec +0 -29
- data/lib/hutch/error_handlers/opbeat.rb +0 -24
- data/lib/hutch/tracers/opbeat.rb +0 -37
- data/spec/hutch/error_handlers/opbeat_spec.rb +0 -22
- data/spec/spec_helper.rb +0 -42
- data/spec/tracers/opbeat_spec.rb +0 -44
data/spec/hutch/cli_spec.rb
CHANGED
|
@@ -4,6 +4,19 @@ require 'tempfile'
|
|
|
4
4
|
describe Hutch::CLI do
|
|
5
5
|
let(:cli) { Hutch::CLI.new }
|
|
6
6
|
|
|
7
|
+
describe "#start_work_loop" do
|
|
8
|
+
context "connection error during setup" do
|
|
9
|
+
let(:error) { Hutch::ConnectionError.new }
|
|
10
|
+
it "gets reported using error handlers" do
|
|
11
|
+
allow(Hutch).to receive(:connect).and_raise(error)
|
|
12
|
+
Hutch::Config[:error_handlers].each do |backend|
|
|
13
|
+
expect(backend).to receive(:handle_setup_exception).with(error)
|
|
14
|
+
end
|
|
15
|
+
cli.start_work_loop
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
7
20
|
describe "#parse_options" do
|
|
8
21
|
context "--config" do
|
|
9
22
|
context "when the config file does not exist" do
|
|
@@ -18,9 +31,10 @@ describe Hutch::CLI do
|
|
|
18
31
|
end
|
|
19
32
|
|
|
20
33
|
context "when the config file exists" do
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
34
|
+
# Kept in a let, so the Tempfile is not garbage collected - and with it
|
|
35
|
+
# unlinked - before the CLI checks that the path exists.
|
|
36
|
+
let(:config_file) { Tempfile.new("hutch-test-config.yaml") }
|
|
37
|
+
let(:file) { config_file.to_path }
|
|
24
38
|
|
|
25
39
|
it "parses the config" do
|
|
26
40
|
expect(Hutch::Config).to receive(:load_from_file)
|
|
@@ -42,9 +56,10 @@ describe Hutch::CLI do
|
|
|
42
56
|
end
|
|
43
57
|
|
|
44
58
|
context "when the keyfile file exists" do
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
# Kept in a let, so the Tempfile is not garbage collected - and with it
|
|
60
|
+
# unlinked - before the CLI checks that the path exists.
|
|
61
|
+
let(:key_file) { Tempfile.new("hutch-test-key.pem") }
|
|
62
|
+
let(:file) { key_file.to_path }
|
|
48
63
|
|
|
49
64
|
it "sets mq_tls_key to the file" do
|
|
50
65
|
expect(Hutch::Config).to receive(:mq_tls_key=)
|
|
@@ -66,9 +81,10 @@ describe Hutch::CLI do
|
|
|
66
81
|
end
|
|
67
82
|
|
|
68
83
|
context "when the certfile file exists" do
|
|
69
|
-
let
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
# Kept in a let, so the Tempfile is not garbage collected - and with it
|
|
85
|
+
# unlinked - before the CLI checks that the path exists.
|
|
86
|
+
let(:cert_file) { Tempfile.new("hutch-test-cert.pem") }
|
|
87
|
+
let(:file) { cert_file.to_path }
|
|
72
88
|
|
|
73
89
|
it "sets mq_tls_cert to the file" do
|
|
74
90
|
expect(Hutch::Config).to receive(:mq_tls_cert=)
|
data/spec/hutch/config_spec.rb
CHANGED
|
@@ -31,12 +31,10 @@ describe Hutch::Config do
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
context 'for invalid attributes' do
|
|
34
|
-
let(:invalid_get)
|
|
35
|
-
-> { Hutch::Config.get(:invalid_attr) }
|
|
36
|
-
end
|
|
34
|
+
let(:invalid_get) { Hutch::Config.get(:invalid_attr) }
|
|
37
35
|
|
|
38
36
|
specify do
|
|
39
|
-
expect
|
|
37
|
+
expect { invalid_get }.to raise_error Hutch::UnknownAttributeError
|
|
40
38
|
end
|
|
41
39
|
end
|
|
42
40
|
end
|
|
@@ -49,15 +47,89 @@ describe Hutch::Config do
|
|
|
49
47
|
context 'sets value in user config hash' do
|
|
50
48
|
it { is_expected.to eq(new_value) }
|
|
51
49
|
end
|
|
50
|
+
|
|
51
|
+
context 'type casting' do
|
|
52
|
+
context 'number attributes' do
|
|
53
|
+
before { Hutch::Config.set(:heartbeat, new_value) }
|
|
54
|
+
subject(:value) { Hutch::Config.user_config[:heartbeat] }
|
|
55
|
+
|
|
56
|
+
let(:new_value) { "0" }
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
specify 'casts values to integers' do
|
|
60
|
+
expect(value).to eq 0
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context 'boolean attributes' do
|
|
66
|
+
context 'from non-empty string' do
|
|
67
|
+
before { Hutch::Config.set(:autoload_rails, new_value) }
|
|
68
|
+
subject(:value) { Hutch::Config.user_config[:autoload_rails] }
|
|
69
|
+
|
|
70
|
+
let(:new_value) { "t" }
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
specify 'casts values to booleans' do
|
|
74
|
+
expect(value).to eq true
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context 'from empty string' do
|
|
79
|
+
before { Hutch::Config.set(:autoload_rails, new_value) }
|
|
80
|
+
subject(:value) { Hutch::Config.user_config[:autoload_rails] }
|
|
81
|
+
|
|
82
|
+
let(:new_value) { "" }
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
specify 'casts values to booleans' do
|
|
86
|
+
expect(value).to eq false
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context 'from boolean' do
|
|
91
|
+
before { Hutch::Config.set(:autoload_rails, new_value) }
|
|
92
|
+
subject(:value) { Hutch::Config.user_config[:autoload_rails] }
|
|
93
|
+
|
|
94
|
+
let(:new_value) { true }
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
specify 'casts values to booleans' do
|
|
98
|
+
expect(value).to eq true
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context 'from nil' do
|
|
103
|
+
before { Hutch::Config.set(:autoload_rails, new_value) }
|
|
104
|
+
subject(:value) { Hutch::Config.user_config[:autoload_rails] }
|
|
105
|
+
|
|
106
|
+
let(:new_value) { nil }
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
specify 'casts values to booleans' do
|
|
110
|
+
expect(value).to eq false
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
context 'string attributes' do
|
|
116
|
+
before { Hutch::Config.set(:mq_exchange_type, new_value) }
|
|
117
|
+
subject(:value) { Hutch::Config.user_config[:mq_exchange_type] }
|
|
118
|
+
|
|
119
|
+
let(:new_value) { 1 }
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
specify 'does not perform any typecasting' do
|
|
123
|
+
expect(value).to eq new_value
|
|
124
|
+
end
|
|
125
|
+
end
|
|
52
126
|
end
|
|
53
127
|
|
|
54
128
|
context 'for invalid attributes' do
|
|
55
|
-
let(:invalid_set)
|
|
56
|
-
-> { Hutch::Config.set(:invalid_attr, new_value) }
|
|
57
|
-
end
|
|
129
|
+
let(:invalid_set) { Hutch::Config.set(:invalid_attr, new_value) }
|
|
58
130
|
|
|
59
131
|
specify do
|
|
60
|
-
expect
|
|
132
|
+
expect { invalid_set }.to raise_error Hutch::UnknownAttributeError
|
|
61
133
|
end
|
|
62
134
|
end
|
|
63
135
|
end
|
|
@@ -71,8 +143,8 @@ describe Hutch::Config do
|
|
|
71
143
|
end
|
|
72
144
|
|
|
73
145
|
context 'for an invalid attribute' do
|
|
74
|
-
let(:invalid_getter) {
|
|
75
|
-
specify { expect
|
|
146
|
+
let(:invalid_getter) { Hutch::Config.invalid_attr }
|
|
147
|
+
specify { expect { invalid_getter }.to raise_error NoMethodError }
|
|
76
148
|
end
|
|
77
149
|
|
|
78
150
|
context 'for an ENV-overriden value attribute' do
|
|
@@ -109,8 +181,8 @@ describe Hutch::Config do
|
|
|
109
181
|
end
|
|
110
182
|
|
|
111
183
|
context 'for an invalid attribute' do
|
|
112
|
-
let(:invalid_setter) {
|
|
113
|
-
specify { expect
|
|
184
|
+
let(:invalid_setter) { Hutch::Config.invalid_attr = new_value }
|
|
185
|
+
specify { expect { invalid_setter }.to raise_error NoMethodError }
|
|
114
186
|
end
|
|
115
187
|
end
|
|
116
188
|
|
data/spec/hutch/consumer_spec.rb
CHANGED
|
@@ -28,6 +28,32 @@ describe Hutch::Consumer do
|
|
|
28
28
|
ComplexConsumer
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
let(:consumer_using_quorum_queue) do
|
|
32
|
+
unless defined? ConsumerUsingQuorumQueue
|
|
33
|
+
class ConsumerUsingQuorumQueue
|
|
34
|
+
include Hutch::Consumer
|
|
35
|
+
consume 'hutch.test1'
|
|
36
|
+
arguments foo: :bar
|
|
37
|
+
|
|
38
|
+
quorum_queue
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
ConsumerUsingQuorumQueue
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
let(:consumer_using_classic_queue) do
|
|
45
|
+
unless defined? ConsumerUsingLazyQueue
|
|
46
|
+
class ConsumerUsingLazyQueue
|
|
47
|
+
include Hutch::Consumer
|
|
48
|
+
consume 'hutch.test1'
|
|
49
|
+
arguments foo: :bar
|
|
50
|
+
lazy_queue
|
|
51
|
+
classic_queue
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
ConsumerUsingLazyQueue
|
|
55
|
+
end
|
|
56
|
+
|
|
31
57
|
describe 'module inclusion' do
|
|
32
58
|
it 'registers the class as a consumer' do
|
|
33
59
|
expect(Hutch).to receive(:register_consumer) do |klass|
|
|
@@ -71,6 +97,54 @@ describe Hutch::Consumer do
|
|
|
71
97
|
end
|
|
72
98
|
end
|
|
73
99
|
|
|
100
|
+
describe '.without_namespace' do
|
|
101
|
+
it 'is false by default' do
|
|
102
|
+
expect(simple_consumer.without_namespace?).to eq(false)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'returns true after calling without_namespace' do
|
|
106
|
+
simple_consumer.without_namespace
|
|
107
|
+
expect(simple_consumer.without_namespace?).to eq(true)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
describe 'default queue mode' do
|
|
112
|
+
it 'does not specify any mode by default' do
|
|
113
|
+
expect(simple_consumer.queue_mode).to eq(nil)
|
|
114
|
+
expect(simple_consumer.queue_type).to eq(nil)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe '.lazy_queue' do
|
|
119
|
+
context 'when queue mode has been set explicitly to lazy' do
|
|
120
|
+
it 'sets queue mode to lazy' do
|
|
121
|
+
expect(consumer_using_classic_queue.queue_mode).to eq('lazy')
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
describe '.classic_queue' do
|
|
127
|
+
context 'when queue type has been set explicitly to classic' do
|
|
128
|
+
it 'sets queue type to classic' do
|
|
129
|
+
expect(consumer_using_classic_queue.queue_type).to eq('classic')
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
describe '.quorum_queue' do
|
|
135
|
+
context 'when queue type has been set explicitly to quorum' do
|
|
136
|
+
it 'sets queue type to quorum' do
|
|
137
|
+
expect(consumer_using_quorum_queue.queue_type).to eq('quorum')
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'accepts initial group size as an option' do
|
|
141
|
+
consumer = simple_consumer
|
|
142
|
+
expect { consumer.quorum_queue(initial_group_size: 3) }
|
|
143
|
+
.to change { consumer.initial_group_size }.to(3)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
74
148
|
describe '.arguments' do
|
|
75
149
|
let(:args) { { foo: :bar} }
|
|
76
150
|
|
|
@@ -82,15 +156,30 @@ describe Hutch::Consumer do
|
|
|
82
156
|
end
|
|
83
157
|
|
|
84
158
|
describe '.get_arguments' do
|
|
85
|
-
|
|
86
159
|
context 'when defined' do
|
|
87
|
-
it { expect(complex_consumer.get_arguments).to
|
|
160
|
+
it { expect(complex_consumer.get_arguments).to include(foo: :bar) }
|
|
88
161
|
end
|
|
89
162
|
|
|
90
|
-
context 'when
|
|
91
|
-
it
|
|
163
|
+
context 'when queue is lazy' do
|
|
164
|
+
it 'has the x-queue-mode argument set to lazy' do
|
|
165
|
+
expect(consumer_using_classic_queue.get_arguments['x-queue-mode'])
|
|
166
|
+
.to eq('lazy')
|
|
167
|
+
end
|
|
92
168
|
end
|
|
93
169
|
|
|
170
|
+
context "when queue's type is quorum" do
|
|
171
|
+
let(:arguments) { consumer_using_quorum_queue.get_arguments }
|
|
172
|
+
it 'has the x-queue-type argument set to quorum' do
|
|
173
|
+
expect(arguments['x-queue-type']).to eq('quorum')
|
|
174
|
+
expect(arguments).to_not have_key('x-quorum-initial-group-size')
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it 'has the x-quorum-initial-group-size argument set to quorum' do
|
|
178
|
+
consumer_using_quorum_queue.quorum_queue(initial_group_size: 5)
|
|
179
|
+
expect(arguments['x-queue-type']).to eq('quorum')
|
|
180
|
+
expect(arguments['x-quorum-initial-group-size']).to eq(5)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
94
183
|
end
|
|
95
184
|
|
|
96
185
|
describe '.get_queue_name' do
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
+
# The airbrake gem is MRI-only, see the Gemfile
|
|
4
|
+
return if defined?(JRUBY_VERSION)
|
|
5
|
+
|
|
3
6
|
describe Hutch::ErrorHandlers::Airbrake do
|
|
4
7
|
let(:error_handler) { Hutch::ErrorHandlers::Airbrake.new }
|
|
5
8
|
|
|
@@ -14,7 +17,7 @@ describe Hutch::ErrorHandlers::Airbrake do
|
|
|
14
17
|
|
|
15
18
|
it "logs the error to Airbrake" do
|
|
16
19
|
message_id = "1"
|
|
17
|
-
properties =
|
|
20
|
+
properties = Struct.new(:message_id).new(message_id)
|
|
18
21
|
payload = "{}"
|
|
19
22
|
consumer = double
|
|
20
23
|
ex = error
|
|
@@ -27,4 +30,23 @@ describe Hutch::ErrorHandlers::Airbrake do
|
|
|
27
30
|
error_handler.handle(properties, payload, consumer, ex)
|
|
28
31
|
end
|
|
29
32
|
end
|
|
33
|
+
|
|
34
|
+
describe '#handle_setup_exception' do
|
|
35
|
+
let(:error) do
|
|
36
|
+
begin
|
|
37
|
+
raise "Stuff went wrong"
|
|
38
|
+
rescue RuntimeError => err
|
|
39
|
+
err
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "logs the error to Airbrake" do
|
|
44
|
+
ex = error
|
|
45
|
+
message = {
|
|
46
|
+
cgi_data: ENV.to_hash,
|
|
47
|
+
}
|
|
48
|
+
expect(::Airbrake).to receive(:notify).with(ex, message)
|
|
49
|
+
error_handler.handle_setup_exception(ex)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
30
52
|
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Hutch::ErrorHandlers::Bugsnag do
|
|
6
|
+
let(:error_handler) { described_class.new }
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
Bugsnag.configure do |bugsnag|
|
|
10
|
+
bugsnag.api_key = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
11
|
+
bugsnag.logger = Logger.new(File::NULL) # suppress logging
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "#handle" do
|
|
16
|
+
let(:error) do
|
|
17
|
+
begin
|
|
18
|
+
raise "Stuff went wrong"
|
|
19
|
+
rescue RuntimeError => err
|
|
20
|
+
err
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "logs the error to Bugsnag" do
|
|
25
|
+
message_id = "1"
|
|
26
|
+
properties = Struct.new(:message_id).new(message_id)
|
|
27
|
+
payload = "{}"
|
|
28
|
+
consumer = double
|
|
29
|
+
ex = error
|
|
30
|
+
message = {
|
|
31
|
+
payload: payload,
|
|
32
|
+
consumer: consumer
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
expect(::Bugsnag).to receive(:notify).with(ex).and_call_original
|
|
36
|
+
expect_any_instance_of(::Bugsnag::Report).to receive(:add_tab).with(:hutch, message)
|
|
37
|
+
error_handler.handle(properties, payload, consumer, ex)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "#handle_setup_exception" do
|
|
42
|
+
let(:error) do
|
|
43
|
+
begin
|
|
44
|
+
raise "Stuff went wrong"
|
|
45
|
+
rescue RuntimeError => err
|
|
46
|
+
err
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "logs the error to Bugsnag" do
|
|
51
|
+
ex = error
|
|
52
|
+
expect(::Bugsnag).to receive(:notify).with(ex)
|
|
53
|
+
error_handler.handle_setup_exception(ex)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -14,7 +14,7 @@ describe Hutch::ErrorHandlers::Honeybadger do
|
|
|
14
14
|
|
|
15
15
|
it "logs the error to Honeybadger" do
|
|
16
16
|
message_id = "1"
|
|
17
|
-
properties =
|
|
17
|
+
properties = Struct.new(:message_id).new(message_id)
|
|
18
18
|
payload = "{}"
|
|
19
19
|
consumer = double
|
|
20
20
|
ex = error
|
|
@@ -34,4 +34,25 @@ describe Hutch::ErrorHandlers::Honeybadger do
|
|
|
34
34
|
error_handler.handle(properties, payload, consumer, ex)
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
|
+
|
|
38
|
+
describe '#handle_setup_exception' do
|
|
39
|
+
let(:error) do
|
|
40
|
+
begin
|
|
41
|
+
raise "Stuff went wrong during setup"
|
|
42
|
+
rescue RuntimeError => err
|
|
43
|
+
err
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "logs the error to Honeybadger" do
|
|
48
|
+
ex = error
|
|
49
|
+
message = {
|
|
50
|
+
:error_class => ex.class.name,
|
|
51
|
+
:error_message => "#{ ex.class.name }: #{ ex.message }",
|
|
52
|
+
:backtrace => ex.backtrace,
|
|
53
|
+
}
|
|
54
|
+
expect(error_handler).to receive(:notify_honeybadger).with(message)
|
|
55
|
+
error_handler.handle_setup_exception(ex)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
37
58
|
end
|
|
@@ -4,7 +4,7 @@ describe Hutch::ErrorHandlers::Logger do
|
|
|
4
4
|
let(:error_handler) { Hutch::ErrorHandlers::Logger.new }
|
|
5
5
|
|
|
6
6
|
describe '#handle' do
|
|
7
|
-
let(:properties) {
|
|
7
|
+
let(:properties) { Struct.new(:message_id).new("1") }
|
|
8
8
|
let(:payload) { "{}" }
|
|
9
9
|
let(:error) { double(message: "Stuff went wrong", class: "RuntimeError",
|
|
10
10
|
backtrace: ["line 1", "line 2"]) }
|
|
@@ -14,4 +14,15 @@ describe Hutch::ErrorHandlers::Logger do
|
|
|
14
14
|
error_handler.handle(properties, payload, double, error)
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
|
+
|
|
18
|
+
describe '#handle_setup_exception' do
|
|
19
|
+
let(:error) { double(message: "Stuff went wrong during setup",
|
|
20
|
+
class: "RuntimeError",
|
|
21
|
+
backtrace: ["line 1", "line 2"]) }
|
|
22
|
+
|
|
23
|
+
it "logs two separate lines" do
|
|
24
|
+
expect(Hutch::Logging.logger).to receive(:error).exactly(2).times
|
|
25
|
+
error_handler.handle_setup_exception(error)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
17
28
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Hutch::ErrorHandlers::Rollbar do
|
|
4
|
+
let(:error_handler) { Hutch::ErrorHandlers::Rollbar.new }
|
|
5
|
+
|
|
6
|
+
describe '#handle' do
|
|
7
|
+
let(:error) do
|
|
8
|
+
begin
|
|
9
|
+
raise "Stuff went wrong"
|
|
10
|
+
rescue RuntimeError => err
|
|
11
|
+
err
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "logs the error to Rollbar" do
|
|
16
|
+
message_id = "1"
|
|
17
|
+
properties = Struct.new(:message_id).new(message_id)
|
|
18
|
+
payload = "{}"
|
|
19
|
+
consumer = double
|
|
20
|
+
ex = error
|
|
21
|
+
message = {
|
|
22
|
+
payload: payload,
|
|
23
|
+
consumer: consumer
|
|
24
|
+
}
|
|
25
|
+
expect(::Rollbar).to receive(:error).with(ex, message)
|
|
26
|
+
error_handler.handle(properties, payload, consumer, ex)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '#handle_setup_exception' do
|
|
31
|
+
let(:error) do
|
|
32
|
+
begin
|
|
33
|
+
raise "Stuff went wrong"
|
|
34
|
+
rescue RuntimeError => err
|
|
35
|
+
err
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "logs the error to Rollbar" do
|
|
40
|
+
ex = error
|
|
41
|
+
expect(::Rollbar).to receive(:error).with(ex)
|
|
42
|
+
error_handler.handle_setup_exception(ex)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -3,8 +3,16 @@ require 'spec_helper'
|
|
|
3
3
|
describe Hutch::ErrorHandlers::Sentry do
|
|
4
4
|
let(:error_handler) { Hutch::ErrorHandlers::Sentry.new }
|
|
5
5
|
|
|
6
|
+
before do
|
|
7
|
+
Sentry.init do
|
|
8
|
+
# initialize Sentry so that the integration acutally works
|
|
9
|
+
# otherwise, all its methods are going to return early
|
|
10
|
+
# so it will be impossible to check if it actually works
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
6
14
|
describe '#handle' do
|
|
7
|
-
let(:properties) {
|
|
15
|
+
let(:properties) { Struct.new(:message_id).new("1") }
|
|
8
16
|
let(:payload) { "{}" }
|
|
9
17
|
let(:error) do
|
|
10
18
|
begin
|
|
@@ -15,8 +23,25 @@ describe Hutch::ErrorHandlers::Sentry do
|
|
|
15
23
|
end
|
|
16
24
|
|
|
17
25
|
it "logs the error to Sentry" do
|
|
18
|
-
expect(
|
|
26
|
+
expect(::Sentry).to receive(:capture_exception).with(error).and_call_original
|
|
27
|
+
|
|
19
28
|
error_handler.handle(properties, payload, double, error)
|
|
20
29
|
end
|
|
21
30
|
end
|
|
31
|
+
|
|
32
|
+
describe '#handle_setup_exception' do
|
|
33
|
+
let(:error) do
|
|
34
|
+
begin
|
|
35
|
+
raise "Stuff went wrong during setup"
|
|
36
|
+
rescue RuntimeError => err
|
|
37
|
+
err
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "logs the error to Sentry" do
|
|
42
|
+
expect(::Sentry).to receive(:capture_exception).with(error).and_call_original
|
|
43
|
+
|
|
44
|
+
error_handler.handle_setup_exception(error)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
22
47
|
end
|
data/spec/hutch/message_spec.rb
CHANGED
|
@@ -4,7 +4,7 @@ describe Hutch::Message do
|
|
|
4
4
|
let(:delivery_info) { double('Delivery Info') }
|
|
5
5
|
let(:props) { double('Properties', content_type: "application/json") }
|
|
6
6
|
let(:body) {{ foo: 'bar' }.with_indifferent_access}
|
|
7
|
-
let(:json_body) {
|
|
7
|
+
let(:json_body) { JSON.generate(body) }
|
|
8
8
|
subject(:message) { Hutch::Message.new(delivery_info, props, json_body, Hutch::Config[:serializer]) }
|
|
9
9
|
|
|
10
10
|
describe '#body' do
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Hutch::Tracers::Datadog do
|
|
4
|
+
::Datadog.logger.level = Logger::FATAL # suppress logging
|
|
5
|
+
|
|
6
|
+
describe "#handle" do
|
|
7
|
+
subject(:handle) { tracer.handle(message) }
|
|
8
|
+
|
|
9
|
+
let(:tracer) { described_class.new(klass) }
|
|
10
|
+
let(:klass) do
|
|
11
|
+
Class.new do
|
|
12
|
+
attr_reader :message
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@message = nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def class
|
|
19
|
+
Struct.new(:name).new('ClassName')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def process(message)
|
|
23
|
+
@message = message
|
|
24
|
+
end
|
|
25
|
+
end.new
|
|
26
|
+
end
|
|
27
|
+
let(:message) { double(:message) }
|
|
28
|
+
|
|
29
|
+
before do
|
|
30
|
+
allow(::Datadog::Tracing).to receive(:trace).and_call_original
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'uses Datadog tracer' do
|
|
34
|
+
handle
|
|
35
|
+
|
|
36
|
+
expect(::Datadog::Tracing).to have_received(:trace).with('ClassName',
|
|
37
|
+
hash_including(service: 'hutch', type: 'rabbitmq'))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'processes the message' do
|
|
41
|
+
expect {
|
|
42
|
+
handle
|
|
43
|
+
}.to change { klass.message }.from(nil).to(message)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/spec/hutch/waiter_spec.rb
CHANGED
|
@@ -22,7 +22,7 @@ RSpec.describe Hutch::Waiter do
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
context 'a TERM signal is received' do
|
|
25
|
+
context 'a TERM signal is received', if: !defined?(JRUBY_VERSION) do
|
|
26
26
|
it 'logs that hutch is stopping' do
|
|
27
27
|
expect(Hutch::Logging.logger).to receive(:info)
|
|
28
28
|
.with('caught SIGTERM, stopping hutch...')
|
|
@@ -32,7 +32,7 @@ RSpec.describe Hutch::Waiter do
|
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
context 'a INT signal is received' do
|
|
35
|
+
context 'a INT signal is received', if: !defined?(JRUBY_VERSION) do
|
|
36
36
|
it 'logs that hutch is stopping' do
|
|
37
37
|
expect(Hutch::Logging.logger).to receive(:info)
|
|
38
38
|
.with('caught SIGINT, stopping hutch...')
|