Skip to content

Commit e00ed46

Browse files
committed
RUBY-1188 Improve SDAM test mocking to not require localhost:27017 to be unreachable
1 parent c4632a1 commit e00ed46

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

spec/mongo/sdam_spec.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
context(spec.description) do
1111

1212
before(:all) do
13-
Mongo::Client.new(spec.uri_string).tap do |client|
14-
@client = client.with(connect_timeout: 0.1, heartbeat_frequency: 100)
15-
end.close
13+
@client = Mongo::Client.new([])
14+
@client.send(:create_from_uri, spec.uri_string)
15+
client_options = @client.instance_variable_get(:@options)
16+
@client.instance_variable_set(:@options, client_options.merge(heartbeat_frequency: 100, connect_timeout: 0.1))
17+
@client.cluster.instance_variable_set(:@options, client_options.merge(heartbeat_frequency: 100, connect_timeout: 0.1))
18+
@client.cluster.instance_variable_get(:@servers).each { |s| s.disconnect!; s.unknown!; }
1619
end
1720

1821
after(:all) do
@@ -26,13 +29,17 @@
2629
before(:all) do
2730
phase.responses.each do |response|
2831
server = find_server(@client, response.address)
29-
server ||= Mongo::Server.new(
30-
Mongo::Address.new(response.address),
31-
@client.cluster,
32-
@client.instance_variable_get(:@monitoring),
33-
@client.cluster.send(:event_listeners),
34-
@client.cluster.options
35-
)
32+
unless server
33+
server = Mongo::Server.new(
34+
Mongo::Address.new(response.address),
35+
@client.cluster,
36+
@client.instance_variable_get(:@monitoring),
37+
@client.cluster.send(:event_listeners),
38+
@client.cluster.options
39+
)
40+
server.disconnect!
41+
server.unknown!
42+
end
3643
monitor = server.instance_variable_get(:@monitor)
3744
description = monitor.inspector.run(server.description, response.ismaster, 0.5)
3845
monitor.instance_variable_set(:@description, description)

spec/support/sdam/rs/primary_mismatched_me.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"responses": [
2020
[
21-
"lhost:27017",
21+
"localhost:27017",
2222
{
2323
"me": "a:27017",
2424
"hosts": [
@@ -33,5 +33,5 @@
3333
]
3434
}
3535
],
36-
"uri": "mongodb://lhost:27017/?replicaSet=rs"
36+
"uri": "mongodb://localhost:27017/?replicaSet=rs"
3737
}

spec/support/sdam/rs/secondary_mismatched_me.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"responses": [
2020
[
21-
"lhost:27017",
21+
"localhost:27017",
2222
{
2323
"me": "a:27017",
2424
"hosts": [
@@ -33,5 +33,5 @@
3333
]
3434
}
3535
],
36-
"uri": "mongodb://lhost:27017/?replicaSet=rs"
36+
"uri": "mongodb://localhost:27017/?replicaSet=rs"
3737
}

0 commit comments

Comments
 (0)