Skip to content

Commit

Permalink
Merge pull request #3708 from DataDog/ivoanjo/use-fiddle-to-simulate-…
Browse files Browse the repository at this point in the history
…crash

[NO-TICKET] Minor: Use fiddle to simulate crash in spec
  • Loading branch information
ivoanjo authored Jun 12, 2024
2 parents b047a30 + ac8e06f commit c0ca274
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions spec/datadog/profiling/crashtracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'datadog/profiling/crashtracker'

require 'webrick'
require 'fiddle'

RSpec.describe Datadog::Profiling::Crashtracker do
before do
Expand Down Expand Up @@ -175,33 +176,39 @@

let(:exporter_configuration) { [:agent, "http://#{hostname}:#{port}"] }

it 'reports crashes via http' do
fork_expectations = proc do |status:, stdout:, stderr:|
expect(Signal.signame(status.termsig)).to eq('SEGV').or eq('ABRT')
expect(stderr).to include('[BUG] Segmentation fault')
end
[:fiddle, :signal].each do |trigger|
it "reports crashes via http when app crashes with #{trigger}" do
fork_expectations = proc do |status:, stdout:, stderr:|
expect(Signal.signame(status.termsig)).to eq('SEGV').or eq('ABRT')
expect(stderr).to include('[BUG] Segmentation fault')
end

expect_in_fork(fork_expectations: fork_expectations) do
crashtracker.start
expect_in_fork(fork_expectations: fork_expectations) do
crashtracker.start

Process.kill('SEGV', Process.pid)
end
if trigger == :fiddle
Fiddle.free(42)
else
Process.kill('SEGV', Process.pid)
end
end

crash_report = JSON.parse(request.body, symbolize_names: true)[:payload].first
crash_report = JSON.parse(request.body, symbolize_names: true)[:payload].first

expect(crash_report[:stack_trace]).to_not be_empty
expect(crash_report[:tags]).to include('signum:11', 'signame:SIGSEGV')
expect(crash_report[:stack_trace]).to_not be_empty
expect(crash_report[:tags]).to include('signum:11', 'signame:SIGSEGV')

crash_report_message = JSON.parse(crash_report[:message], symbolize_names: true)
crash_report_message = JSON.parse(crash_report[:message], symbolize_names: true)

expect(crash_report_message[:metadata]).to include(
profiling_library_name: 'dd-trace-rb',
profiling_library_version: Datadog::VERSION::STRING,
family: 'ruby',
tags: ['tag1:value1', 'tag2:value2'],
)
expect(crash_report_message[:files][:'/proc/self/maps']).to_not be_empty
expect(crash_report_message[:os_info]).to_not be_empty
expect(crash_report_message[:metadata]).to include(
profiling_library_name: 'dd-trace-rb',
profiling_library_version: Datadog::VERSION::STRING,
family: 'ruby',
tags: ['tag1:value1', 'tag2:value2'],
)
expect(crash_report_message[:files][:'/proc/self/maps']).to_not be_empty
expect(crash_report_message[:os_info]).to_not be_empty
end
end
end
end

0 comments on commit c0ca274

Please sign in to comment.