|
52 | 52 | end |
53 | 53 | end |
54 | 54 |
|
55 | | - context 'with config.async set' do |
56 | | - let(:async_block) do |
57 | | - lambda do |event| |
58 | | - subject.send_event(event) |
59 | | - end |
60 | | - end |
61 | | - |
62 | | - around do |example| |
63 | | - prior_async = configuration.async |
64 | | - configuration.async = async_block |
65 | | - example.run |
66 | | - configuration.async = prior_async |
67 | | - end |
68 | | - |
69 | | - it "executes the given block" do |
70 | | - expect(async_block).to receive(:call).and_call_original |
71 | | - |
72 | | - returned = subject.capture_event(event, scope) |
73 | | - |
74 | | - expect(returned).to be_a(Sentry::ErrorEvent) |
75 | | - expect(subject.transport.events.first).to eq(event.to_json_compatible) |
76 | | - end |
77 | | - |
78 | | - it "doesn't call the async block if not allow sending events" do |
79 | | - allow(configuration).to receive(:sending_allowed?).and_return(false) |
80 | | - |
81 | | - expect(async_block).not_to receive(:call) |
82 | | - |
83 | | - returned = subject.capture_event(event, scope) |
84 | | - |
85 | | - expect(returned).to eq(nil) |
86 | | - end |
87 | | - |
88 | | - context "with to json conversion failed" do |
89 | | - let(:logger) { ::Logger.new(string_io) } |
90 | | - let(:string_io) { StringIO.new } |
91 | | - let(:event) { subject.event_from_message("Bad data '\x80\xF8'") } |
92 | | - |
93 | | - it "does not mask the exception" do |
94 | | - configuration.logger = logger |
95 | | - |
96 | | - subject.capture_event(event, scope) |
97 | | - |
98 | | - expect(string_io.string).to include("Converting event (#{event.event_id}) to JSON compatible hash failed: source sequence is illegal/malformed utf-8") |
99 | | - end |
100 | | - end |
101 | | - |
102 | | - context "with nil as value (the legacy way to disable it)" do |
103 | | - let(:async_block) { nil } |
104 | | - |
105 | | - it "doesn't cause any issue" do |
106 | | - returned = subject.capture_event(event, scope, { background: false }) |
107 | | - |
108 | | - expect(returned).to be_a(Sentry::ErrorEvent) |
109 | | - expect(subject.transport.events.first).to eq(event) |
110 | | - end |
111 | | - end |
112 | | - |
113 | | - context "with 2 arity block" do |
114 | | - let(:async_block) do |
115 | | - lambda do |event, hint| |
116 | | - event["tags"]["hint"] = hint |
117 | | - subject.send_event(event) |
118 | | - end |
119 | | - end |
120 | | - |
121 | | - it "serializes hint and supplies it as the second argument" do |
122 | | - expect(configuration.async).to receive(:call).and_call_original |
123 | | - |
124 | | - returned = subject.capture_event(event, scope, { foo: "bar" }) |
125 | | - |
126 | | - expect(returned).to be_a(Sentry::ErrorEvent) |
127 | | - event = subject.transport.events.first |
128 | | - expect(event.dig("tags", "hint")).to eq({ "foo" => "bar" }) |
129 | | - end |
130 | | - end |
131 | | - end |
132 | | - |
133 | 55 | context "with background_worker enabled (default)" do |
134 | 56 | before do |
135 | 57 | Sentry.background_worker = Sentry::BackgroundWorker.new(configuration) |
|
303 | 225 | let(:event) { subject.event_from_message(message) } |
304 | 226 |
|
305 | 227 | describe "#capture_event" do |
306 | | - around do |example| |
307 | | - prior_async = configuration.async |
308 | | - example.run |
309 | | - configuration.async = prior_async |
310 | | - end |
311 | | - |
312 | 228 | context "when scope.apply_to_event returns nil" do |
313 | 229 | before do |
314 | 230 | scope.add_event_processor do |event, hint| |
|
400 | 316 | expect(string_io.string).to match(/Unreported Event: Test message/) |
401 | 317 | end |
402 | 318 | end |
403 | | - |
404 | | - context "when config.async causes error" do |
405 | | - before do |
406 | | - expect(subject).to receive(:send_event) |
407 | | - end |
408 | | - |
409 | | - it "swallows Redis related error and send the event synchronizely" do |
410 | | - configuration.async = -> (_, _) { raise Redis::ConnectionError } |
411 | | - |
412 | | - subject.capture_event(event, scope) |
413 | | - |
414 | | - expect(string_io.string).to match(/Async event sending failed: Redis::ConnectionError/) |
415 | | - end |
416 | | - |
417 | | - it "swallows and logs the exception" do |
418 | | - configuration.async = -> (_, _) { raise TypeError } |
419 | | - |
420 | | - subject.capture_event(event, scope) |
421 | | - |
422 | | - expect(string_io.string).to match(/Async event sending failed: TypeError/) |
423 | | - end |
424 | | - end |
425 | 319 | end |
426 | 320 |
|
427 | 321 | describe "#send_event" do |
|
0 commit comments