Skip to content

Commit 0da6f17

Browse files
Fix Mongoid CI (#5986) (#5993)
1 parent 3c87007 commit 0da6f17

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

.evergreen/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ buildvariants:
635635
driver: ["current"]
636636
topology: '*'
637637
mongodb-version: ['6.0']
638-
os: debian11
638+
os: ubuntu-22.04
639639
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
640640
tasks:
641641
- name: "test"
@@ -646,7 +646,7 @@ buildvariants:
646646
driver: ["current"]
647647
topology: '*'
648648
mongodb-version: ['latest']
649-
os: debian11
649+
os: ubuntu-22.04
650650
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
651651
tasks:
652652
- name: "test"
@@ -690,7 +690,7 @@ buildvariants:
690690
ruby: ["ruby-3.2"]
691691
mongodb-version: "6.0"
692692
topology: ['replica-set', 'sharded-cluster']
693-
os: debian11
693+
os: ubuntu-22.04
694694
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
695695
tasks:
696696
- name: "test"

.evergreen/config/variants.yml.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildvariants:
55
driver: ["current"]
66
topology: '*'
77
mongodb-version: ['6.0']
8-
os: debian11
8+
os: ubuntu-22.04
99
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
1010
tasks:
1111
- name: "test"
@@ -16,7 +16,7 @@ buildvariants:
1616
driver: ["current"]
1717
topology: '*'
1818
mongodb-version: ['latest']
19-
os: debian11
19+
os: ubuntu-22.04
2020
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
2121
tasks:
2222
- name: "test"
@@ -60,7 +60,7 @@ buildvariants:
6060
ruby: ["ruby-3.2"]
6161
mongodb-version: "6.0"
6262
topology: ['replica-set', 'sharded-cluster']
63-
os: debian11
63+
os: ubuntu-22.04
6464
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
6565
tasks:
6666
- name: "test"

spec/support/expectations.rb

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@
22

33
module Mongoid
44
module Expectations
5-
6-
def connection_class
7-
if defined?(Mongo::Server::ConnectionBase)
8-
Mongo::Server::ConnectionBase
9-
else
10-
# Pre-2.8 drivers
11-
Mongo::Server::Connection
5+
# Previously this method used RSpec::Mocks with .exactly.times(n).and_call_original,
6+
# which stopped working reliably in Ruby 3.3. Now we directly wrap the target method.
7+
def expect_query(number)
8+
if %i[ sharded load-balanced ].include?(ClusterConfig.instance.topology) && number > 0
9+
skip 'This spec requires replica set or standalone topology'
1210
end
13-
end
1411

15-
def expect_query(number)
16-
rv = nil
17-
RSpec::Mocks.with_temporary_scope do
18-
if number > 0
19-
expect_any_instance_of(connection_class).to receive(:command_started).exactly(number).times.and_call_original
20-
else
21-
expect_any_instance_of(connection_class).not_to receive(:command_started)
12+
klass = Mongo::Server::ConnectionBase
13+
original_method = klass.instance_method(:command_started)
14+
query_count = 0
15+
16+
begin
17+
klass.define_method(:command_started) do |*args, **kwargs|
18+
query_count += 1
19+
original_method.bind_call(self, *args, **kwargs)
2220
end
23-
rv = yield
21+
22+
result = yield
23+
expect(query_count).to eq(number)
24+
result
25+
ensure
26+
klass.remove_method(:command_started)
27+
klass.define_method(:command_started, original_method)
2428
end
25-
rv
2629
end
2730

2831
def expect_no_queries(&block)

0 commit comments

Comments
 (0)