fastly_nsq 1.17.0 → 1.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.git-blame-ignore-revs +6 -0
- data/.ruby-version +1 -1
- data/.travis.yml +4 -2
- data/ChangeLog.md +8 -1
- data/Gemfile +8 -8
- data/README.md +1 -1
- data/Rakefile +10 -11
- data/fastly_nsq.gemspec +26 -26
- data/lib/fastly_nsq/cli.rb +43 -50
- data/lib/fastly_nsq/consumer.rb +6 -6
- 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 +7 -7
- 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 +7 -7
- 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 +27 -29
- data/spec/cli_spec.rb +2 -2
- data/spec/consumer_spec.rb +12 -12
- data/spec/fastly_nsq_spec.rb +31 -31
- 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 +63 -64
- data/spec/new_relic.rb +27 -27
- data/spec/priority_thread_pool_spec.rb +2 -2
- data/spec/producer_spec.rb +30 -30
- 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 +7 -8
- data/.rubocop.yml +0 -68
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,100 +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"}
|
64
63
|
|
65
|
-
expected_attributes = {
|
64
|
+
expected_attributes = {data: message, meta: meta.merge(originating_service: origin, sent_at: sent_at)}
|
66
65
|
|
67
|
-
meta[:originating_service] =
|
66
|
+
meta[:originating_service] = "other_service"
|
68
67
|
|
69
|
-
subject.producers[
|
68
|
+
subject.producers["topic"] = producer
|
70
69
|
|
71
|
-
subject.deliver message: message, topic:
|
70
|
+
subject.deliver message: message, topic: "topic", meta: meta, originating_service: origin
|
72
71
|
|
73
72
|
expect(producer).to have_received(:write).with(expected_attributes.to_json)
|
74
73
|
end
|
75
74
|
|
76
|
-
it
|
77
|
-
sent_at = Time.parse(
|
75
|
+
it "can set the sent_at in the metadata" do
|
76
|
+
sent_at = Time.parse("2020-06-08 23:42:42")
|
78
77
|
meta = {}
|
79
78
|
|
80
|
-
expected_attributes = {
|
79
|
+
expected_attributes = {data: message, meta: meta.merge(originating_service: origin, sent_at: sent_at.iso8601(5))}
|
81
80
|
|
82
|
-
subject.producers[
|
81
|
+
subject.producers["topic"] = producer
|
83
82
|
|
84
|
-
subject.deliver message: message, topic:
|
83
|
+
subject.deliver message: message, topic: "topic", sent_at: sent_at, meta: meta, originating_service: origin
|
85
84
|
|
86
85
|
expect(producer).to have_received(:write).with(expected_attributes.to_json)
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
|
-
describe
|
89
|
+
describe "#deliver_multi" do
|
91
90
|
let(:expected_attributes_multi) do
|
92
91
|
[
|
93
92
|
expected_attributes.to_json,
|
94
93
|
{
|
95
94
|
data: message2,
|
96
95
|
meta: {
|
97
|
-
originating_service:
|
98
|
-
sent_at: sent_at
|
99
|
-
}
|
100
|
-
}.to_json
|
96
|
+
originating_service: "originating_service",
|
97
|
+
sent_at: sent_at
|
98
|
+
}
|
99
|
+
}.to_json
|
101
100
|
]
|
102
101
|
end
|
103
102
|
before { Timecop.freeze(sent_at) }
|
104
103
|
|
105
|
-
it
|
106
|
-
subject.producers[
|
104
|
+
it "writes an array of messages on a producer" do
|
105
|
+
subject.producers["topic"] = producer
|
107
106
|
|
108
|
-
subject.deliver_multi messages: [message, message2], topic:
|
107
|
+
subject.deliver_multi messages: [message, message2], topic: "topic", originating_service: origin
|
109
108
|
|
110
109
|
expect(producer).to have_received(:write).with(expected_attributes_multi)
|
111
110
|
end
|
112
111
|
end
|
113
112
|
|
114
|
-
describe
|
113
|
+
describe "#originating_service=" do
|
115
114
|
before { Timecop.freeze(sent_at) }
|
116
115
|
|
117
116
|
it "set's the default originating service" do
|
118
|
-
subject.producers[
|
119
|
-
service =
|
117
|
+
subject.producers["nanotopic"] = producer
|
118
|
+
service = "nano service"
|
120
119
|
subject.originating_service = service
|
121
120
|
expected_attributes[:meta][:originating_service] = service
|
122
121
|
|
123
|
-
subject.deliver message: message, topic:
|
122
|
+
subject.deliver message: message, topic: "nanotopic"
|
124
123
|
|
125
124
|
expect(producer).to have_received(:write).with(expected_attributes.to_json)
|
126
125
|
|
@@ -129,42 +128,42 @@ RSpec.describe FastlyNsq::Messenger do
|
|
129
128
|
end
|
130
129
|
end
|
131
130
|
|
132
|
-
describe
|
133
|
-
it
|
134
|
-
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")
|
135
134
|
expect(my_producer).to be_a(FastlyNsq::Producer)
|
136
135
|
end
|
137
136
|
|
138
|
-
it
|
139
|
-
subject.producers[
|
137
|
+
it "persists producers" do
|
138
|
+
subject.producers["topic"] = producer
|
140
139
|
|
141
|
-
my_producer = subject.producer_for(topic:
|
140
|
+
my_producer = subject.producer_for(topic: "topic")
|
142
141
|
|
143
142
|
expect(my_producer).to eq(producer)
|
144
143
|
end
|
145
144
|
end
|
146
145
|
|
147
|
-
describe
|
146
|
+
describe "#terminate_producer" do
|
148
147
|
before do
|
149
|
-
subject.producers[
|
150
|
-
subject.terminate_producer(topic:
|
148
|
+
subject.producers["topic"] = producer
|
149
|
+
subject.terminate_producer(topic: "topic")
|
151
150
|
end
|
152
151
|
|
153
|
-
it
|
152
|
+
it "terminates a producer" do
|
154
153
|
expect(producer).to have_received(:terminate)
|
155
154
|
end
|
156
155
|
|
157
|
-
it
|
158
|
-
expect(subject.producers.key?(
|
156
|
+
it "removes the producer from the persisted producers" do
|
157
|
+
expect(subject.producers.key?("topic")).to be(false)
|
159
158
|
end
|
160
159
|
end
|
161
160
|
|
162
|
-
describe
|
163
|
-
let(:producer_2) { double
|
161
|
+
describe "#terminate_all_producers" do
|
162
|
+
let(:producer_2) { double "FastlyNsq::Producer", write: nil, terminate: :terminated }
|
164
163
|
|
165
|
-
it
|
166
|
-
subject.producers[
|
167
|
-
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
|
168
167
|
|
169
168
|
subject.terminate_all_producers
|
170
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 } }
|
data/spec/producer_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq::Producer do
|
6
|
-
let!(:topic) {
|
6
|
+
let!(:topic) { "fnsq" }
|
7
7
|
subject { FastlyNsq::Producer.new(topic: topic) }
|
8
8
|
|
9
9
|
before { reset_topic(topic) }
|
@@ -12,86 +12,86 @@ RSpec.describe FastlyNsq::Producer do
|
|
12
12
|
|
13
13
|
it { should be_connected }
|
14
14
|
|
15
|
-
it
|
16
|
-
subject.write
|
15
|
+
it "writes a message" do
|
16
|
+
subject.write "foo"
|
17
17
|
expect { message_count(topic) }.to eventually(eq(1)).within(5)
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it "writes multiple messages" do
|
21
21
|
subject.write %w[foo bar]
|
22
22
|
expect { message_count(topic) }.to eventually(eq(2)).within(5)
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it "should terminate" do
|
26
26
|
expect { subject.terminate }.to change(subject, :connected?).to(false)
|
27
27
|
expect(subject.connection).to eq(nil)
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it "does not write after termination" do
|
31
31
|
subject.terminate
|
32
|
-
expect { subject.write
|
32
|
+
expect { subject.write "foo" }.to raise_error(FastlyNsq::NotConnectedError)
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it "can connect after termination" do
|
36
36
|
subject.terminate
|
37
37
|
expect { subject.connect }.to change(subject, :connected?).to(true)
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it "raises when connection fails within the specified timeframe" do
|
41
41
|
allow_any_instance_of(Nsq::Producer).to receive(:connected?).and_return(false)
|
42
|
-
logger = spy(
|
42
|
+
logger = spy("logger")
|
43
43
|
expect(logger).to receive(:error).and_return("Producer for #{topic} failed to connect!")
|
44
44
|
|
45
|
-
if RUBY_VERSION >
|
46
|
-
expect { FastlyNsq::Producer.new(topic: topic, logger: logger, connect_timeout: 0.2) }
|
47
|
-
to raise_error(FastlyNsq::ConnectionFailed, match(FastlyNsq.lookupd_http_addresses.inspect))
|
45
|
+
if RUBY_VERSION > "2.4.0"
|
46
|
+
expect { FastlyNsq::Producer.new(topic: topic, logger: logger, connect_timeout: 0.2) }
|
47
|
+
.to raise_error(FastlyNsq::ConnectionFailed, match(FastlyNsq.lookupd_http_addresses.inspect))
|
48
48
|
else
|
49
|
-
expect { FastlyNsq::Producer.new(topic: topic, logger: logger, connect_timeout: 0.2) }
|
50
|
-
to raise_error(FastlyNsq::ConnectionFailed)
|
49
|
+
expect { FastlyNsq::Producer.new(topic: topic, logger: logger, connect_timeout: 0.2) }
|
50
|
+
.to raise_error(FastlyNsq::ConnectionFailed)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
54
|
+
describe "faking", :fake do
|
55
55
|
it { should be_connected }
|
56
56
|
|
57
|
-
it
|
57
|
+
it "should terminate" do
|
58
58
|
expect { subject.terminate }.to change(subject, :connected?).to(false)
|
59
59
|
expect(subject.connection).to eq(nil)
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
63
|
-
expect { subject.write
|
62
|
+
it "writes a message" do
|
63
|
+
expect { subject.write "foo" }.to change { subject.messages.size }.by(1)
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
66
|
+
it "does not write after termination" do
|
67
67
|
subject.terminate
|
68
|
-
expect { subject.write
|
68
|
+
expect { subject.write "foo" }.to raise_error(FastlyNsq::NotConnectedError)
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
71
|
+
it "can connect after termination" do
|
72
72
|
subject.terminate
|
73
73
|
expect { subject.connect }.to change(subject, :connected?).to(true)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
describe
|
77
|
+
describe "inline", :inline do
|
78
78
|
it { should be_connected }
|
79
79
|
|
80
|
-
it
|
80
|
+
it "should terminate" do
|
81
81
|
expect { subject.terminate }.to change(subject, :connected?).to(false)
|
82
82
|
expect(subject.connection).to eq(nil)
|
83
83
|
end
|
84
84
|
|
85
|
-
it
|
86
|
-
expect { subject.write
|
85
|
+
it "writes a message" do
|
86
|
+
expect { subject.write "foo" }.to change { subject.messages.size }.by(1)
|
87
87
|
end
|
88
88
|
|
89
|
-
it
|
89
|
+
it "does not write after termination" do
|
90
90
|
subject.terminate
|
91
|
-
expect { subject.write
|
91
|
+
expect { subject.write "foo" }.to raise_error(FastlyNsq::NotConnectedError)
|
92
92
|
end
|
93
93
|
|
94
|
-
it
|
94
|
+
it "can connect after termination" do
|
95
95
|
subject.terminate
|
96
96
|
expect { subject.connect }.to change(subject, :connected?).to(true)
|
97
97
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dotenv"
|
4
4
|
Dotenv.load
|
5
5
|
|
6
|
-
require
|
6
|
+
require "bundler/setup"
|
7
7
|
|
8
8
|
Bundler.require(:development)
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
10
|
+
require "fastly_nsq"
|
11
|
+
require "fastly_nsq/http"
|
12
|
+
require "fastly_nsq/testing"
|
13
13
|
|
14
|
-
Dir[File.expand_path(
|
14
|
+
Dir[File.expand_path("../{support,shared,matchers}/**/*.rb", __FILE__)].sort.each { |f| require(f) }
|
15
15
|
|
16
16
|
FastlyNsq::Testing.disable!
|
17
17
|
|
18
|
-
if ENV[
|
18
|
+
if ENV["DEBUG"]
|
19
19
|
Concurrent.use_stdlib_logger(Logger::DEBUG)
|
20
|
-
FastlyNsq.logger = Logger.new(
|
20
|
+
FastlyNsq.logger = Logger.new($stdout)
|
21
21
|
else
|
22
22
|
Concurrent.use_stdlib_logger(Logger::ERROR)
|
23
|
-
FastlyNsq.logger = Logger.new(
|
23
|
+
FastlyNsq.logger = Logger.new("/dev/null").tap { |l| l.level = Logger::DEBUG }
|
24
24
|
end
|
25
25
|
|
26
26
|
RSpec.configure do |config|
|
@@ -32,15 +32,15 @@ RSpec.configure do |config|
|
|
32
32
|
mocks.verify_partial_doubles = true
|
33
33
|
end
|
34
34
|
|
35
|
-
config.default_formatter =
|
35
|
+
config.default_formatter = "progress"
|
36
36
|
config.disable_monkey_patching!
|
37
|
-
config.example_status_persistence_file_path =
|
37
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
38
38
|
config.filter_run :focus
|
39
39
|
config.order = :random
|
40
40
|
config.profile_examples = 1
|
41
41
|
config.run_all_when_everything_filtered = true
|
42
42
|
Kernel.srand config.seed
|
43
|
-
config.default_formatter =
|
43
|
+
config.default_formatter = "doc" if config.files_to_run.one?
|
44
44
|
|
45
45
|
config.around(:each, fake: true) do |example|
|
46
46
|
RSpec::Mocks.with_temporary_scope do
|
data/spec/support/http.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module SupportHttp
|
4
4
|
def message_count(topic)
|
5
|
-
topic_stats = JSON.parse(FastlyNsq::Http::Nsqd.stats(topic: topic).body)[
|
6
|
-
topic_stats[
|
5
|
+
topic_stats = JSON.parse(FastlyNsq::Http::Nsqd.stats(topic: topic).body)["topics"].first || {}
|
6
|
+
topic_stats["message_count"]
|
7
7
|
end
|
8
8
|
|
9
9
|
def create_topic(topic)
|
data/spec/support/webmock.rb
CHANGED
data/spec/testing_spec.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::Testing do
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
data = {
|
6
|
+
describe ".message" do
|
7
|
+
it "returns a FastlyNsq::Message" do
|
8
|
+
data = {"foo" => "bar"}
|
9
9
|
message = FastlyNsq::Testing.message(data: data)
|
10
10
|
|
11
|
-
expect(message.body).to eq(
|
11
|
+
expect(message.body).to eq("data" => data, "meta" => nil)
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
15
|
-
data = {
|
16
|
-
meta =
|
14
|
+
it "returns a FastlyNsq::Message with meta" do
|
15
|
+
data = {"foo" => "bar"}
|
16
|
+
meta = "foo"
|
17
17
|
message = FastlyNsq::Testing.message(data: data, meta: meta)
|
18
18
|
|
19
|
-
expect(message.body).to eq(
|
19
|
+
expect(message.body).to eq("data" => data, "meta" => meta)
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
data =
|
22
|
+
it "wraps a FastlyNsq::TestMessage" do
|
23
|
+
data = "bar"
|
24
24
|
message = FastlyNsq::Testing.message(data: data)
|
25
25
|
expect(message.nsq_message).to be_a(FastlyNsq::TestMessage)
|
26
|
-
expect(message.nsq_message.body).to eq(JSON.dump(
|
26
|
+
expect(message.nsq_message.body).to eq(JSON.dump("data" => data, "meta" => nil))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|