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

[SDTEST-755] attempt to fix datadog_cov crash when doing allocation profiling #224

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
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
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", "[email protected]")

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", "[email protected]")

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", "[email protected]")

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", "[email protected]")

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", "[email protected]")

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
Loading