spec/support/cluster_tools.rb
# Attempts to elect the server at the specified address as the new primary
# by manipulating priorities.
#
# This method requires that there is an active primary in the replica set at
# the time of the call (presumably a different one).
#
# @param [ Mongo::Address ] address
Attempts to elect the server at the specified address as the new primary
by manipulating priorities.

This method requires that there is an active primary in the replica set at
the time of the call (presumably a different one).
Attempts to elect the server at the specified address as the new primary by manipulating priorities . This method requires that there is an active primary in the replica set at the time of the call ( presumably a different one ) .
def force_primary(address)
    current_primary = admin_client.cluster.next_primary
    if current_primary.address == address
      raise "Attempting to set primary to #{address} but it is already the primary"
    end
    encourage_primary(address)
    if unfreeze_server(address)
      return
    end
    step_down
    persistently_step_up(address)
    admin_client.cluster.next_primary.unknown!
    new_primary = admin_client.cluster.next_primary
    if new_primary.address != address
      raise "Elected primary #{new_primary.address} is not what we wanted (#{address})"
    end
  end
def force_primary ( address ) current_primary = admin_client . cluster . next_primary if current_primary . address == address raise "Attempting to set primary to #{address} but it is already the primary" end encourage_primary ( address ) if unfreeze_server ( address ) return end step_down persistently_step_up ( address ) admin_client . cluster . next_primary . unknown! new_primary = admin_client . cluster . next_primary if new_primary . address != address raise "Elected primary #{new_primary.address} is not what we wanted (#{address})" end end
Attempts to elect the server at the specified address as the new primary
by manipulating priorities.
Attempts to elect the server at the specified address as the new primary by manipulating priorities .
# Target server self-elected as primary, no further action is needed.
address
None