Skip to content

Commit 9b7e100

Browse files
p-mongop
authored andcommitted
Fix some intermittent failures in test suite (#1381)
* Fix intermittent failures in server spec * Fix intermittent failures in map reduce spec
1 parent fe2f59a commit 9b7e100

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

lib/mongo/collection/view/aggregation.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Aggregation
4242
# The reroute message.
4343
#
4444
# @since 2.1.0
45+
# @deprecated
4546
REROUTE = 'Rerouting the Aggregation operation to the primary server.'.freeze
4647

4748
# Set to true if disk usage is allowed during the aggregation.
@@ -120,8 +121,8 @@ def secondary_ok?
120121

121122
def send_initial_query(server, session)
122123
unless valid_server?(server)
123-
log_warn(REROUTE)
124-
server = cluster.next_primary(false)
124+
log_warn("Rerouting the Aggregation operation to the primary server - #{server.summary} is not suitable")
125+
server = cluster.next_primary
125126
end
126127
validate_collation!(server)
127128
initial_query_op(session).execute(server)

lib/mongo/collection/view/map_reduce.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class MapReduce
3535
# Reroute message.
3636
#
3737
# @since 2.1.0
38+
# @deprecated
3839
REROUTE = 'Rerouting the MapReduce operation to the primary server.'.freeze
3940

4041
# @return [ View ] view The collection view.
@@ -232,8 +233,8 @@ def secondary_ok?
232233

233234
def send_initial_query(server, session)
234235
unless valid_server?(server)
235-
log_warn(REROUTE)
236-
server = cluster.next_primary(false)
236+
log_warn("Rerouting the MapReduce operation to the primary server - #{server.summary} is not suitable")
237+
server = cluster.next_primary
237238
end
238239
validate_collation!(server)
239240
initial_query_op(session).execute(server)

spec/mongo/collection/view/map_reduce_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,14 @@
646646
end
647647

648648
context 'when the server is a valid for writing' do
649+
before do
650+
# We are inspecting server state - kill monitor threads so that
651+
# server state is not changed in background due to intermittent
652+
# connectivity issues in Evergreen
653+
authorized_collection.client.cluster.servers_list.map do |server|
654+
server.monitor.stop!
655+
end
656+
end
649657

650658
it 'does not reroute the operation to a primary' do
651659
expect(Mongo::Logger.logger).not_to receive(:warn?)

spec/mongo/server_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@
364364

365365
context 'server is unknown' do
366366
let(:server) do
367-
described_class.new(address, cluster, monitoring, listeners, SpecConfig.instance.test_options)
367+
described_class.new(address, cluster, monitoring, listeners,
368+
SpecConfig.instance.test_options.merge(monitoring_io: false))
368369
end
369370

370371
before do

0 commit comments

Comments
 (0)