Sha256: 7063b298e619cc1987d9dbaf049e1cb9e3b2dc42d0b57c6548b21b91a5168132

Contents?: true

Size: 1.69 KB

Versions: 47

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

require File.expand_path("../../test_helper", File.dirname(__FILE__))

class BackgroundTest < Minitest::Test
  class ThreadDouble < Struct.new(:alive)
    def exit
    end

    def alive?
      alive
    end
  end

  def setup
    Coverband.configuration.reset
    super
    Coverband.configure do |config|
      config.background_reporting_sleep_seconds = 60
      Coverband.configuration.reporting_wiggle = 0
    end
  end

  def test_start
    sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds.to_i
    Thread.expects(:new).yields.returns(ThreadDouble.new(true))
    Coverband::Background.expects(:loop).yields
    Coverband::Background.expects(:sleep).with(sleep_seconds)
    Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
    2.times { Coverband::Background.start }
  end

  def test_start_with_wiggle
    sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds.to_i
    Thread.expects(:new).yields.returns(ThreadDouble.new(true))
    Coverband::Background.expects(:loop).yields
    Coverband::Background.expects(:sleep).with(sleep_seconds + 5)
    Coverband::Background.expects(:rand).with(10).returns(5)
    Coverband.configuration.reporting_wiggle = 10
    Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
    2.times { Coverband::Background.start }
  end

  def test_start_dead_thread
    Thread.expects(:new).yields.returns(ThreadDouble.new(false)).twice
    Coverband::Background.expects(:loop).yields.twice
    Coverband::Background.expects(:sleep).with(60).twice
    Coverband::Collectors::Coverage.instance.expects(:report_coverage).twice
    2.times { Coverband::Background.start }
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
coverband-6.1.4 test/coverband/integrations/background_test.rb
coverband-6.1.3 test/coverband/integrations/background_test.rb
coverband-6.1.2 test/coverband/integrations/background_test.rb
coverband-6.1.2.rc.1 test/coverband/integrations/background_test.rb
coverband-6.1.1 test/coverband/integrations/background_test.rb
coverband-6.1.0 test/coverband/integrations/background_test.rb
coverband-6.0.3.rc.4 test/coverband/integrations/background_test.rb
coverband-6.0.3.rc.3 test/coverband/integrations/background_test.rb
coverband-6.0.3.rc.2 test/coverband/integrations/background_test.rb
coverband-6.0.3.rc.1 test/coverband/integrations/background_test.rb
coverband-6.0.2 test/coverband/integrations/background_test.rb
coverband-6.0.1 test/coverband/integrations/background_test.rb
coverband-6.0.1.rc.1 test/coverband/integrations/background_test.rb
coverband-6.0.0 test/coverband/integrations/background_test.rb
coverband-5.2.6.rc.6 test/coverband/integrations/background_test.rb
coverband-5.2.3.2 test/coverband/integrations/background_test.rb
coverband-5.2.6.rc.5 test/coverband/integrations/background_test.rb
coverband-5.2.3.1 test/coverband/integrations/background_test.rb
coverband-5.2.6.rc.4 test/coverband/integrations/background_test.rb
coverband-5.2.6.rc.3 test/coverband/integrations/background_test.rb