<commit_before>require 'bundler/setup'

require 'activejob-google_cloud_pubsub'
require 'timeout'

RSpec.configure do |config|
  # Enable flags like --only-failures and --next-failure
  config.example_status_persistence_file_path = '.rspec_status'

  config.expect_with :rspec do |rspec|
    rspec.syntax = :expect
  end

  config.around :each, emulator: true do |example|
    run_pubsub_emulator do |emulator_host|
      @emulator_host = emulator_host

      example.run
    end
  end

  private

  def run_pubsub_emulator(&block)
    pipe = IO.popen('gcloud beta emulators pubsub start', err: %i(child out), pgroup: true)

    Timeout.timeout 10 do
      pipe.each do |line|
        break if line.include?('INFO: Server started')

        raise line if line.include?('Exception in thread')
      end
    end

    host = `gcloud beta emulators pubsub env-init`.match(/^export PUBSUB_EMULATOR_HOST=(\S+)$/).values_at(1).first

    block.call host
  ensure
    return unless pipe

    begin
      Process.kill :TERM, -Process.getpgid(pipe.pid)
      Process.wait pipe.pid
    rescue Errno::ESRCH, Errno::ECHILD
      # already terminated
    end
  end
end<commit_msg>Return in ensure clause causes unexpected results<commit_after>require 'bundler/setup'

require 'activejob-google_cloud_pubsub'
require 'timeout'

RSpec.configure do |config|
  # Enable flags like --only-failures and --next-failure
  config.example_status_persistence_file_path = '.rspec_status'

  config.expect_with :rspec do |rspec|
    rspec.syntax = :expect
  end

  config.around :each, emulator: true do |example|
    run_pubsub_emulator do |emulator_host|
      @emulator_host = emulator_host

      example.run
    end
  end

  private

  def run_pubsub_emulator(&block)
    pipe = IO.popen('gcloud beta emulators pubsub start', err: %i(child out), pgroup: true)

    begin
      Timeout.timeout 10 do
        pipe.each do |line|
          break if line.include?('INFO: Server started')

          raise line if line.include?('Exception in thread')
        end
      end

      host = `gcloud beta emulators pubsub env-init`.match(/^export PUBSUB_EMULATOR_HOST=(\S+)$/).values_at(1).first

      block.call host
    ensure
      begin
        Process.kill :TERM, -Process.getpgid(pipe.pid)
        Process.wait pipe.pid
      rescue Errno::ESRCH, Errno::ECHILD
        # already terminated
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09531772575250837, 'fraction_numerical': 0.002508361204013378, 'mean_word_length': 3.0490693739424706, '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': '4637444', 'n_tokens_mistral': 793, 'n_tokens_neox': 761, 'n_words': 200}