Skip to content

Commit 8d061f7

Browse files
p-mongop
authored andcommitted
RUBY-1561 Handle mongos in server summary reporting (#1399)
1 parent 3a51385 commit 8d061f7

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

lib/mongo/server.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ def summary
263263
'GHOST'
264264
when other?
265265
'OTHER'
266+
when mongos?
267+
'MONGOS'
266268
when unknown?
267269
'UNKNOWN'
268270
else

spec/mongo/server_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,5 +380,19 @@
380380
expect(server.summary).not_to include('replica_set')
381381
end
382382
end
383+
384+
context 'server is a mongos' do
385+
let(:server) do
386+
make_server(:mongos)
387+
end
388+
389+
before do
390+
expect(server).to be_mongos
391+
end
392+
393+
it 'specifies the server is a mongos' do
394+
expect(server.summary).to match(/MONGOS/)
395+
end
396+
end
383397
end
384398
end

spec/support/common_shortcuts.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,23 @@ def make_server(mode, options = {})
4646
tags = options[:tags] || {}
4747
average_round_trip_time = options[:average_round_trip_time] || 0
4848

49-
ismaster = {
50-
'ismaster' => mode == :primary,
51-
'secondary' => mode == :secondary,
52-
'arbiterOnly' => mode == :arbiter,
53-
'isreplicaset' => mode == :ghost,
54-
'hidden' => mode == :other,
55-
'tags' => tags,
56-
'ok' => 1,
57-
'minWireVersion' => 2, 'maxWireVersion' => 8,
58-
}
59-
if [:primary, :secondary, :arbiter, :other].include?(mode)
60-
ismaster['setName'] = 'mongodb_set'
49+
if mode == :unknown
50+
ismaster = {}
51+
else
52+
ismaster = {
53+
'ismaster' => mode == :primary,
54+
'secondary' => mode == :secondary,
55+
'arbiterOnly' => mode == :arbiter,
56+
'isreplicaset' => mode == :ghost,
57+
'hidden' => mode == :other,
58+
'msg' => mode == :mongos ? 'isdbgrid' : nil,
59+
'tags' => tags,
60+
'ok' => 1,
61+
'minWireVersion' => 2, 'maxWireVersion' => 8,
62+
}
63+
if [:primary, :secondary, :arbiter, :other].include?(mode)
64+
ismaster['setName'] = 'mongodb_set'
65+
end
6166
end
6267

6368
listeners = Mongo::Event::Listeners.new

0 commit comments

Comments
 (0)