<commit_before>require "fileutils"

module SeleniumDriverSetup
  # WebDriver uses port 7054 (the "locking port") as a mutex to ensure
  # that we don't launch two Firefox instances at the same time. Each
  # new instance you create will wait for the mutex before starting
  # the browser, then release it as soon as the browser is open.
  #
  # The default port mutex wait timeout is 45 seconds.
  # Bump it to 90 seconds as a stopgap for the recent flood of:
  # `unable to bind to locking port 7054 within 45 seconds`
  #
  # TODO: Investigate why it's taking so long to launch Firefox, or
  #       what process is hogging port 7054.
  Selenium::WebDriver::Firefox::Launcher::SOCKET_LOCK_TIMEOUT = 90

  # Number of recent specs to show in failure pages
  RECENT_SPEC_RUNS_LIMIT = 500
  # Number of identical failures in a row before we abort this worker
  RECENT_SPEC_FAILURE_LIMIT = 10
  # Number of failures to record
  MAX_FAILURES_TO_RECORD = 20
  IMPLICIT_WAIT_TIMEOUT = 15

  def browser
    $selenium_config[:browser].try(:to_sym) || :firefox
  end

  def setup_selenium
    path = $selenium_config[:paths].try(:[], browser)
    if path
      Selenium::WebDriver.const_get(browser.to_s.capitalize).path = path
    end

    SeleniumDriverSetup.set_up_display_buffer if run_headless?

    failure_proc = -> {
      # ensure we quit frd, cuz it's not going to work (otherwise rspec<commit_msg>fix previous definition of SOCKET_LOCK_TIMEOUT warning<commit_after>require "fileutils"

module SeleniumDriverSetup
  # WebDriver uses port 7054 (the "locking port") as a mutex to ensure
  # that we don't launch two Firefox instances at the same time. Each
  # new instance you create will wait for the mutex before starting
  # the browser, then release it as soon as the browser is open.
  #
  # The default port mutex wait timeout is 45 seconds.
  # Bump it to 90 seconds as a stopgap for the recent flood of:
  # `unable to bind to locking port 7054 within 45 seconds`
  #
  # TODO: Investigate why it's taking so long to launch Firefox, or
  #       what process is hogging port 7054.
  module ::Selenium
    module WebDriver
      module Firefox
        class Launcher
          remove_const(:SOCKET_LOCK_TIMEOUT)
        end
      end
    end
  end
  Selenium::WebDriver::Firefox::Launcher::SOCKET_LOCK_TIMEOUT = 90

  # Number of recent specs to show in failure pages
  RECENT_SPEC_RUNS_LIMIT = 500
  # Number of identical failures in a row before we abort this worker
  RECENT_SPEC_FAILURE_LIMIT = 10
  # Number of failures to record
  MAX_FAILURES_TO_RECORD = 20
  IMPLICIT_WAIT_TIMEOUT = 15

  def browser
    $selenium_config[:browser].try(:to_sym) || :firefox
  end

  def setup_selenium
    path = $selenium_config[:paths].try(:[], browser)
    if path
      Selenium::WebDriver.const_get(browser.to_s.capitalize).path = path
    end

    SeleniumDriverSetup.set_up_display_buffer if run_headless?

    failure_proc = -> {
      # ensure we quit frd, cuz it's not going to work (otherwise rspec
{'fraction_non_alphanumeric': 0.06148222000664673, 'fraction_numerical': 0.01927550681289465, 'mean_word_length': 3.5537065052950076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2973720', 'n_tokens_mistral': 995, 'n_tokens_neox': 907, 'n_words': 351}