Skip to content

Commit

Permalink
Merge pull request #224 from DataDog/anmarchenko/fix_datadog_cov_crashes
Browse files Browse the repository at this point in the history
[SDTEST-755] attempt to fix datadog_cov crash when doing allocation profiling
  • Loading branch information
anmarchenko authored Aug 28, 2024
2 parents 1ae8c0b + 58452e4 commit 12ed0e8
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/datadog_cov/datadog_cov.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static int process_instantiated_klass(st_data_t key, st_data_t _value, st_data_t
}

VALUE filename = RARRAY_AREF(source_location, 0);
if (filename == Qnil)
if (filename == Qnil || !RB_TYPE_P(filename, T_STRING))
{
return ST_CONTINUE;
}
Expand Down
2 changes: 2 additions & 0 deletions spec/ddcov/app/model/my_model_❤️.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class MyModel❤️
end
88 changes: 88 additions & 0 deletions spec/ddcov/ddcov_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "datadog_cov.#{RUBY_VERSION}_#{RUBY_PLATFORM}"

require_relative "app/model/my_model"
require_relative "app/model/my_model_❤️"
require_relative "app/model/my_struct"
require_relative "calculator/calculator"
require_relative "calculator/code_with_❤️"
Expand Down Expand Up @@ -357,6 +358,93 @@ def thread_local_cov
expect(coverage.keys).to include(absolute_path("app/model/my_struct.rb"))
end

it "tracks coverage for objects defined with emojis" do
subject.start

MyModel❤️.new

coverage = subject.stop
expect(coverage.size).to eq(1)
expect(coverage.keys).to include(absolute_path("app/model/my_model_❤️.rb"))
end

context "Object.const_source_location is redefined in tests" do
context "returns invalid values" do
before do
allow(Object).to receive(:const_source_location).and_return([-1, -1])
end

it "does not break" do
subject.start

User.new("john doe", "johndoe@mail.test")

coverage = subject.stop
expect(coverage.size).to eq(0)
end
end

context "returns nil" do
before do
allow(Object).to receive(:const_source_location).and_return(nil)
end

it "does not break" do
subject.start

User.new("john doe", "johndoe@mail.test")

coverage = subject.stop
expect(coverage.size).to eq(0)
end
end

context "returns empty array" do
before do
allow(Object).to receive(:const_source_location).and_return([])
end

it "does not break" do
subject.start

User.new("john doe", "johndoe@mail.test")

coverage = subject.stop
expect(coverage.size).to eq(0)
end
end

context "returns empty nested array" do
before do
allow(Object).to receive(:const_source_location).and_return([[]])
end

it "does not break" do
subject.start

User.new("john doe", "johndoe@mail.test")

coverage = subject.stop
expect(coverage.size).to eq(0)
end
end

context "raises" do
before do
allow(Object).to receive(:const_source_location).and_raise(StandardError)
end

it "does not break" do
subject.start

User.new("john doe", "johndoe@mail.test")

coverage = subject.stop
expect(coverage.size).to eq(0)
end
end
end

context "Data structs available since Ruby 3.2" do
before do
if RUBY_VERSION < "3.2"
Expand Down

0 comments on commit 12ed0e8

Please sign in to comment.