From a424d4f40af364079659ffe701cab61ebb6442bb Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Fri, 22 Oct 2021 10:56:47 -0400 Subject: [PATCH 1/4] Upgrade rake dev dependency for ruby 3 compatibility --- stack_frames.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack_frames.gemspec b/stack_frames.gemspec index 742a294..fa864dd 100644 --- a/stack_frames.gemspec +++ b/stack_frames.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_development_dependency "bundler" - spec.add_development_dependency "rake", "~> 10.0" + spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency 'rake-compiler', '~> 1.0' spec.add_development_dependency "minitest", "~> 5.0" spec.add_development_dependency "stackprof", "~> 0.2.13" From 03f834de7e37fd149fd855e422578f0d149ac64d Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Fri, 22 Oct 2021 14:13:02 -0400 Subject: [PATCH 2/4] Fix an allocation count test assertion failure on ruby 3 Allocations started being done more lazily, so they wouldn't be done unnecessarily, but they are memoized. So we just need to run the block once before measuring for the test to ignore the memiozed allocations. --- test/stack_frames/buffer_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/stack_frames/buffer_test.rb b/test/stack_frames/buffer_test.rb index 2b4c967..7fc2e5e 100644 --- a/test/stack_frames/buffer_test.rb +++ b/test/stack_frames/buffer_test.rb @@ -36,13 +36,15 @@ def test_no_object_allocations got_path = nil got_lineno = nil got_method_name = nil - num_allocations = count_allocations do + instrumented_code = lambda do buffer.capture frame = buffer[1] got_path = frame.path got_lineno = frame.lineno got_method_name = frame.method_name end + count_allocations(&instrumented_code) # allow lazy memoized allocations + num_allocations = count_allocations(&instrumented_code) assert_equal(0, num_allocations) assert_equal('count_allocations', got_method_name) assert_equal(method(:count_allocations).source_location[1] + 1, got_lineno) From 0b10c2bff866df788ed231ce46ad6ddd322e2aef Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Fri, 22 Oct 2021 16:14:45 -0400 Subject: [PATCH 3/4] Fix tests for ruby 3, which no longer skips C stack frames --- test/stack_frames/buffer_test.rb | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/test/stack_frames/buffer_test.rb b/test/stack_frames/buffer_test.rb index 7fc2e5e..1b65b37 100644 --- a/test/stack_frames/buffer_test.rb +++ b/test/stack_frames/buffer_test.rb @@ -17,11 +17,11 @@ def test_new_with_invalid_capacity end def test_capture - buffer = StackFrames::Buffer.new(1) + buffer = StackFrames::Buffer.new(2) expected_line = __LINE__ + 1 frames_length = buffer.capture - assert_equal(1, frames_length) - frame = buffer[0] + assert_equal(2, frames_length) + frame = buffer[skipping_c_frames? ? 0 : 1] assert_equal('test_capture', frame.method_name) assert_equal(true, frame.method_name.frozen?) assert_equal(__FILE__, frame.path) @@ -36,9 +36,10 @@ def test_no_object_allocations got_path = nil got_lineno = nil got_method_name = nil + frame_index = skipping_c_frames? ? 1 : 3 instrumented_code = lambda do buffer.capture - frame = buffer[1] + frame = buffer[frame_index] got_path = frame.path got_lineno = frame.lineno got_method_name = frame.method_name @@ -57,12 +58,19 @@ def test_index_lookup frame1 do buffer.capture end + skipped = 0 [ - ["test_index_lookup", capture_lineno], - ["frame1", method(:frame1).source_location[1] + 1], - ["test_index_lookup", capture_lineno - 1], - ].each_with_index do |(method_name, lineno), i| - frame = buffer[i] + [:c, "capture", 0], + [:ruby, "test_index_lookup", capture_lineno], + [:ruby, "frame1", method(:frame1).source_location[1] + 1], + [:ruby, "test_index_lookup", capture_lineno - 1], + ].each_with_index do |(lang, method_name, lineno), i| + if skipping_c_frames? && lang == :c + skipped += 1 + next + end + buffer_idx = i - skipped + frame = buffer[buffer_idx] assert_equal(method_name, frame.method_name, "frame #{i}") assert_equal(lineno, frame.lineno, "frame #{i}") end @@ -109,6 +117,10 @@ def test_gc_stress private + def skipping_c_frames? + Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3") + end + def frame1 yield end From 872c1178cf00eb4536ba21c1251e26bb7b639dd5 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Fri, 22 Oct 2021 11:00:08 -0400 Subject: [PATCH 4/4] Use Github Actions instead of no longer worker travis-ci.org --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ .travis.yml | 8 -------- 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f80c10c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: Tests + +on: + push + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: [ + '2.6', # minimum supported + '2.7', # latest passing tests + ] + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: bundle exec rake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 279ff7f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -sudo: false -language: ruby -cache: bundler -rvm: - - 2.4.9 # minimum supported - - 2.7.0 # latest released -before_install: gem install bundler -v 1.17.3