Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO-TICKET] Minor: Use fiddle to simulate crash in spec #3708

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading