<commit_before>require 'spec_helper'

describe "Managing the Worker pool" do
  it "should log mode changes" do
    Que.mode = :off
    $logger.messages.should == ["[Que] Set mode to :off"]
  end

  describe "Que.mode = :sync" do
    it "should make jobs run in the same thread as they are queued" do
      Que.mode = :sync

      ArgsJob.queue(5, :testing => "synchronous").should be_an_instance_of ArgsJob
      $passed_args.should == [5, {'testing' => "synchronous"}]
      DB[:que_jobs].count.should be 0

      $logger.messages.length.should be 2
      $logger.messages[0].should == "[Que] Set mode to :sync"
      $logger.messages[1].should =~ /\A\[Que\] Worked job in/
    end

    it "should not affect jobs that are queued with specific run_ats" do
      Que.mode = :sync

      ArgsJob.queue(5, :testing => "synchronous", :run_at => Time.now + 60)
      DB[:que_jobs].select_map(:job_class).should == ["ArgsJob"]
    end
  end

  describe "Que.mode = :async" do
    it "should spin up 4 workers" do
      Que.mode = :async
      workers = Que::Worker.workers
      workers.count.should be 4
      sleep_until { workers.all?(&:sleeping?) }
    end<commit_msg>Spec that Que.stop! doesn't blow up when there are no workers.<commit_after>require 'spec_helper'

describe "Managing the Worker pool" do
  it "should log mode changes" do
    Que.mode = :off
    $logger.messages.should == ["[Que] Set mode to :off"]
  end

  it "Que.stop! should do nothing if there are no workers running" do
    Que.stop!
  end

  describe "Que.mode = :sync" do
    it "should make jobs run in the same thread as they are queued" do
      Que.mode = :sync

      ArgsJob.queue(5, :testing => "synchronous").should be_an_instance_of ArgsJob
      $passed_args.should == [5, {'testing' => "synchronous"}]
      DB[:que_jobs].count.should be 0

      $logger.messages.length.should be 2
      $logger.messages[0].should == "[Que] Set mode to :sync"
      $logger.messages[1].should =~ /\A\[Que\] Worked job in/
    end

    it "should not affect jobs that are queued with specific run_ats" do
      Que.mode = :sync

      ArgsJob.queue(5, :testing => "synchronous", :run_at => Time.now + 60)
      DB[:que_jobs].select_map(:job_class).should == ["ArgsJob"]
    end

    it "then Que.stop! should do nothing" do
      Que.stop!
    end
  end

  describe "Que.mode = :async" do
    it "should spin up 4 workers" do
      Que.mode = :async
      workers = Que::Worker.workers
      workers.count.should be 4
      sleep_until { workers.all?(&:sleeping?) }
    end
{'fraction_non_alphanumeric': 0.12657232704402516, 'fraction_numerical': 0.008647798742138365, 'mean_word_length': 2.8444108761329305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5249710', 'n_tokens_mistral': 853, 'n_tokens_neox': 817, 'n_words': 262}