From b45c7f35779185a760b8264bc9db7df694867d22 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Thu, 22 Aug 2024 07:18:55 +0000 Subject: [PATCH] wip - move profiler helper module to support --- .../spec/sentry/vernier/profiler_spec.rb | 33 ++++++------------- sentry-ruby/spec/spec_helper.rb | 2 ++ sentry-ruby/spec/support/profiler.rb | 14 ++++++++ 3 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 sentry-ruby/spec/support/profiler.rb diff --git a/sentry-ruby/spec/sentry/vernier/profiler_spec.rb b/sentry-ruby/spec/sentry/vernier/profiler_spec.rb index 917f6aec3..356c5ec66 100644 --- a/sentry-ruby/spec/sentry/vernier/profiler_spec.rb +++ b/sentry-ruby/spec/sentry/vernier/profiler_spec.rb @@ -14,19 +14,6 @@ end end - module Bar - module Foo - def self.foo - 1e6.to_i.times { 2**2 } - end - end - - def self.bar - Foo.foo - sleep 0.1 - end - end - describe '#start' do context 'without sampling decision' do it 'does not start Vernier' do @@ -111,7 +98,7 @@ def self.bar context 'with single-thread profiled code' do before do profiler.start - Bar.bar + ProfilerTest::Bar.bar profiler.stop end @@ -121,11 +108,11 @@ def self.bar foo_frame = frames.find { |f| f[:function] =~ /foo/ } expect(foo_frame[:function]).to eq('Foo.foo') - expect(foo_frame[:module]).to eq('Bar') + expect(foo_frame[:module]).to eq('ProfilerTest::Bar') expect(foo_frame[:in_app]).to eq(true) - expect(foo_frame[:lineno]).to eq(16) - expect(foo_frame[:filename]).to eq('spec/sentry/vernier/profiler_spec.rb') - expect(foo_frame[:abs_path]).to include('sentry-ruby/sentry-ruby/spec/sentry/vernier/profiler_spec.rb') + expect(foo_frame[:lineno]).to eq(4) + expect(foo_frame[:filename]).to eq('spec/support/profiler.rb') + expect(foo_frame[:abs_path]).to include('sentry-ruby/sentry-ruby/spec/support/profiler.rb') end it 'has correct stacks' do @@ -173,7 +160,7 @@ def self.bar Thread.new do Thread.current.name = "thread-bar-#{i}" - Bar.bar + ProfilerTest::Bar.bar end end.map(&:join) @@ -201,11 +188,11 @@ def self.bar foo_frame = frames.find { |f| f[:function] =~ /foo/ } expect(foo_frame[:function]).to eq('Foo.foo') - expect(foo_frame[:module]).to eq('Bar') + expect(foo_frame[:module]).to eq('ProfilerTest::Bar') expect(foo_frame[:in_app]).to eq(true) - expect(foo_frame[:lineno]).to eq(16) - expect(foo_frame[:filename]).to eq('spec/sentry/vernier/profiler_spec.rb') - expect(foo_frame[:abs_path]).to include('sentry-ruby/sentry-ruby/spec/sentry/vernier/profiler_spec.rb') + expect(foo_frame[:lineno]).to eq(4) + expect(foo_frame[:filename]).to eq('spec/support/profiler.rb') + expect(foo_frame[:abs_path]).to include('sentry-ruby/sentry-ruby/spec/support/profiler.rb') end it 'has correct stacks' do diff --git a/sentry-ruby/spec/spec_helper.rb b/sentry-ruby/spec/spec_helper.rb index 611205163..b31b63954 100644 --- a/sentry-ruby/spec/spec_helper.rb +++ b/sentry-ruby/spec/spec_helper.rb @@ -23,6 +23,8 @@ require "sentry-ruby" require "sentry/test_helper" +Dir[Pathname(__dir__).join("support/**/*.rb")].sort.each { |f| require f } + RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = ".rspec_status" diff --git a/sentry-ruby/spec/support/profiler.rb b/sentry-ruby/spec/support/profiler.rb new file mode 100644 index 000000000..7f048b8a5 --- /dev/null +++ b/sentry-ruby/spec/support/profiler.rb @@ -0,0 +1,14 @@ +module ProfilerTest + module Bar + module Foo + def self.foo + 1e6.to_i.times { 2**2 } + end + end + + def self.bar + Foo.foo + sleep 0.1 + end + end +end