fastly_nsq 1.16.0 → 1.18.0
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 +4 -4
- data/.env +2 -2
- data/.git-blame-ignore-revs +6 -0
- data/.ruby-version +1 -1
- data/.travis.yml +4 -3
- data/ChangeLog.md +31 -1
- data/Gemfile +8 -8
- data/README.md +84 -6
- data/Rakefile +10 -11
- data/fastly_nsq.gemspec +26 -26
- data/lib/fastly_nsq/cli.rb +43 -50
- data/lib/fastly_nsq/consumer.rb +27 -14
- data/lib/fastly_nsq/feeder.rb +5 -7
- data/lib/fastly_nsq/http/nsqd.rb +28 -28
- data/lib/fastly_nsq/http/nsqlookupd.rb +11 -11
- data/lib/fastly_nsq/http.rb +4 -4
- data/lib/fastly_nsq/launcher.rb +16 -16
- data/lib/fastly_nsq/listener.rb +16 -16
- data/lib/fastly_nsq/manager.rb +13 -12
- data/lib/fastly_nsq/message.rb +4 -4
- data/lib/fastly_nsq/messenger.rb +25 -15
- data/lib/fastly_nsq/new_relic.rb +8 -8
- data/lib/fastly_nsq/priority_queue.rb +2 -2
- data/lib/fastly_nsq/priority_thread_pool.rb +3 -3
- data/lib/fastly_nsq/producer.rb +23 -14
- data/lib/fastly_nsq/safe_thread.rb +1 -1
- data/lib/fastly_nsq/testing.rb +4 -3
- data/lib/fastly_nsq/tls_options.rb +6 -6
- data/lib/fastly_nsq/version.rb +1 -1
- data/lib/fastly_nsq.rb +64 -29
- data/spec/cli_spec.rb +2 -2
- data/spec/consumer_spec.rb +53 -12
- data/spec/fastly_nsq_spec.rb +108 -32
- data/spec/feeder_spec.rb +4 -4
- data/spec/http/nsqd_spec.rb +23 -23
- data/spec/http/nsqlookupd_spec.rb +19 -19
- data/spec/http_spec.rb +22 -22
- data/spec/integration_spec.rb +10 -10
- data/spec/launcher_spec.rb +21 -21
- data/spec/listener_spec.rb +50 -50
- data/spec/manager_spec.rb +27 -27
- data/spec/matchers/delegate.rb +4 -4
- data/spec/message_spec.rb +19 -19
- data/spec/messenger_spec.rb +71 -59
- data/spec/new_relic.rb +27 -27
- data/spec/priority_thread_pool_spec.rb +2 -2
- data/spec/producer_spec.rb +70 -31
- data/spec/spec_helper.rb +12 -12
- data/spec/support/http.rb +2 -2
- data/spec/support/webmock.rb +1 -1
- data/spec/testing_spec.rb +12 -12
- data/spec/tls_options_spec.rb +47 -47
- metadata +10 -11
- data/.rubocop.yml +0 -68
data/spec/manager_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq::Manager do
|
6
|
-
let!(:topic) {
|
7
|
-
let!(:channel) {
|
6
|
+
let!(:topic) { "fnsq" }
|
7
|
+
let!(:channel) { "fnsq" }
|
8
8
|
|
9
9
|
subject { FastlyNsq.manager }
|
10
10
|
|
@@ -14,33 +14,33 @@ RSpec.describe FastlyNsq::Manager do
|
|
14
14
|
|
15
15
|
it { should_not be_stopped }
|
16
16
|
|
17
|
-
describe
|
18
|
-
it
|
17
|
+
describe "#initialize" do
|
18
|
+
it "allows max_threads to be specified" do
|
19
19
|
max_threads = FastlyNsq.max_processing_pool_threads * 2
|
20
20
|
manager = described_class.new(max_threads: max_threads)
|
21
21
|
|
22
22
|
expect(manager.pool.max_threads).to eq(max_threads)
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it "defaults max_threads to FastlyNsq.max_processing_pool_threads" do
|
26
26
|
expect(subject.pool.max_threads).to eq(FastlyNsq.max_processing_pool_threads)
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it "allows fallback_policy to be specified" do
|
30
30
|
manager = described_class.new(fallback_policy: :abort)
|
31
31
|
|
32
32
|
expect(manager.pool.fallback_policy).to eq(:abort)
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it "defaults fallback_policy to caller_runs" do
|
36
36
|
expect(subject.pool.fallback_policy).to eq(:caller_runs)
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it "defaults logger to FastlyNsq.logger" do
|
40
40
|
expect(subject.logger).to eq(FastlyNsq.logger)
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it "allows logger to be specified" do
|
44
44
|
logger = Logger.new(nil)
|
45
45
|
manager = described_class.new(logger: logger)
|
46
46
|
|
@@ -48,39 +48,39 @@ RSpec.describe FastlyNsq::Manager do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
context
|
51
|
+
context "with a listener" do
|
52
52
|
let!(:listener) { FastlyNsq::Listener.new(topic: topic, channel: channel, processor: ->(*) {}) }
|
53
53
|
before { expect { listener }.to eventually(be_connected).within(5) }
|
54
54
|
|
55
|
-
it
|
55
|
+
it "tracks listener" do
|
56
56
|
expect(subject.listeners).to contain_exactly(listener)
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it "tracks topic listeners" do
|
60
60
|
expect(subject.topic_listeners).to eq(topic => listener)
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
63
|
+
it "tracks topics" do
|
64
64
|
expect(subject.topics).to contain_exactly(topic)
|
65
65
|
end
|
66
66
|
|
67
|
-
describe
|
68
|
-
it
|
67
|
+
describe "#terminate" do
|
68
|
+
it "terminates listeners" do
|
69
69
|
expect { subject.terminate(2) }.to change(listener, :connected?).to(false)
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
72
|
+
it "terminates the processing pool" do
|
73
73
|
expect { subject.terminate(2) }.to change(subject.pool, :shutdown?).to(true)
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
77
|
-
expect { subject.terminate(2) }
|
76
|
+
it "stops" do
|
77
|
+
expect { subject.terminate(2) }.to change(subject, :stopped?).from(false).to(true)
|
78
78
|
end
|
79
79
|
|
80
|
-
context
|
80
|
+
context "when the pool does not terminate within a the specified timeframe" do
|
81
81
|
before { expect(subject.pool).to receive(:shutdown).and_return(false) }
|
82
82
|
|
83
|
-
it
|
83
|
+
it "kills the pool" do
|
84
84
|
expect(subject.pool).to receive(:kill).once.and_call_original
|
85
85
|
|
86
86
|
expect { subject.terminate(0.1) }.to change(subject.pool, :shutdown?).to(true)
|
@@ -89,19 +89,19 @@ RSpec.describe FastlyNsq::Manager do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
it
|
92
|
+
it "transfers" do
|
93
93
|
manager = described_class.new
|
94
94
|
|
95
95
|
listener = nil
|
96
96
|
# register listener with default manager
|
97
|
-
expect { listener = FastlyNsq::Listener.new(topic: topic, channel: channel, processor: ->(*) {}) }
|
98
|
-
to change { FastlyNsq.manager.listeners.size }.by(1)
|
97
|
+
expect { listener = FastlyNsq::Listener.new(topic: topic, channel: channel, processor: ->(*) {}) }
|
98
|
+
.to change { FastlyNsq.manager.listeners.size }.by(1)
|
99
99
|
expect { listener }.to eventually(be_connected).within(5)
|
100
100
|
|
101
101
|
# transfer listener to new manager
|
102
|
-
expect { FastlyNsq.manager.transfer(manager) }
|
103
|
-
to change { manager.listeners.size }.by(1)
|
104
|
-
and change { FastlyNsq.manager.listeners.size }.by(-1)
|
102
|
+
expect { FastlyNsq.manager.transfer(manager) }
|
103
|
+
.to change { manager.listeners.size }.by(1)
|
104
|
+
.and change { FastlyNsq.manager.listeners.size }.by(-1)
|
105
105
|
|
106
106
|
# old manager processing is disabled
|
107
107
|
expect(FastlyNsq.manager.pool).to be_shutdown
|
data/spec/matchers/delegate.rb
CHANGED
@@ -9,22 +9,22 @@ RSpec::Matchers.define :delegate do |method|
|
|
9
9
|
rescue NoMethodError
|
10
10
|
raise "#{@delegator} does not respond to #{@to}!"
|
11
11
|
end
|
12
|
-
allow(@delegator).to receive(@to).and_return(double(
|
12
|
+
allow(@delegator).to receive(@to).and_return(double("receiver", method => :called))
|
13
13
|
actual = (@delegator.send(@method) == :called)
|
14
14
|
allow(@delegator).to receive(@to).and_call_original # unstub
|
15
15
|
actual
|
16
16
|
end
|
17
17
|
|
18
18
|
description do
|
19
|
-
"delegate :#{@method} to its #{@to}#{@prefix ?
|
19
|
+
"delegate :#{@method} to its #{@to}#{@prefix ? " with prefix" : ""}"
|
20
20
|
end
|
21
21
|
|
22
22
|
failure_message do |_text|
|
23
|
-
"expected #{@delegator} to delegate :#{@method} to its #{@to}#{@prefix ?
|
23
|
+
"expected #{@delegator} to delegate :#{@method} to its #{@to}#{@prefix ? " with prefix" : ""}"
|
24
24
|
end
|
25
25
|
|
26
26
|
failure_message_when_negated do |_text|
|
27
|
-
"expected #{@delegator} not to delegate :#{@method} to its #{@to}#{@prefix ?
|
27
|
+
"expected #{@delegator} not to delegate :#{@method} to its #{@to}#{@prefix ? " with prefix" : ""}"
|
28
28
|
end
|
29
29
|
|
30
30
|
chain(:to) { |receiver| @to = receiver }
|
data/spec/message_spec.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "json"
|
5
5
|
|
6
6
|
RSpec.describe FastlyNsq::Message do
|
7
|
-
let(:nsq_message) { double
|
8
|
-
let(:body)
|
9
|
-
let(:json_body)
|
10
|
-
subject
|
7
|
+
let(:nsq_message) { double "Nsq::Message", body: json_body, attempts: 1, finish: nil, requeue: nil, touch: nil, timestamp: nil, id: nil }
|
8
|
+
let(:body) { {"data" => "goes here", "other_field" => "is over here", "meta" => "meta stuff"} }
|
9
|
+
let(:json_body) { body.to_json }
|
10
|
+
subject { FastlyNsq::Message.new nsq_message }
|
11
11
|
|
12
|
-
it
|
12
|
+
it "preserves original message body as raw_body" do
|
13
13
|
expect(subject.raw_body).to eq(json_body)
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it "presents parsed message body as body" do
|
17
17
|
expect(subject.body).to eq(body)
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
expect(subject.data).to eq(
|
20
|
+
it "plucks data as data" do
|
21
|
+
expect(subject.data).to eq("goes here")
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
expect(subject.meta).to eq(body[
|
24
|
+
it "plucks meta as meta" do
|
25
|
+
expect(subject.meta).to eq(body["meta"])
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it "aliases raw_body to to_s" do
|
29
29
|
expect(subject.to_s).to eq(json_body)
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it "delegates methods to the nsq_message object" do
|
33
33
|
%w[attempts finish requeue touch timestamp id].each do |method|
|
34
34
|
subject = FastlyNsq::Message.new nsq_message
|
35
35
|
expect(nsq_message).to receive(method)
|
@@ -38,7 +38,7 @@ RSpec.describe FastlyNsq::Message do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it "does not finish if the message was requeued" do
|
42
42
|
expect(nsq_message).to receive(:requeue).with(1000)
|
43
43
|
expect(nsq_message).not_to receive(:finish)
|
44
44
|
|
@@ -48,7 +48,7 @@ RSpec.describe FastlyNsq::Message do
|
|
48
48
|
expect(subject.managed).to eq(:requeued)
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it "does not requeue if the message was finished" do
|
52
52
|
expect(nsq_message).to receive(:finish)
|
53
53
|
expect(nsq_message).not_to receive(:requeue)
|
54
54
|
|
@@ -58,19 +58,19 @@ RSpec.describe FastlyNsq::Message do
|
|
58
58
|
expect(subject.managed).to eq(:finished)
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it "uses the passed timeout for the requeue timeout" do
|
62
62
|
expect(nsq_message).to receive(:requeue).with(1000)
|
63
63
|
|
64
64
|
subject.requeue(1000)
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it "uses exponential backoff for timeout if none is given" do
|
68
68
|
expect(nsq_message).to receive(:requeue).with(46_000..166_000)
|
69
69
|
|
70
70
|
subject.requeue
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
73
|
+
it "uses the FastlyNsq.max_req_timeout it timeout is larger than FastlyNsq.max_req_timeout" do
|
74
74
|
expect(nsq_message).to receive(:requeue).with(60 * 60 * 1_000)
|
75
75
|
|
76
76
|
subject.requeue(60 * 60 * 4 * 1_000)
|
data/spec/messenger_spec.rb
CHANGED
@@ -1,23 +1,22 @@
|
|
1
|
-
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "json"
|
6
5
|
|
7
6
|
RSpec.describe FastlyNsq::Messenger do
|
8
|
-
let(:message)
|
9
|
-
let(:message2) { {
|
10
|
-
let(:producer) { double
|
11
|
-
let(:origin)
|
12
|
-
let(:sent_at)
|
7
|
+
let(:message) { {sample: "sample", message: "message"} }
|
8
|
+
let(:message2) { {sample: "elpmas", message: "egassem"} }
|
9
|
+
let(:producer) { double "FastlyNsq::Producer", write: nil, terminate: :terminated }
|
10
|
+
let(:origin) { "originating_service" }
|
11
|
+
let(:sent_at) { Time.now.iso8601(5) }
|
13
12
|
|
14
13
|
let(:expected_attributes) do
|
15
14
|
{
|
16
15
|
data: message,
|
17
16
|
meta: {
|
18
|
-
originating_service:
|
19
|
-
sent_at: sent_at
|
20
|
-
}
|
17
|
+
originating_service: "originating_service",
|
18
|
+
sent_at: sent_at
|
19
|
+
}
|
21
20
|
}
|
22
21
|
end
|
23
22
|
|
@@ -27,87 +26,100 @@ RSpec.describe FastlyNsq::Messenger do
|
|
27
26
|
FastlyNsq::Messenger.instance_variable_set(:@producers, nil)
|
28
27
|
end
|
29
28
|
|
30
|
-
describe
|
29
|
+
describe "#deliver" do
|
31
30
|
before { Timecop.freeze(sent_at) }
|
32
31
|
|
33
|
-
it
|
34
|
-
subject.producers[
|
32
|
+
it "writes a single message on a producer" do
|
33
|
+
subject.producers["topic"] = producer
|
35
34
|
|
36
|
-
subject.deliver message: message, topic:
|
35
|
+
subject.deliver message: message, topic: "topic", originating_service: origin
|
37
36
|
|
38
37
|
expect(producer).to have_received(:write).with(expected_attributes.to_json)
|
39
38
|
end
|
40
39
|
|
41
|
-
it
|
42
|
-
subject.producers[
|
43
|
-
expected_attributes[:meta][:originating_service] =
|
40
|
+
it "uses a Unknown for the default originating_service" do
|
41
|
+
subject.producers["topic"] = producer
|
42
|
+
expected_attributes[:meta][:originating_service] = "Unknown"
|
44
43
|
|
45
|
-
subject.deliver message: message, topic:
|
44
|
+
subject.deliver message: message, topic: "topic"
|
46
45
|
|
47
46
|
expect(producer).to have_received(:write).with(expected_attributes.to_json)
|
48
47
|
end
|
49
48
|
|
50
|
-
it
|
51
|
-
meta = {
|
49
|
+
it "allows setting arbitrary metadata" do
|
50
|
+
meta = {test: "test"}
|
52
51
|
|
53
|
-
expected_attributes = {
|
52
|
+
expected_attributes = {data: message, meta: meta.merge(originating_service: origin, sent_at: sent_at)}
|
54
53
|
|
55
|
-
subject.producers[
|
54
|
+
subject.producers["topic"] = producer
|
56
55
|
|
57
|
-
subject.deliver message: message, topic:
|
56
|
+
subject.deliver message: message, topic: "topic", meta: meta, originating_service: origin
|
58
57
|
|
59
58
|
expect(producer).to have_received(:write).with(expected_attributes.to_json)
|
60
59
|
end
|
61
60
|
|
62
|
-
it
|
63
|
-
meta = {
|
61
|
+
it "prevents originating_service from being overwritten by meta" do
|
62
|
+
meta = {test: "test"}
|
63
|
+
|
64
|
+
expected_attributes = {data: message, meta: meta.merge(originating_service: origin, sent_at: sent_at)}
|
65
|
+
|
66
|
+
meta[:originating_service] = "other_service"
|
67
|
+
|
68
|
+
subject.producers["topic"] = producer
|
69
|
+
|
70
|
+
subject.deliver message: message, topic: "topic", meta: meta, originating_service: origin
|
71
|
+
|
72
|
+
expect(producer).to have_received(:write).with(expected_attributes.to_json)
|
73
|
+
end
|
64
74
|
|
65
|
-
|
75
|
+
it "can set the sent_at in the metadata" do
|
76
|
+
sent_at = Time.parse("2020-06-08 23:42:42")
|
77
|
+
meta = {}
|
66
78
|
|
67
|
-
meta
|
79
|
+
expected_attributes = {data: message, meta: meta.merge(originating_service: origin, sent_at: sent_at.iso8601(5))}
|
68
80
|
|
69
|
-
subject.producers[
|
81
|
+
subject.producers["topic"] = producer
|
70
82
|
|
71
|
-
subject.deliver message: message, topic:
|
83
|
+
subject.deliver message: message, topic: "topic", sent_at: sent_at, meta: meta, originating_service: origin
|
72
84
|
|
73
85
|
expect(producer).to have_received(:write).with(expected_attributes.to_json)
|
74
86
|
end
|
75
87
|
end
|
76
88
|
|
77
|
-
describe
|
89
|
+
describe "#deliver_multi" do
|
78
90
|
let(:expected_attributes_multi) do
|
79
91
|
[
|
80
92
|
expected_attributes.to_json,
|
81
93
|
{
|
82
94
|
data: message2,
|
83
95
|
meta: {
|
84
|
-
originating_service:
|
85
|
-
sent_at: sent_at
|
86
|
-
}
|
87
|
-
}.to_json
|
96
|
+
originating_service: "originating_service",
|
97
|
+
sent_at: sent_at
|
98
|
+
}
|
99
|
+
}.to_json
|
88
100
|
]
|
89
101
|
end
|
90
102
|
before { Timecop.freeze(sent_at) }
|
91
103
|
|
92
|
-
it
|
93
|
-
subject.producers[
|
104
|
+
it "writes an array of messages on a producer" do
|
105
|
+
subject.producers["topic"] = producer
|
94
106
|
|
95
|
-
subject.deliver_multi messages: [message, message2], topic:
|
107
|
+
subject.deliver_multi messages: [message, message2], topic: "topic", originating_service: origin
|
96
108
|
|
97
109
|
expect(producer).to have_received(:write).with(expected_attributes_multi)
|
98
110
|
end
|
99
111
|
end
|
100
112
|
|
101
|
-
describe
|
113
|
+
describe "#originating_service=" do
|
102
114
|
before { Timecop.freeze(sent_at) }
|
103
115
|
|
104
116
|
it "set's the default originating service" do
|
105
|
-
subject.producers[
|
106
|
-
service =
|
117
|
+
subject.producers["nanotopic"] = producer
|
118
|
+
service = "nano service"
|
107
119
|
subject.originating_service = service
|
108
120
|
expected_attributes[:meta][:originating_service] = service
|
109
121
|
|
110
|
-
subject.deliver message: message, topic:
|
122
|
+
subject.deliver message: message, topic: "nanotopic"
|
111
123
|
|
112
124
|
expect(producer).to have_received(:write).with(expected_attributes.to_json)
|
113
125
|
|
@@ -116,42 +128,42 @@ RSpec.describe FastlyNsq::Messenger do
|
|
116
128
|
end
|
117
129
|
end
|
118
130
|
|
119
|
-
describe
|
120
|
-
it
|
121
|
-
my_producer = subject.producer_for(topic:
|
131
|
+
describe "#producer_for" do
|
132
|
+
it "returns an FastlyNsq::Producer for the given topic" do
|
133
|
+
my_producer = subject.producer_for(topic: "my_topic")
|
122
134
|
expect(my_producer).to be_a(FastlyNsq::Producer)
|
123
135
|
end
|
124
136
|
|
125
|
-
it
|
126
|
-
subject.producers[
|
137
|
+
it "persists producers" do
|
138
|
+
subject.producers["topic"] = producer
|
127
139
|
|
128
|
-
my_producer = subject.producer_for(topic:
|
140
|
+
my_producer = subject.producer_for(topic: "topic")
|
129
141
|
|
130
142
|
expect(my_producer).to eq(producer)
|
131
143
|
end
|
132
144
|
end
|
133
145
|
|
134
|
-
describe
|
146
|
+
describe "#terminate_producer" do
|
135
147
|
before do
|
136
|
-
subject.producers[
|
137
|
-
subject.terminate_producer(topic:
|
148
|
+
subject.producers["topic"] = producer
|
149
|
+
subject.terminate_producer(topic: "topic")
|
138
150
|
end
|
139
151
|
|
140
|
-
it
|
152
|
+
it "terminates a producer" do
|
141
153
|
expect(producer).to have_received(:terminate)
|
142
154
|
end
|
143
155
|
|
144
|
-
it
|
145
|
-
expect(subject.producers.key?(
|
156
|
+
it "removes the producer from the persisted producers" do
|
157
|
+
expect(subject.producers.key?("topic")).to be(false)
|
146
158
|
end
|
147
159
|
end
|
148
160
|
|
149
|
-
describe
|
150
|
-
let(:producer_2) { double
|
161
|
+
describe "#terminate_all_producers" do
|
162
|
+
let(:producer_2) { double "FastlyNsq::Producer", write: nil, terminate: :terminated }
|
151
163
|
|
152
|
-
it
|
153
|
-
subject.producers[
|
154
|
-
subject.producers[
|
164
|
+
it "terminates all the producers and resets the hash or producers" do
|
165
|
+
subject.producers["topic"] = producer
|
166
|
+
subject.producers["topic_2"] = producer_2
|
155
167
|
|
156
168
|
subject.terminate_all_producers
|
157
169
|
|
data/spec/new_relic.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq::NewRelic do
|
6
|
-
let(:agent) { double
|
6
|
+
let(:agent) { double "NewRelic::Agent", notice_error: true }
|
7
7
|
let(:tracer) { FastlyNsq::NewRelic.new(agent) }
|
8
8
|
|
9
|
-
describe
|
10
|
-
it
|
11
|
-
allow(Object).to receive(:const_defined?).with(
|
9
|
+
describe "#enabled?" do
|
10
|
+
it "returns false unless NewRelic is loaded" do
|
11
|
+
allow(Object).to receive(:const_defined?).with("NewRelic").and_return(false)
|
12
12
|
expect(tracer.enabled?).to be false
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it "returns true id NewRelic is loaded" do
|
16
16
|
expect(tracer.enabled?).to be true
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
context
|
20
|
+
context "enabled" do
|
21
21
|
before do
|
22
|
-
allow(Object).to receive(:const_defined?).with(
|
22
|
+
allow(Object).to receive(:const_defined?).with("NewRelic").and_return(true)
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
26
|
-
it
|
25
|
+
describe "#notice_error" do
|
26
|
+
it "call agent.notice_error" do
|
27
27
|
ex = Exception.new
|
28
28
|
|
29
29
|
tracer.notice_error(ex)
|
@@ -31,34 +31,34 @@ RSpec.describe FastlyNsq::NewRelic do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
35
|
-
it
|
34
|
+
describe "#trace_with_newrelic" do
|
35
|
+
it "calls perform_action_with_newrelic_trace and yields" do
|
36
36
|
allow(tracer).to receive(:perform_action_with_newrelic_trace).and_yield
|
37
37
|
|
38
38
|
expect { |b| tracer.trace_with_newrelic({}, &b) }.to yield_control
|
39
39
|
expect(tracer).to have_received(:perform_action_with_newrelic_trace)
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
43
|
-
params = {
|
42
|
+
it "calls perform_action_with_newrelic_trace with trace_args" do
|
43
|
+
params = {id: 1, vp: "joe biden"}
|
44
44
|
|
45
45
|
expected = {
|
46
|
-
name:
|
46
|
+
name: "call",
|
47
47
|
category: FastlyNsq::NewRelic::CATEGORY,
|
48
48
|
params: params,
|
49
|
-
class_name:
|
49
|
+
class_name: "SomeClass"
|
50
50
|
}
|
51
51
|
|
52
52
|
allow(tracer).to receive(:perform_action_with_newrelic_trace).and_yield
|
53
|
-
expect { |b| tracer.trace_with_newrelic(params: params, class_name:
|
53
|
+
expect { |b| tracer.trace_with_newrelic(params: params, class_name: "SomeClass", &b) }.to yield_control
|
54
54
|
|
55
55
|
expect(tracer).to have_received(:perform_action_with_newrelic_trace).with(expected)
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
58
|
+
it "always sends the default trace args" do
|
59
59
|
expected = {
|
60
|
-
name:
|
61
|
-
category: FastlyNsq::NewRelic::CATEGORY
|
60
|
+
name: "call",
|
61
|
+
category: FastlyNsq::NewRelic::CATEGORY
|
62
62
|
}
|
63
63
|
allow(tracer).to receive(:perform_action_with_newrelic_trace).and_yield
|
64
64
|
|
@@ -69,19 +69,19 @@ RSpec.describe FastlyNsq::NewRelic do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
context
|
72
|
+
context "disabled" do
|
73
73
|
before do
|
74
|
-
allow(Object).to receive(:const_defined?).with(
|
74
|
+
allow(Object).to receive(:const_defined?).with("NewRelic").and_return(false)
|
75
75
|
end
|
76
76
|
|
77
|
-
describe
|
78
|
-
it
|
79
|
-
expect(tracer.notice_error(
|
77
|
+
describe "#notice_error" do
|
78
|
+
it "returns nil" do
|
79
|
+
expect(tracer.notice_error("ex")).to be nil
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
describe
|
84
|
-
it
|
83
|
+
describe "#trace_with_newrelic" do
|
84
|
+
it "yields" do
|
85
85
|
allow(tracer).to receive(:perform_action_with_newrelic_trace)
|
86
86
|
|
87
87
|
expect { |b| tracer.trace_with_newrelic({}, &b) }.to yield_control
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq::PriorityThreadPool do
|
6
6
|
let!(:pool) { described_class.new(max_threads: 1) }
|
7
7
|
|
8
8
|
after { pool.shutdown || pool.wait_for_termination }
|
9
9
|
|
10
|
-
it
|
10
|
+
it "executes work based on supplied priority" do
|
11
11
|
actual = []
|
12
12
|
count = 10
|
13
13
|
count.times { |i| pool.post(i) { actual << i } }
|