Skip to content

Commit 50c3a87

Browse files
committed
fix explain on old sharded cluster servers
1 parent 562dedb commit 50c3a87

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

spec/integration/crud_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
it 'passes the session' do
148148
client.start_session do |session|
149149
event = Utils.get_command_event(client, 'explain') do |client|
150-
client['foo'].find({}, session: session).explain.should have_key('queryPlanner')
150+
client['foo'].find({}, session: session).explain.should be_explain_output
151151
end
152152
event.command.fetch('lsid').should == session.session_id
153153
end
@@ -159,7 +159,7 @@
159159

160160
it 'passes the read preference' do
161161
event = Utils.get_command_event(client, 'explain') do |client|
162-
client['foo'].find({}, read: {mode: :secondary_preferred}).explain.should have_key('queryPlanner')
162+
client['foo'].find({}, read: {mode: :secondary_preferred}).explain.should be_explain_output
163163
end
164164
event.command.fetch('$readPreference').should == {'mode' => 'secondaryPreferred'}
165165
end
@@ -170,7 +170,7 @@
170170

171171
it 'passes the read preference' do
172172
event = Utils.get_command_event(client, 'explain') do |client|
173-
client['foo', read: {mode: :secondary_preferred}].find.explain.should have_key('queryPlanner')
173+
client['foo', read: {mode: :secondary_preferred}].find.explain.should be_explain_output
174174
end
175175
event.command.fetch('$readPreference').should == {'mode' => 'secondaryPreferred'}
176176
end
@@ -183,7 +183,7 @@
183183

184184
it 'passes the read preference' do
185185
event = Utils.get_command_event(client, 'explain') do |client|
186-
client['foo'].find.explain.should have_key('queryPlanner')
186+
client['foo'].find.explain.should be_explain_output
187187
end
188188
event.command.fetch('$readPreference').should == {'mode' => 'secondaryPreferred'}
189189
end

spec/support/matchers.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,16 @@
7373
(Time.now - start_time).should < min_expected_time
7474
end
7575
end
76+
77+
RSpec::Matchers.define :be_explain_output do
78+
match do |actual|
79+
Hash === actual && (
80+
actual.key?('queryPlanner') ||
81+
actual.key?('allPlans')
82+
)
83+
end
84+
85+
failure_message do |actual|
86+
"expected that #{actual} is explain output: is a hash with either allPlans or queryPlanner keys present"
87+
end
88+
end

0 commit comments

Comments
 (0)