Skip to content

Commit c4e8357

Browse files
committed
Stub requests in event sending spec
This spec was very flaky
1 parent 5e542ea commit c4e8357

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

sentry-ruby/spec/sentry/client/event_sending_spec.rb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
config.transport.transport_class = Sentry::DummyTransport
1111
end
1212
end
13+
14+
before do
15+
stub_request(:post, Sentry::TestHelper::DUMMY_DSN)
16+
end
17+
1318
subject(:client) { Sentry::Client.new(configuration) }
1419

1520
let(:hub) do
@@ -470,13 +475,16 @@
470475
before do
471476
configuration.background_worker_threads = 0
472477
Sentry.background_worker = Sentry::BackgroundWorker.new(configuration)
478+
479+
stub_request(:post, "http://sentry.localdomain/sentry/api/42/envelope/")
480+
.to_raise(Timeout::Error)
473481
end
474482

475483
it "swallows and logs Sentry::ExternalError (caused by transport's networking error)" do
476484
expect(client.capture_event(event, scope)).to be_nil
477485

478-
expect(string_io.string).to match(/Event sending failed: Failed to open TCP connection/)
479-
expect(string_io.string).to match(/Event capturing failed: Failed to open TCP connection/)
486+
expect(string_io.string).to match(/Event sending failed: Exception from WebMock/)
487+
expect(string_io.string).to match(/Event capturing failed: Exception from WebMock/)
480488
end
481489

482490
it "swallows and logs errors caused by the user (like in before_send)" do
@@ -502,13 +510,16 @@
502510
context "when sending events in background causes error", retry: 3 do
503511
before do
504512
Sentry.background_worker = Sentry::BackgroundWorker.new(configuration)
513+
514+
stub_request(:post, "http://sentry.localdomain/sentry/api/42/envelope/")
515+
.to_raise(Timeout::Error)
505516
end
506517

507518
it "swallows and logs Sentry::ExternalError (caused by transport's networking error)" do
508519
expect(client.capture_event(event, scope)).to be_a(Sentry::ErrorEvent)
509520
sleep(0.2)
510521

511-
expect(string_io.string).to match(/Event sending failed: Failed to open TCP connection/)
522+
expect(string_io.string).to match(/Event sending failed: Exception from WebMock/)
512523
end
513524

514525
it "swallows and logs errors caused by the user (like in before_send)" do
@@ -560,11 +571,14 @@
560571
describe "#send_event" do
561572
context "error happens when sending the event" do
562573
it "raises the error" do
574+
stub_request(:post, "http://sentry.localdomain/sentry/api/42/envelope/")
575+
.to_raise(Timeout::Error)
576+
563577
expect do
564578
client.send_event(event)
565579
end.to raise_error(Sentry::ExternalError)
566580

567-
expect(string_io.string).to match(/Event sending failed: Failed to open TCP connection/)
581+
expect(string_io.string).to match(/Event sending failed: Exception from WebMock/)
568582
end
569583
end
570584

@@ -635,6 +649,9 @@
635649
end
636650

637651
it "records lost span delta client reports" do
652+
stub_request(:post, "http://sentry.localdomain/sentry/api/42/envelope/")
653+
.to_raise(Timeout::Error)
654+
638655
expect { client.send_event(transaction_event) }.to raise_error(Sentry::ExternalError)
639656
expect(client.transport).to have_recorded_lost_event(:before_send, 'span', num: 2)
640657
end

0 commit comments

Comments
 (0)