<commit_before>module ReplicaSetHelper
  def wait_for_primary(port)
    loop do
      begin
        connection = Mongo::Connection.new 'localhost',port
        return if connection.primary?
        puts "mongodb is not primary yet waiting a second"
        connection.close
      rescue Mongo::ConnectionFailure
        $stderr.puts "mongodb not ready yet, waiting a second"
      end
      sleep 1
    end
  end

  def start_replica_set
    port_a = 27117
    port_b = 27118
    port_c = 27119
  #--replSet dm-mongo-adapter 
  #
    mongod_start :a,port_a,%W(--replSet dm-mongo-adapter)
    mongod_start :b,port_b,%W(--replSet dm-mongo-adapter)
    mongod_start :c,port_c,%W(--replSet dm-mongo-adapter)

    config = <<-JSON
      {
        "_id" : "dm-mongo-adapter",
        "version" : 1,
        "members" : [
          {
            "_id" : 0,
            "priority" : 100,
            "host" : "localhost:#{port_a}"
          },
          {
            "_id" : 1,
            "priority" : 1,
            "host" : "localhost:#{port_b}"
          },
          {
            "_id" : 2,
            "priority" : 1,
            "host" : "localhost:#{port_c}"
          }
        ]
      }
    JSON

    mongod_wait port_a

    Kernel.system *%W(mongo localhost:#{port_a} --eval #{"rs.initiate(#{config});"})

    wait_for_primary port_a

    [
      ['localhost',port_a],
      ['localhost',port_b]
    ]
  end

  def teardown_replica_set
    mongod_stop :a
    mongod_stop :b
    mongod_stop :c
  end
end<commit_msg>Fix mongod_wait in repl set spec<commit_after>module ReplicaSetHelper
  def wait_for_primary(port)
    loop do
      begin
        connection = Mongo::Connection.new 'localhost',port
        return if connection.primary?
        puts "mongodb is not primary yet waiting a second"
        connection.close
      rescue Mongo::ConnectionFailure
        $stderr.puts "mongodb not ready yet, waiting a second"
      end
      sleep 1
    end
  end

  def start_replica_set
    port_a = 27117
    port_b = 27118
    port_c = 27119
  #--replSet dm-mongo-adapter 
  #
    mongod_start :a,port_a,%W(--replSet dm-mongo-adapter)
    mongod_start :b,port_b,%W(--replSet dm-mongo-adapter)
    mongod_start :c,port_c,%W(--replSet dm-mongo-adapter)

    config = <<-JSON
      {
        "_id" : "dm-mongo-adapter",
        "version" : 1,
        "members" : [
          {
            "_id" : 0,
            "priority" : 100,
            "host" : "localhost:#{port_a}"
          },
          {
            "_id" : 1,
            "priority" : 1,
            "host" : "localhost:#{port_b}"
          },
          {
            "_id" : 2,
            "priority" : 1,
            "host" : "localhost:#{port_c}"
          }
        ]
      }
    JSON

    mongod_wait :a

    Kernel.system *%W(mongo localhost:#{port_a} --eval #{"rs.initiate(#{config});"})

    wait_for_primary port_a

    [
      ['localhost',port_a],
      ['localhost',port_b]
    ]
  end

  def teardown_replica_set
    mongod_stop :a
    mongod_stop :b
    mongod_stop :c
  end
end
{'fraction_non_alphanumeric': 0.12086472322305929, 'fraction_numerical': 0.016377333770062234, 'mean_word_length': 1.7864963503649636, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1982587', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1035, 'n_words': 214}