diff --git a/lib/mongo/collection/view/aggregation.rb b/lib/mongo/collection/view/aggregation.rb index 10e1c304b1..e75c39335a 100644 --- a/lib/mongo/collection/view/aggregation.rb +++ b/lib/mongo/collection/view/aggregation.rb @@ -42,6 +42,7 @@ class Aggregation # The reroute message. # # @since 2.1.0 + # @deprecated REROUTE = 'Rerouting the Aggregation operation to the primary server.'.freeze # Set to true if disk usage is allowed during the aggregation. @@ -120,8 +121,8 @@ def secondary_ok? def send_initial_query(server, session) unless valid_server?(server) - log_warn(REROUTE) - server = cluster.next_primary(false) + log_warn("Rerouting the Aggregation operation to the primary server - #{server.summary} is not suitable") + server = cluster.next_primary end validate_collation!(server) initial_query_op(session).execute(server) diff --git a/lib/mongo/collection/view/map_reduce.rb b/lib/mongo/collection/view/map_reduce.rb index 01648f49ad..377c7b5c01 100644 --- a/lib/mongo/collection/view/map_reduce.rb +++ b/lib/mongo/collection/view/map_reduce.rb @@ -35,6 +35,7 @@ class MapReduce # Reroute message. # # @since 2.1.0 + # @deprecated REROUTE = 'Rerouting the MapReduce operation to the primary server.'.freeze # @return [ View ] view The collection view. @@ -232,8 +233,8 @@ def secondary_ok? def send_initial_query(server, session) unless valid_server?(server) - log_warn(REROUTE) - server = cluster.next_primary(false) + log_warn("Rerouting the MapReduce operation to the primary server - #{server.summary} is not suitable") + server = cluster.next_primary end validate_collation!(server) initial_query_op(session).execute(server) diff --git a/spec/mongo/collection/view/map_reduce_spec.rb b/spec/mongo/collection/view/map_reduce_spec.rb index 9fd3d8ab09..f6f7dd4171 100644 --- a/spec/mongo/collection/view/map_reduce_spec.rb +++ b/spec/mongo/collection/view/map_reduce_spec.rb @@ -646,6 +646,14 @@ end context 'when the server is a valid for writing' do + before do + # We are inspecting server state - kill monitor threads so that + # server state is not changed in background due to intermittent + # connectivity issues in Evergreen + authorized_collection.client.cluster.servers_list.map do |server| + server.monitor.stop! + end + end it 'does not reroute the operation to a primary' do expect(Mongo::Logger.logger).not_to receive(:warn?) diff --git a/spec/mongo/server_spec.rb b/spec/mongo/server_spec.rb index 5726629e75..edf3ffd5e6 100644 --- a/spec/mongo/server_spec.rb +++ b/spec/mongo/server_spec.rb @@ -364,7 +364,8 @@ context 'server is unknown' do let(:server) do - described_class.new(address, cluster, monitoring, listeners, SpecConfig.instance.test_options) + described_class.new(address, cluster, monitoring, listeners, + SpecConfig.instance.test_options.merge(monitoring_io: false)) end before do