<commit_before>require 'spec_helper'
require_relative 'global_thread_pool_shared'

share_examples_for :thread_pool do

  after(:each) do
    subject.kill
    sleep(0.1)
  end

  it_should_behave_like :global_thread_pool

  context '#scheduled_task_count' do

    it 'returns zero on creation' do
      subject.scheduled_task_count.should eq 0
    end

    it 'returns the approximate number of tasks that have been post thus far' do
      10.times{ subject.post{ nil } }
      sleep(0.1)
      subject.scheduled_task_count.should eq 10
    end

    it 'returns the approximate number of tasks that were post' do
      10.times{ subject.post{ nil } }
      sleep(0.1)
      subject.shutdown
      subject.wait_for_termination(1)
      subject.scheduled_task_count.should eq 10
    end
  end

  context '#completed_task_count' do

    it 'returns zero on creation' do
      subject.completed_task_count.should eq 0
    end

    it 'returns the approximate number of tasks that have been completed thus far' do
      5.times{ subject.post{ raise StandardError } }
      5.times{ subject.post{ nil } }
      sleep(0.1)
      subject.completed_task_count.should eq 10
    end

    it 'returns the approximate number of tasks that were completed' do
      5.times{ subject.post{ raise StandardError } }
      5.times{ subject.post{ nil } }
      sleep(0.1)
      subject.shutdown
      subject.wait_for_termination(1)
      subject.completed_task_count.should eq 10
    end
  end

  context '#length' do

    it 'returns zero on creation' do
      subject.length.should eq 0
    end

    it 'returns a non-zero while shutting down' do
      5.times{ subject.post{ sleep(0.1) } }<commit_msg>Minor thread pool spec refactoring.<commit_after>require 'spec_helper'
require_relative 'global_thread_pool_shared'

share_examples_for :thread_pool do

  after(:each) do
    subject.kill
    sleep(0.1)
  end

  it_should_behave_like :global_thread_pool

  context '#scheduled_task_count' do

    it 'returns zero on creation' do
      subject.scheduled_task_count.should eq 0
    end

    it 'returns the approximate number of tasks that have been post thus far' do
      10.times{ subject.post{ nil } }
      sleep(0.1)
      subject.scheduled_task_count.should > 0
    end

    it 'returns the approximate number of tasks that were post' do
      10.times{ subject.post{ nil } }
      sleep(0.1)
      subject.shutdown
      subject.wait_for_termination(1)
      subject.scheduled_task_count.should > 0
    end
  end

  context '#completed_task_count' do

    it 'returns zero on creation' do
      subject.completed_task_count.should eq 0
    end

    it 'returns the approximate number of tasks that have been completed thus far' do
      5.times{ subject.post{ raise StandardError } }
      5.times{ subject.post{ nil } }
      sleep(0.1)
      subject.completed_task_count.should > 0
    end

    it 'returns the approximate number of tasks that were completed' do
      5.times{ subject.post{ raise StandardError } }
      5.times{ subject.post{ nil } }
      sleep(0.1)
      subject.shutdown
      subject.wait_for_termination(1)
      subject.completed_task_count.should > 0
    end
  end

  context '#length' do

    it 'returns zero on creation' do
      subject.length.should eq 0
    end

    it 'returns a non-zero while shutting down' do
      5.times{ subject.post{ sleep(0.1) } }
{'fraction_non_alphanumeric': 0.07303370786516854, 'fraction_numerical': 0.018923713778829097, 'mean_word_length': 2.7926008968609866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2749042', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1013, 'n_words': 320}