<commit_before>require 'singleton'

class ClusterConfig
  include Singleton
  include RSpec::Core::Pending

  def single_server?
    determine_cluster_config
    @single_server
  end

  def replica_set_name
    determine_cluster_config
    @replica_set_name
  end

  def server_version
    determine_cluster_config
    @server_version
  end

  def enterprise?
    determine_cluster_config
    @enterprise
  end

  def short_server_version
    server_version.split('.')[0..1].join('.')
  end

  def fcv
    determine_cluster_config
    @fcv
  end

  # Per https://jira.mongodb.org/browse/SERVER-39052, working with FCV
  # in sharded topologies is annoying. Also, FCV doesn't exist in servers
  # less than 3.4. This method returns FCV on 3.4+ servers when in single
  # or RS topologies, and otherwise returns the major.minor server version.
  def fcv_ish
    if server_version >= '3.4' && topology != :sharded
      fcv
    else
      if short_server_version == '4.1'
        '4.2'
      else
        short_server_version
      end
    end
  end

  # @return [ Mongo::Address ] The address of the primary in the deployment.
  def primary_address
    determine_cluster_config
    @primary_address
  end

  def primary_address_str
    determine_cluster_config
    @primary_address.seed
  end

  def primary_address_host
    both = primary_address_str
    both.split(':').first
  end

  def primary_address_port<commit_msg>Improve diagnostics when tests cannot connect to deployment (#2008)<commit_after>require 'singleton'

class ClusterConfig
  include Singleton
  include RSpec::Core::Pending

  def single_server?
    determine_cluster_config
    @single_server
  end

  def replica_set_name
    determine_cluster_config
    @replica_set_name
  end

  def server_version
    determine_cluster_config
    @server_version
  end

  def enterprise?
    determine_cluster_config
    @enterprise
  end

  def short_server_version
    server_version.split('.')[0..1].join('.')
  end

  def fcv
    determine_cluster_config
    @fcv
  end

  # Per https://jira.mongodb.org/browse/SERVER-39052, working with FCV
  # in sharded topologies is annoying. Also, FCV doesn't exist in servers
  # less than 3.4. This method returns FCV on 3.4+ servers when in single
  # or RS topologies, and otherwise returns the major.minor server version.
  def fcv_ish
    if server_version.nil?
      raise "Deployment server version not known - check that connection to deployment succeeded"
    end

    if server_version >= '3.4' && topology != :sharded
      fcv
    else
      if short_server_version == '4.1'
        '4.2'
      else
        short_server_version
      end
    end
  end

  # @return [ Mongo::Address ] The address of the primary in the deployment.
  def primary_address
    determine_cluster_config
    @primary_address
  end

  def primary_address_str
    determine_cluster_config
    @primary_address.seed
  end

  def primary_address_host
    both = primary_address_str
    both.split(':').first
  end

  def primary_address_port
{'fraction_non_alphanumeric': 0.0627062706270627, 'fraction_numerical': 0.012541254125412541, 'mean_word_length': 3.1182065217391304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '7224365', 'n_tokens_mistral': 969, 'n_tokens_neox': 930, 'n_words': 267}