<commit_before># frozen_string_literal: true

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

class ResqueWorkerTest < Minitest::Test
  def enqueue_and_run_job
    Resque.enqueue(TestResqueJob)
    queue = ENV['QUEUE'] ='resque_coverband'
    worker = Resque::Worker.new
    worker.startup
    worker.work_one_job
  end

  def setup
    super
    Coverband.configure do |config|
      config.background_reporting_enabled = true
    end
    Coverband.start
    redis = Coverband.configuration.store.send(:redis)
    Resque.redis = redis
  end

  test 'resque job coverage' do
    resque_job_file = File.expand_path('./test_resque_job.rb', File.dirname(__FILE__))
    require resque_job_file

    #report after loading the file in parent process
    Coverband::Collectors::Coverage.instance.report_coverage(true)
    
    enqueue_and_run_job

    assert !Coverband::Background.running?

    puts "assert_equal 1, Coverband.configuration.store.coverage['#{resque_job_file}']['data'][4]"
    assert_equal 1, Coverband.configuration.store.coverage[resque_job_file]['data'][4]
  end
end

<commit_msg>Remove extra report call in resque test<commit_after># frozen_string_literal: true

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

class ResqueWorkerTest < Minitest::Test
  def enqueue_and_run_job
    Resque.enqueue(TestResqueJob)
    queue = ENV['QUEUE'] ='resque_coverband'
    worker = Resque::Worker.new
    worker.startup
    worker.work_one_job
  end

  def setup
    super
    Coverband.configure do |config|
      config.background_reporting_enabled = true
    end
    Coverband.start
    redis = Coverband.configuration.store.send(:redis)
    Resque.redis = redis
  end

  test 'resque job coverage' do
    resque_job_file = File.expand_path('./test_resque_job.rb', File.dirname(__FILE__))
    require resque_job_file

    enqueue_and_run_job

    assert !Coverband::Background.running?

    assert_equal 1, Coverband.configuration.store.coverage[resque_job_file]['data'][4]
  end
end


{'fraction_non_alphanumeric': 0.09655172413793103, 'fraction_numerical': 0.002955665024630542, 'mean_word_length': 4.1811224489795915, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5301966', 'n_tokens_mistral': 678, 'n_tokens_neox': 662, 'n_words': 125}