Skip to content

Commit

Permalink
wip - move profiler helper module to support
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Aug 22, 2024
1 parent ff963f5 commit b45c7f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
33 changes: 10 additions & 23 deletions sentry-ruby/spec/sentry/vernier/profiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sentry-ruby/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions sentry-ruby/spec/support/profiler.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b45c7f3

Please sign in to comment.