appsignal 4.0.5 → 4.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,16 +4,13 @@ describe Appsignal::CheckIn::Cron do
4
4
  let(:appsignal_options) { {} }
5
5
  let(:config) { project_fixture_config }
6
6
  let(:cron_checkin) { described_class.new(:identifier => "cron-checkin-name") }
7
- let(:transmitter) { Appsignal::Transmitter.new("https://checkin-endpoint.invalid") }
8
- let(:scheduler) { Appsignal::CheckIn::Scheduler.new }
7
+ let(:scheduler) { Appsignal::CheckIn.scheduler }
9
8
 
10
9
  before do
11
10
  start_agent(
12
11
  :options => appsignal_options,
13
12
  :internal_logger => test_logger(log_stream)
14
13
  )
15
- allow(Appsignal::CheckIn).to receive(:scheduler).and_return(scheduler)
16
- allow(Appsignal::CheckIn).to receive(:transmitter).and_return(transmitter)
17
14
  end
18
15
  after { stop_scheduler }
19
16
 
@@ -64,11 +61,13 @@ describe Appsignal::CheckIn::Cron do
64
61
  it "sends a cron check-in start" do
65
62
  cron_checkin.start
66
63
 
67
- expect(transmitter).to receive(:transmit).with([hash_including(
68
- :identifier => "cron-checkin-name",
69
- :kind => "start",
70
- :check_in_type => "cron"
71
- )], :format => :ndjson).and_return(Net::HTTPResponse.new(nil, "200", nil))
64
+ stub_check_in_request(
65
+ :events => [
66
+ "identifier" => "cron-checkin-name",
67
+ "kind" => "start",
68
+ "check_in_type" => "cron"
69
+ ]
70
+ )
72
71
 
73
72
  scheduler.stop
74
73
 
@@ -86,11 +85,14 @@ describe Appsignal::CheckIn::Cron do
86
85
  it "logs an error if it fails" do
87
86
  cron_checkin.start
88
87
 
89
- expect(transmitter).to receive(:transmit).with([hash_including(
90
- :identifier => "cron-checkin-name",
91
- :kind => "start",
92
- :check_in_type => "cron"
93
- )], :format => :ndjson).and_return(Net::HTTPResponse.new(nil, "499", nil))
88
+ stub_check_in_request(
89
+ :events => [
90
+ "identifier" => "cron-checkin-name",
91
+ "kind" => "start",
92
+ "check_in_type" => "cron"
93
+ ],
94
+ :response => { :status => 499 }
95
+ )
94
96
 
95
97
  scheduler.stop
96
98
 
@@ -109,11 +111,13 @@ describe Appsignal::CheckIn::Cron do
109
111
  it "sends a cron check-in finish" do
110
112
  cron_checkin.finish
111
113
 
112
- expect(transmitter).to receive(:transmit).with([hash_including(
113
- :identifier => "cron-checkin-name",
114
- :kind => "finish",
115
- :check_in_type => "cron"
116
- )], :format => :ndjson).and_return(Net::HTTPResponse.new(nil, "200", nil))
114
+ stub_check_in_request(
115
+ :events => [
116
+ "identifier" => "cron-checkin-name",
117
+ "kind" => "finish",
118
+ "check_in_type" => "cron"
119
+ ]
120
+ )
117
121
 
118
122
  scheduler.stop
119
123
  expect(logs).to_not contains_log(:error)
@@ -130,11 +134,14 @@ describe Appsignal::CheckIn::Cron do
130
134
  it "logs an error if it fails" do
131
135
  cron_checkin.finish
132
136
 
133
- expect(transmitter).to receive(:transmit).with([hash_including(
134
- :identifier => "cron-checkin-name",
135
- :kind => "finish",
136
- :check_in_type => "cron"
137
- )], :format => :ndjson).and_return(Net::HTTPResponse.new(nil, "499", nil))
137
+ stub_check_in_request(
138
+ :events => [
139
+ "identifier" => "cron-checkin-name",
140
+ "kind" => "finish",
141
+ "check_in_type" => "cron"
142
+ ],
143
+ :response => { :status => 499 }
144
+ )
138
145
 
139
146
  scheduler.stop
140
147
 
@@ -152,34 +159,33 @@ describe Appsignal::CheckIn::Cron do
152
159
  describe ".cron" do
153
160
  describe "when a block is given" do
154
161
  it "sends a cron check-in start and finish and return the block output" do
155
- expect(scheduler).to receive(:schedule).with(hash_including(
156
- :kind => "start",
157
- :identifier => "cron-checkin-with-block",
158
- :check_in_type => "cron"
159
- ))
160
-
161
- expect(scheduler).to receive(:schedule).with(hash_including(
162
- :kind => "finish",
163
- :identifier => "cron-checkin-with-block",
164
- :check_in_type => "cron"
165
- ))
162
+ stub_check_in_request(
163
+ :events => [
164
+ "identifier" => "cron-checkin-with-block",
165
+ "kind" => "start",
166
+ "check_in_type" => "cron"
167
+ ]
168
+ )
169
+ stub_check_in_request(
170
+ :events => [
171
+ "identifier" => "cron-checkin-with-block",
172
+ "kind" => "finish",
173
+ "check_in_type" => "cron"
174
+ ]
175
+ )
166
176
 
167
177
  output = Appsignal::CheckIn.cron("cron-checkin-with-block") { "output" }
168
178
  expect(output).to eq("output")
169
179
  end
170
180
 
171
181
  it "does not send a cron check-in finish event when an error is raised" do
172
- expect(scheduler).to receive(:schedule).with(hash_including(
173
- :kind => "start",
174
- :identifier => "cron-checkin-with-block",
175
- :check_in_type => "cron"
176
- ))
177
-
178
- expect(scheduler).not_to receive(:schedule).with(hash_including(
179
- :kind => "finish",
180
- :identifier => "cron-checkin-with-block",
181
- :check_in_type => "cron"
182
- ))
182
+ stub_check_in_request(
183
+ :events => [
184
+ "identifier" => "cron-checkin-with-block",
185
+ "kind" => "start",
186
+ "check_in_type" => "cron"
187
+ ]
188
+ )
183
189
 
184
190
  expect do
185
191
  Appsignal::CheckIn.cron("cron-checkin-with-block") { raise "error" }
@@ -189,11 +195,13 @@ describe Appsignal::CheckIn::Cron do
189
195
 
190
196
  describe "when no block is given" do
191
197
  it "only sends a cron check-in finish event" do
192
- expect(scheduler).to receive(:schedule).with(hash_including(
193
- :kind => "finish",
194
- :identifier => "cron-checkin-without-block",
195
- :check_in_type => "cron"
196
- ))
198
+ stub_check_in_request(
199
+ :events => [
200
+ "identifier" => "cron-checkin-without-block",
201
+ "kind" => "finish",
202
+ "check_in_type" => "cron"
203
+ ]
204
+ )
197
205
 
198
206
  Appsignal::CheckIn.cron("cron-checkin-without-block")
199
207
  end