Sha256: f5743df59a03de562672320f1cc6a0b1aa044d2a8b5ad55fb5d23919528b1884

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require File.expand_path('../rails_test_helper', File.dirname(__FILE__))

class RailsFullStackTest < ActionDispatch::IntegrationTest
  def setup
    Coverband.configuration.store.clear!
  end

  test 'this is how we do it' do
    get '/dummy/show'
    assert_response :success
    assert_equal 'I am no dummy', response.body
    assert_equal [1, 1, 1, nil, nil], Coverband.configuration.store.coverage["#{Rails.root}/app/controllers/dummy_controller.rb"]
  end

  ###
  # Please keep this test starting on line 22
  # as we run it in single test mode via the benchmarks.
  # Add new tests below this test
  ###
  test 'memory usage' do
    return unless ENV['COVERBAND_MEMORY_TEST']
    # we don't want this to run during our standard test suite
    # as the below profiler changes the runtime
    # and shold only be included for isolated processes
    begin
      require 'memory_profiler'

      # warmup
      3.times do
        get '/dummy/show'
        assert_response :success
        Coverband::Collectors::Coverage.instance.report_coverage(true)
      end

      previous_out = $stdout
      capture = StringIO.new
      $stdout = capture

      MemoryProfiler.report do
        15.times do
          get '/dummy/show'
          assert_response :success
          Coverband::Collectors::Coverage.instance.report_coverage(true)
          # this is expected to retain memory across requests
          # clear it to remove the false positive from test
          Coverband::Collectors::Coverage.instance.send(:add_previous_results, nil)
        end
      end.pretty_print
      data = $stdout.string
      $stdout = previous_out
      if data.match(/retained objects by gem(.*)retained objects by file/m)[0]&.match(/coverband/)
        raise 'leaking memory!!!'
      end
    ensure
      $stdout = previous_out
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coverband-4.0.1.alpha test/unit/rails_full_stack_test.rb
coverband-4.0.0 test/unit/rails_full_stack_test.rb
coverband-4.0.0.alpha test/unit/rails_full_stack_test.rb