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/cli_spec.rb
CHANGED
data/spec/consumer_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq::Consumer do
|
6
|
-
let!(:topic)
|
7
|
-
let!(:channel) {
|
8
|
-
let!(:queue)
|
6
|
+
let!(:topic) { "fnsq" }
|
7
|
+
let!(:channel) { "fnsq" }
|
8
|
+
let!(:queue) { nil }
|
9
9
|
|
10
10
|
subject { described_class.new(topic: topic, channel: channel, queue: queue) }
|
11
11
|
|
@@ -16,15 +16,15 @@ RSpec.describe FastlyNsq::Consumer do
|
|
16
16
|
|
17
17
|
it { should be_connected }
|
18
18
|
|
19
|
-
it
|
19
|
+
it "should terminate" do
|
20
20
|
expect { subject.terminate }.to change(subject, :connected?).to(false)
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
23
|
+
describe "with a specified queue" do
|
24
24
|
let!(:queue) { Queue.new }
|
25
25
|
|
26
|
-
it
|
27
|
-
message =
|
26
|
+
it "passes #queue to Nsq::Consumer" do
|
27
|
+
message = "foo"
|
28
28
|
|
29
29
|
FastlyNsq::Messenger.deliver(message: message, topic: topic)
|
30
30
|
|
@@ -41,16 +41,16 @@ RSpec.describe FastlyNsq::Consumer do
|
|
41
41
|
it { should delegate(:pop).to(:connection) }
|
42
42
|
it { should delegate(:pop_without_blocking).to(:connection) }
|
43
43
|
|
44
|
-
describe
|
45
|
-
let(:message) {
|
44
|
+
describe "with a message" do
|
45
|
+
let(:message) { "foo" }
|
46
46
|
|
47
47
|
before { FastlyNsq::Messenger.deliver(message: message, topic: topic) }
|
48
48
|
|
49
|
-
it
|
49
|
+
it "should not be empty" do
|
50
50
|
expect { subject }.to eventually(be_empty).within(15)
|
51
51
|
end
|
52
52
|
|
53
|
-
describe
|
53
|
+
describe "that has finished" do
|
54
54
|
before { subject.pop.finish }
|
55
55
|
|
56
56
|
it { should be_empty }
|
data/spec/fastly_nsq_spec.rb
CHANGED
@@ -1,89 +1,89 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq do
|
6
|
-
describe
|
6
|
+
describe "#configure" do
|
7
7
|
specify { expect { |b| described_class.configure(&b) }.to yield_with_args(described_class) }
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe "#listen" do
|
11
11
|
let!(:default_channel) { subject.channel }
|
12
|
-
let!(:topic) {
|
12
|
+
let!(:topic) { "fnsq" }
|
13
13
|
|
14
|
-
before { subject.channel =
|
14
|
+
before { subject.channel = "fnsq" }
|
15
15
|
after { subject.channel = default_channel }
|
16
16
|
|
17
|
-
it
|
17
|
+
it "creates a listener" do
|
18
18
|
expect { subject.listen topic, ->(*) {} }.to change { subject.manager.topics }.to([topic])
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it "creates a listener with a specific priority" do
|
22
22
|
listener = subject.listen topic, ->(*) {}, priority: 10
|
23
23
|
expect(listener.priority).to eq(10)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe
|
27
|
+
describe "#channel=" do
|
28
28
|
let!(:default_channel) { subject.channel }
|
29
29
|
after { subject.channel = default_channel }
|
30
30
|
|
31
|
-
it
|
31
|
+
it "allows the channel to be set and retrieved" do
|
32
32
|
expect(subject.channel).to be_nil
|
33
|
-
subject.channel =
|
34
|
-
expect(subject.channel).to eq(
|
33
|
+
subject.channel = "foo"
|
34
|
+
expect(subject.channel).to eq("foo")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe
|
38
|
+
describe "#logger" do
|
39
39
|
let!(:default_logger) { subject.logger }
|
40
40
|
after { subject.logger = default_logger }
|
41
41
|
|
42
|
-
it
|
42
|
+
it "returns the set logger" do
|
43
43
|
logger = Logger.new(nil)
|
44
44
|
subject.logger = logger
|
45
45
|
|
46
46
|
expect(subject.logger).to eq logger
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it "sets the default logger if none is set" do
|
50
50
|
subject.instance_variable_set(:@logger, nil)
|
51
51
|
expect(subject.instance_variable_get(:@logger)).to be nil
|
52
52
|
logger = subject.logger
|
53
53
|
|
54
54
|
expect(logger).to be_instance_of(Logger)
|
55
|
-
expect(logger.instance_variable_get(:@logdev).dev).to eq(
|
55
|
+
expect(logger.instance_variable_get(:@logdev).dev).to eq($stderr)
|
56
56
|
expect(logger).to eq(Nsq.logger)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
describe
|
60
|
+
describe "#logger=" do
|
61
61
|
let!(:default_logger) { subject.logger }
|
62
62
|
after { subject.logger = default_logger }
|
63
63
|
|
64
|
-
it
|
65
|
-
logger = Logger.new(
|
64
|
+
it "allows the logger to be set and retrieved" do
|
65
|
+
logger = Logger.new($stdout)
|
66
66
|
subject.logger = logger
|
67
67
|
|
68
68
|
expect(subject.logger).to eq logger
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
logger = Logger.new(
|
71
|
+
it "sets Nsq.logger" do
|
72
|
+
logger = Logger.new($stdout)
|
73
73
|
subject.logger = logger
|
74
74
|
|
75
75
|
expect(Nsq.logger).to eq logger
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
describe
|
80
|
-
it
|
79
|
+
describe "#manager" do
|
80
|
+
it "represents the active default manager" do
|
81
81
|
expect(subject.manager).not_to be_stopped
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
describe
|
86
|
-
it
|
85
|
+
describe "#manager=" do
|
86
|
+
it "transfers to specified manager" do
|
87
87
|
old_manager = subject.manager
|
88
88
|
new_manager = FastlyNsq::Manager.new
|
89
89
|
|
@@ -93,17 +93,17 @@ RSpec.describe FastlyNsq do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
describe
|
97
|
-
it
|
98
|
-
expect(subject.lookupd_http_addresses).to eq(ENV[
|
96
|
+
describe "#lookupd_http_addresses" do
|
97
|
+
it "retreives NSQLOOKUPD_HTTP_ADDRESS" do
|
98
|
+
expect(subject.lookupd_http_addresses).to eq(ENV["NSQLOOKUPD_HTTP_ADDRESS"].split(","))
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
describe
|
102
|
+
describe "#on" do
|
103
103
|
before { FastlyNsq.events.each { |(_, v)| v.clear } }
|
104
|
-
after
|
104
|
+
after { FastlyNsq.events.each { |(_, v)| v.clear } }
|
105
105
|
|
106
|
-
it
|
106
|
+
it "registers callbacks for events" do
|
107
107
|
%i[startup shutdown heartbeat].each do |event|
|
108
108
|
block = -> {}
|
109
109
|
FastlyNsq.on(event, &block)
|
@@ -111,7 +111,7 @@ RSpec.describe FastlyNsq do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
it
|
114
|
+
it "limits callback registration to valid events" do
|
115
115
|
expect { FastlyNsq.on(:foo, &-> {}) }.to raise_error(ArgumentError, /Invalid event name/)
|
116
116
|
end
|
117
117
|
end
|
data/spec/feeder_spec.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq::Feeder do
|
6
|
-
describe
|
7
|
-
it
|
6
|
+
describe "#push" do
|
7
|
+
it "sends message to processor with the specified priority" do
|
8
8
|
messages = []
|
9
9
|
processor = ->(m) { messages << m }
|
10
10
|
priority = 5
|
11
|
-
message =
|
11
|
+
message = "foo"
|
12
12
|
|
13
13
|
feeder = described_class.new(processor, priority)
|
14
14
|
|
data/spec/http/nsqd_spec.rb
CHANGED
@@ -1,77 +1,77 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "fastly_nsq/http/nsqd"
|
5
5
|
|
6
6
|
RSpec.describe FastlyNsq::Http::Nsqd, :webmock do
|
7
|
-
let(:base_uri) {
|
7
|
+
let(:base_uri) { "http://example.com" }
|
8
8
|
|
9
|
-
it
|
9
|
+
it "makes simple get requests" do
|
10
10
|
%w[ping info config/nsqlookupd_tcp_addresses].each do |api|
|
11
11
|
url = "#{base_uri}/#{api}"
|
12
12
|
stub_request(:get, url)
|
13
|
-
FastlyNsq::Http::Nsqd.send(api.tr(
|
13
|
+
FastlyNsq::Http::Nsqd.send(api.tr("/", "_").to_sym, base_uri: base_uri)
|
14
14
|
|
15
15
|
expect(a_request(:get, url)).to have_been_requested
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe
|
20
|
-
it
|
19
|
+
describe "stats" do
|
20
|
+
it "can fetch stats" do
|
21
21
|
url = "#{base_uri}/stats?topic=lol&channel=foo&format=json"
|
22
22
|
stub_request(:get, url)
|
23
|
-
data = {
|
23
|
+
data = {topic: "lol", channel: "foo", format: "json"}
|
24
24
|
|
25
|
-
FastlyNsq::Http::Nsqd.stats(topic:
|
25
|
+
FastlyNsq::Http::Nsqd.stats(topic: "lol", channel: "foo", base_uri: base_uri)
|
26
26
|
|
27
27
|
expect(a_request(:get, url).with(query: data)).to have_been_requested
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it "raises InvaildFormatError if provided format is not in list" do
|
31
31
|
expect do
|
32
|
-
FastlyNsq::Http::Nsqd.stats(format:
|
32
|
+
FastlyNsq::Http::Nsqd.stats(format: "foo")
|
33
33
|
end.to raise_error(FastlyNsq::Http::Nsqd::InvalidFormatError)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it "can publish messages" do
|
38
38
|
url = "#{base_uri}/pub?topic=lol&defer=999"
|
39
39
|
stub_request(:post, url)
|
40
|
-
data = {
|
40
|
+
data = {topic: "lol", defer: 999}
|
41
41
|
|
42
|
-
FastlyNsq::Http::Nsqd.pub(topic:
|
42
|
+
FastlyNsq::Http::Nsqd.pub(topic: "lol", defer: 999, message: "SOMETHING", base_uri: base_uri)
|
43
43
|
|
44
|
-
expect(a_request(:post, url).with(query: data, body:
|
44
|
+
expect(a_request(:post, url).with(query: data, body: "SOMETHING")).to have_been_requested
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it "can publish multiple messages" do
|
48
48
|
url = "#{base_uri}/mpub?topic=lol&binary=false"
|
49
49
|
stub_request(:post, url)
|
50
|
-
data = {
|
50
|
+
data = {topic: "lol"}
|
51
51
|
body = "ONE MESSAGE\nTWO MESSAGE\nRED MESSAGE\nBLUE MESSAGE"
|
52
52
|
|
53
|
-
FastlyNsq::Http::Nsqd.mpub(topic:
|
53
|
+
FastlyNsq::Http::Nsqd.mpub(topic: "lol", message: body, base_uri: base_uri)
|
54
54
|
|
55
55
|
expect(a_request(:post, url).with(query: data, body: body)).to have_been_requested
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
58
|
+
it "can create, delete, empty, pause and unpause topics and channels" do
|
59
59
|
verbs = %w[create delete empty pause unpause]
|
60
60
|
|
61
61
|
verbs.each do |verb|
|
62
62
|
url = "#{base_uri}/topic/#{verb}?topic=lol"
|
63
63
|
stub_request(:post, url)
|
64
|
-
data = {
|
64
|
+
data = {topic: "lol"}
|
65
65
|
|
66
|
-
FastlyNsq::Http::Nsqd.send("topic_#{verb}".to_sym, topic:
|
66
|
+
FastlyNsq::Http::Nsqd.send("topic_#{verb}".to_sym, topic: "lol", base_uri: base_uri)
|
67
67
|
|
68
68
|
expect(a_request(:post, url).with(query: data)).to have_been_requested
|
69
69
|
|
70
70
|
url = "#{base_uri}/channel/#{verb}?topic=lol&channel=foo"
|
71
71
|
stub_request(:post, url)
|
72
|
-
data = {
|
72
|
+
data = {topic: "lol", channel: "foo"}
|
73
73
|
|
74
|
-
FastlyNsq::Http::Nsqd.send("channel_#{verb}".to_sym, topic:
|
74
|
+
FastlyNsq::Http::Nsqd.send("channel_#{verb}".to_sym, topic: "lol", channel: "foo", base_uri: base_uri)
|
75
75
|
|
76
76
|
expect(a_request(:post, url).with(query: data)).to have_been_requested
|
77
77
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "fastly_nsq/http/nsqlookupd"
|
5
5
|
|
6
6
|
RSpec.describe FastlyNsq::Http::Nsqlookupd, :webmock do
|
7
|
-
let(:base_uri) {
|
7
|
+
let(:base_uri) { "http://example.com" }
|
8
8
|
|
9
|
-
it
|
9
|
+
it "makes simple get requests" do
|
10
10
|
%w[topics nodes ping info].each do |api|
|
11
11
|
url = "#{base_uri}/#{api}"
|
12
12
|
stub_request(:get, url)
|
@@ -16,52 +16,52 @@ RSpec.describe FastlyNsq::Http::Nsqlookupd, :webmock do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it "can lookup producers for a topic" do
|
20
20
|
url = "#{base_uri}/lookup?topic=lol"
|
21
21
|
stub_request(:get, url)
|
22
|
-
data = {
|
22
|
+
data = {topic: "lol"}
|
23
23
|
|
24
|
-
FastlyNsq::Http::Nsqlookupd.lookup(topic:
|
24
|
+
FastlyNsq::Http::Nsqlookupd.lookup(topic: "lol", base_uri: base_uri)
|
25
25
|
|
26
26
|
expect(a_request(:get, url).with(query: data)).to have_been_requested
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it "can lookup channels for a topic" do
|
30
30
|
url = "#{base_uri}/channels?topic=lol"
|
31
31
|
stub_request(:get, url)
|
32
|
-
data = {
|
32
|
+
data = {topic: "lol"}
|
33
33
|
|
34
|
-
FastlyNsq::Http::Nsqlookupd.channels(topic:
|
34
|
+
FastlyNsq::Http::Nsqlookupd.channels(topic: "lol", base_uri: base_uri)
|
35
35
|
|
36
36
|
expect(a_request(:get, url).with(query: data)).to have_been_requested
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it "can delete a topic" do
|
40
40
|
url = "#{base_uri}/delete_topic?topic=lol"
|
41
41
|
stub_request(:get, url)
|
42
|
-
data = {
|
42
|
+
data = {topic: "lol"}
|
43
43
|
|
44
|
-
FastlyNsq::Http::Nsqlookupd.delete_topic(topic:
|
44
|
+
FastlyNsq::Http::Nsqlookupd.delete_topic(topic: "lol", base_uri: base_uri)
|
45
45
|
|
46
46
|
expect(a_request(:get, url).with(query: data)).to have_been_requested
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it "can delete a channel" do
|
50
50
|
url = "#{base_uri}/delete_channel?topic=lol&channel=foo"
|
51
51
|
stub_request(:get, url)
|
52
|
-
data = {
|
52
|
+
data = {topic: "lol", channel: "foo"}
|
53
53
|
|
54
|
-
FastlyNsq::Http::Nsqlookupd.delete_channel(topic:
|
54
|
+
FastlyNsq::Http::Nsqlookupd.delete_channel(topic: "lol", channel: "foo", base_uri: base_uri)
|
55
55
|
|
56
56
|
expect(a_request(:get, url).with(query: data)).to have_been_requested
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it "can tombstone a producer" do
|
60
60
|
url = "#{base_uri}/tombstone_topic_producer?topic=lol&node=localhost:8989"
|
61
61
|
stub_request(:get, url)
|
62
|
-
data = {
|
62
|
+
data = {topic: "lol", node: "localhost:8989"}
|
63
63
|
|
64
|
-
FastlyNsq::Http::Nsqlookupd.tombstone_topic_producer(topic:
|
64
|
+
FastlyNsq::Http::Nsqlookupd.tombstone_topic_producer(topic: "lol", node: "localhost:8989", base_uri: base_uri)
|
65
65
|
|
66
66
|
expect(a_request(:get, url).with(query: data)).to have_been_requested
|
67
67
|
end
|
data/spec/http_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "fastly_nsq/http"
|
5
5
|
|
6
6
|
RSpec.describe FastlyNsq::Http, :webmock do
|
7
|
-
let(:base_url) {
|
8
|
-
describe
|
9
|
-
it
|
7
|
+
let(:base_url) { "http://example.com" }
|
8
|
+
describe "get" do
|
9
|
+
it "can make simple requests" do
|
10
10
|
url = "#{base_url}/boop"
|
11
11
|
stub_request(:get, url)
|
12
12
|
|
@@ -16,9 +16,9 @@ RSpec.describe FastlyNsq::Http, :webmock do
|
|
16
16
|
expect(a_request(:get, url)).to have_been_requested.twice
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it "can make requests with params" do
|
20
20
|
url = "#{base_url}/boop?sloop=noop"
|
21
|
-
data = {
|
21
|
+
data = {sloop: "noop"}
|
22
22
|
stub_request(:get, url)
|
23
23
|
|
24
24
|
FastlyNsq::Http.new(uri: url).get(data)
|
@@ -27,11 +27,11 @@ RSpec.describe FastlyNsq::Http, :webmock do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe
|
31
|
-
it
|
30
|
+
describe "post" do
|
31
|
+
it "can make simple post requests" do
|
32
32
|
url = "#{base_url}/boop?sloop=noop"
|
33
33
|
stub_request(:post, url)
|
34
|
-
data = {
|
34
|
+
data = {sloop: "noop"}
|
35
35
|
|
36
36
|
FastlyNsq::Http.new(uri: URI.parse(url)).post(data)
|
37
37
|
FastlyNsq::Http.new(uri: url).post(data)
|
@@ -39,11 +39,11 @@ RSpec.describe FastlyNsq::Http, :webmock do
|
|
39
39
|
expect(a_request(:post, url)).to have_been_requested.twice
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
42
|
+
it "can make post requests with bodies" do
|
43
43
|
url = "#{base_url}/boop?sloop=noop"
|
44
44
|
stub_request(:post, url)
|
45
|
-
data = {
|
46
|
-
body =
|
45
|
+
data = {sloop: "noop"}
|
46
|
+
body = "SOME MESSAGE"
|
47
47
|
|
48
48
|
FastlyNsq::Http.new(uri: url).post(data, body)
|
49
49
|
|
@@ -51,18 +51,18 @@ RSpec.describe FastlyNsq::Http, :webmock do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
55
|
-
it
|
56
|
-
ssl_url =
|
54
|
+
describe "SSL" do
|
55
|
+
it "can be asked to use SSL" do
|
56
|
+
ssl_url = "https://example.com:80/boop"
|
57
57
|
stub_request(:get, ssl_url)
|
58
58
|
|
59
|
-
cert_file =
|
60
|
-
key_file =
|
59
|
+
cert_file = "/tmp/thing.cert"
|
60
|
+
key_file = "/tmp/thing.key"
|
61
61
|
|
62
|
-
allow(File).to receive(:read).with(cert_file).and_return(
|
63
|
-
allow(File).to receive(:read).with(key_file).and_return(
|
64
|
-
allow(OpenSSL::X509::Certificate).to receive(:new).with(
|
65
|
-
allow(OpenSSL::PKey::RSA).to receive(:new).with(
|
62
|
+
allow(File).to receive(:read).with(cert_file).and_return("something")
|
63
|
+
allow(File).to receive(:read).with(key_file).and_return("something")
|
64
|
+
allow(OpenSSL::X509::Certificate).to receive(:new).with("something").and_return(true)
|
65
|
+
allow(OpenSSL::PKey::RSA).to receive(:new).with("something").and_return(true)
|
66
66
|
|
67
67
|
url = "#{base_url}/boop"
|
68
68
|
http = FastlyNsq::Http.new(uri: url, cert_filename: cert_file, key_filename: key_file)
|
data/spec/integration_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
|
-
RSpec.describe
|
6
|
-
let!(:topic) {
|
7
|
-
let!(:channel) {
|
8
|
-
let!(:message) { {
|
5
|
+
RSpec.describe "integration" do
|
6
|
+
let!(:topic) { "fnsq-topic" }
|
7
|
+
let!(:channel) { "fnsq-channel" }
|
8
|
+
let!(:message) { {"foo" => "bar"} }
|
9
9
|
|
10
10
|
before { reset_topic(topic, channel: channel) }
|
11
11
|
|
12
|
-
it
|
12
|
+
it "processes jobs" do
|
13
13
|
received = nil
|
14
14
|
producer = FastlyNsq::Producer.new(topic: topic)
|
15
15
|
FastlyNsq::Listener.new(topic: topic, channel: channel, processor: ->(m) { received = m })
|
@@ -18,8 +18,8 @@ RSpec.describe 'integration' do
|
|
18
18
|
expect { received&.body }.to eventually(eq(message)).within(2)
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
it
|
21
|
+
describe "inline", :inline do
|
22
|
+
it "processes job" do
|
23
23
|
received = nil
|
24
24
|
producer = FastlyNsq::Producer.new(topic: topic)
|
25
25
|
FastlyNsq::Listener.new(topic: topic, channel: channel, processor: ->(m) { received = m })
|
@@ -29,8 +29,8 @@ RSpec.describe 'integration' do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
33
|
-
it
|
32
|
+
describe "fake", :fake do
|
33
|
+
it "stores jobs" do
|
34
34
|
received = nil
|
35
35
|
encoded_message = JSON.dump(message)
|
36
36
|
producer = FastlyNsq::Producer.new(topic: topic)
|
data/spec/launcher_spec.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq::Launcher do
|
6
|
-
let!(:channel)
|
7
|
-
let!(:options)
|
8
|
-
let!(:topic)
|
6
|
+
let!(:channel) { "fnsq" }
|
7
|
+
let!(:options) { {max_threads: 3, timeout: 9} }
|
8
|
+
let!(:topic) { "fnsq" }
|
9
9
|
|
10
|
-
let(:launcher) { FastlyNsq::Launcher.new
|
11
|
-
let(:listener)
|
10
|
+
let(:launcher) { FastlyNsq::Launcher.new(**options) }
|
11
|
+
let(:listener) { FastlyNsq::Listener.new(topic: topic, channel: channel, processor: ->(*) {}) }
|
12
12
|
let(:manager) { launcher.manager }
|
13
13
|
|
14
14
|
before { reset_topic(topic, channel: channel) }
|
15
15
|
before { expect { listener }.to eventually(be_connected).within(5) }
|
16
|
-
after
|
16
|
+
after { listener.terminate if listener.connected? }
|
17
17
|
|
18
|
-
it
|
18
|
+
it "creates a manager with correct options" do
|
19
19
|
launcher
|
20
20
|
|
21
21
|
expect(FastlyNsq.manager.pool.max_threads).to eq(3)
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
25
|
-
let!(:logger)
|
24
|
+
describe "#beat" do
|
25
|
+
let!(:logger) { Logger.new(nil).tap { |l| l.level = Logger::DEBUG } }
|
26
26
|
let!(:launcher) { FastlyNsq::Launcher.new pulse: 0.01, logger: logger }
|
27
27
|
|
28
|
-
it
|
28
|
+
it "creates a heartbeat thread" do
|
29
29
|
expect(logger).not_to receive(:error)
|
30
|
-
expect { launcher.beat }.to eventually_not(eq(
|
30
|
+
expect { launcher.beat }.to eventually_not(eq("dead")).pause_for(1)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
34
|
+
describe "#stop_listeners" do
|
35
35
|
before { launcher }
|
36
36
|
|
37
|
-
it
|
37
|
+
it "stops listeners and sets done" do
|
38
38
|
expect(launcher).not_to be_stopping
|
39
39
|
expect(manager).to receive(:stop_listeners)
|
40
40
|
expect(manager).not_to receive(:terminate)
|
@@ -45,20 +45,20 @@ RSpec.describe FastlyNsq::Launcher do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe
|
48
|
+
describe "#stop" do
|
49
49
|
before { launcher }
|
50
50
|
|
51
|
-
it
|
51
|
+
it "stops the manager within a deadline" do
|
52
52
|
expect(manager).to receive(:terminate).with(options[:timeout])
|
53
53
|
launcher.stop
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
describe
|
57
|
+
describe "callbacks" do
|
58
58
|
before { FastlyNsq.events.each { |(_, v)| v.clear } }
|
59
|
-
after
|
59
|
+
after { FastlyNsq.events.each { |(_, v)| v.clear } }
|
60
60
|
|
61
|
-
it
|
61
|
+
it "fires :startup event on initialization" do
|
62
62
|
obj = spy
|
63
63
|
block = -> { obj.start }
|
64
64
|
FastlyNsq.on(:startup, &block)
|
@@ -67,7 +67,7 @@ RSpec.describe FastlyNsq::Launcher do
|
|
67
67
|
expect(obj).to have_received(:start)
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
70
|
+
it "fires :shutdown event on #stop" do
|
71
71
|
launcher
|
72
72
|
|
73
73
|
obj = spy
|
@@ -78,7 +78,7 @@ RSpec.describe FastlyNsq::Launcher do
|
|
78
78
|
expect(obj).to have_received(:stop)
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
81
|
+
it "fires :heartbeat event on #heartbeat" do
|
82
82
|
obj = spy
|
83
83
|
block = -> { obj.beat }
|
84
84
|
FastlyNsq.on(:heartbeat, &block)
|