<commit_before>require 'rails_helper'

describe RepositoryMaintenanceStatWorker do
  let!(:repository) { create(:repository) }

  it "should use the medium priority queue by default" do
    is_expected.to be_processed_in :repo_maintenance_stat
  end

  it "should be unique" do
    is_expected.to be_unique
  end

  it "should gather stats for the repository" do
    expect(GatherRepositoryMaintenanceStats).to receive(:gather_stats).with(repository)
    subject.perform(repository.id)
  end
end<commit_msg>added more tests for queue priority<commit_after>require 'rails_helper'

describe RepositoryMaintenanceStatWorker do
  let!(:repository) { create(:repository) }

  before do
    Sidekiq::Worker.clear_all
  end

  it "should use the medium priority queue by default" do
    is_expected.to be_processed_in :repo_maintenance_stat
  end

  it "should be unique" do
    is_expected.to be_unique
  end

  it "should gather stats for the repository" do
    expect(GatherRepositoryMaintenanceStats).to receive(:gather_stats).with(repository)
    subject.perform(repository.id)
  end

  it "should queue jobs in high priority" do
    # need to disable the queue locking for tests to work with Sidekiq mocking
    SidekiqUniqueJobs.use_config(enabled: false) do
      expect(Sidekiq::Queues["repo_maintenance_stat_high"].size).to eql 0
      expect(RepositoryMaintenanceStatWorker.jobs.size).to eql 0

      RepositoryMaintenanceStatWorker.queue(repository.id, priority: :high)
    
      expect(RepositoryMaintenanceStatWorker.jobs.size).to eql 1
      expect(Sidekiq::Queues["repo_maintenance_stat_high"].size).to eql 1
    end
  end

  it "should queue jobs in low priority" do
    # need to disable the queue locking for tests to work with Sidekiq mocking
    SidekiqUniqueJobs.use_config(enabled: false) do
      expect(Sidekiq::Queues["repo_maintenance_stat_low"].size).to eql 0
      expect(RepositoryMaintenanceStatWorker.jobs.size).to eql 0

      RepositoryMaintenanceStatWorker.queue(repository.id, priority: :low)
    
      expect(RepositoryMaintenanceStatWorker.jobs.size).to eql 1
      expect(Sidekiq::Queues["repo_maintenance_stat_low"].size).to eql 1
    end
  end
end
{'fraction_non_alphanumeric': 0.07466788822721027, 'fraction_numerical': 0.0036646816307833257, 'mean_word_length': 4.432835820895522, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4936175', 'n_tokens_mistral': 673, 'n_tokens_neox': 639, 'n_words': 174}