Skip to content

Commit

Permalink
Merge pull request #41 from DataDog/ivoanjo/prof-9963-dir-interruptio…
Browse files Browse the repository at this point in the history
…n-testing-ruby-spec

[PROF-9963] Add integration testing for Ruby dir interruption monkey patch
  • Loading branch information
ivoanjo authored Jul 2, 2024
2 parents 121708a + af8650b commit bf170a6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
27 changes: 27 additions & 0 deletions scenarios/ruby_dir_interruption_patch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ruby:3.3

ENV DD_PROFILING_ENABLED true
ENV DD_PROFILING_DIR_INTERRUPTION_WORKAROUND_ENABLED true

COPY ./scenarios/ruby_dir_interruption_patch/*.rb /app/
RUN chmod 755 /app/*

WORKDIR /app
RUN bundle install

RUN wget https://github.com/ruby/spec/archive/refs/heads/master.zip -O spec-master.zip
RUN wget https://github.com/ruby/mspec/archive/refs/heads/master.zip -O mspec-master.zip
RUN unzip spec-master.zip
RUN unzip mspec-master.zip

# Since we aggressively drop permissions when running, we need to manually create a folder for rubyspec to use
RUN mkdir /app/rubyspec_temp
RUN chmod 777 /app/rubyspec_temp

# Needed by one of the ruby specs (which is testing access to home)
# @ivoanjo: Locally I get uid 1000, and in CI I'm seeing 1001. I am not sure why they differ, or if any other uids
# can show up. But, if we're missing this for an user, it'll cause the tests to fail so we definitely won't miss it.
RUN useradd -u 1000 -ms /bin/bash someuser
RUN useradd -u 1001 -ms /bin/bash someuser2

CMD bundle exec ddprofrb exec ruby mspec-master/bin/mspec-run --config mspec_config.rb spec-master/core/dir/
5 changes: 5 additions & 0 deletions scenarios/ruby_dir_interruption_patch/expected_profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test_name": "ruby_dir_interruption_patch",
"stacks": [],
"note": "This test has no stacks, as it's not expected to emit profiles -- we're only testing that the mspec run is successful even when the profiler monkey patches are available."
}
3 changes: 3 additions & 0 deletions scenarios/ruby_dir_interruption_patch/gems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'datadog', git: 'https://github.com/datadog/dd-trace-rb.git', branch: 'master'
8 changes: 8 additions & 0 deletions scenarios/ruby_dir_interruption_patch/mspec_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Datadog::Profiling.wait_until_running

if Dir.ancestors.first == Datadog::Profiling::Ext::DirInstanceMonkeyPatches &&
Dir.singleton_class.ancestors.first == Datadog::Profiling::Ext::DirClassMonkeyPatches
puts "Dir interruption patch is present!"
else
raise 'Dir interruption patch is not present!'
end

0 comments on commit bf170a6

Please sign in to comment.