diff --git a/lib/MongoDB/_Topology.pm b/lib/MongoDB/_Topology.pm index 3913a3c0..27675c85 100644 --- a/lib/MongoDB/_Topology.pm +++ b/lib/MongoDB/_Topology.pm @@ -597,6 +597,8 @@ sub _check_wire_versions { my ( $server_min_wire_version, $server_max_wire_version ) = @{ $server->is_master }{qw/minWireVersion maxWireVersion/}; + # set to 0 as could be undefined. 0 is the equivalent to missing, and + # also kept as 0 for legacy compatibility. $server_max_wire_version = 0 unless defined $server_max_wire_version; $server_min_wire_version = 0 unless defined $server_min_wire_version; @@ -1200,8 +1202,9 @@ sub _update_rs_with_primary_from_member { $self->_remove_server($new_server); } - # require 'me' that matches expected address - if ( $new_server->me && $new_server->me ne $new_server->address ) { + # require 'me' that matches expected address. + # check is case insensitive + if ( $new_server->me && lc $new_server->me ne $new_server->address ) { $self->_remove_server($new_server); $self->_check_for_primary; return; diff --git a/t/data/SDAM/README.rst b/t/data/SDAM/README.rst index ddfab3a8..768a1128 100644 --- a/t/data/SDAM/README.rst +++ b/t/data/SDAM/README.rst @@ -9,14 +9,8 @@ Server Discovery And Monitoring Spec. Version ------- -Files in the "specifications" repository have no version scheme. -They are not tied to a MongoDB server version, -and it is our intention that each specification moves from "draft" to "final" -with no further versions; it is superseded by a future spec, not revised. - -However, implementers must have stable sets of tests to target. -As test files evolve they will be occasionally tagged like -"server-discovery-tests-2014-09-10", until the spec is final. +Files in the "specifications" repository have no version scheme. They are not +tied to a MongoDB server version. Format ------ diff --git a/t/data/SDAM/rs/normalize_case_me.json b/t/data/SDAM/rs/normalize_case_me.json new file mode 100644 index 00000000..e854e7fb --- /dev/null +++ b/t/data/SDAM/rs/normalize_case_me.json @@ -0,0 +1,93 @@ +{ + "description": "Replica set mixed case normalization", + "uri": "mongodb://A/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": true, + "setName": "rs", + "me": "A:27017", + "hosts": [ + "A:27017" + ], + "passives": [ + "B:27017" + ], + "arbiters": [ + "C:27017" + ], + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + }, + "b:27017": { + "type": "Unknown", + "setName": null + }, + "c:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "ismaster": false, + "secondary": true, + "setName": "rs", + "me": "B:27017", + "hosts": [ + "A:27017" + ], + "passives": [ + "B:27017" + ], + "arbiters": [ + "C:27017" + ], + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + }, + "b:27017": { + "type": "RSSecondary", + "setName": "rs" + }, + "c:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/t/data/SDAM/rs/normalize_case_me.yml b/t/data/SDAM/rs/normalize_case_me.yml new file mode 100644 index 00000000..51700b96 --- /dev/null +++ b/t/data/SDAM/rs/normalize_case_me.yml @@ -0,0 +1,100 @@ +description: "Replica set mixed case normalization" + +uri: "mongodb://A/?replicaSet=rs" + +phases: [ + + { + responses: [ + + ["a:27017", { + + ok: 1, + ismaster: true, + setName: "rs", + me: "A:27017", + hosts: ["A:27017"], + passives: ["B:27017"], + arbiters: ["C:27017"], + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSPrimary", + setName: "rs" + }, + + "b:27017": { + + type: "Unknown", + setName: + }, + + "c:27017": { + + type: "Unknown", + setName: + } + + }, + + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + }, + { + responses: [ + + ["b:27017", { + + ok: 1, + ismaster: false, + secondary: true, + setName: "rs", + me: "B:27017", + hosts: ["A:27017"], + passives: ["B:27017"], + arbiters: ["C:27017"], + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSPrimary", + setName: "rs" + }, + + "b:27017": { + + type: "RSSecondary", + setName: "rs" + }, + + "c:27017": { + + type: "Unknown", + setName: + } + + }, + + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + } +] diff --git a/t/sdam_spec.t b/t/sdam_spec.t index 09745537..d754cbea 100644 --- a/t/sdam_spec.t +++ b/t/sdam_spec.t @@ -95,8 +95,12 @@ sub run_test { $topology->_update_topology_from_server_desc( @$response[0], $desc); } + # Need to force this check for compatibility checking + # scan_all_servers wont work as there arent actually any servers... + $topology->_check_wire_versions; + # Process outcome - check_outcome($topology, $phase->{'outcome'}); + check_outcome($topology, $phase->{'outcome'}, $name); } }; @@ -104,7 +108,7 @@ sub run_test { sub check_outcome { - my ($topology, $outcome, $start_type) = @_; + my ($topology, $outcome, $name) = @_; my %expected_servers = %{$outcome->{'servers'}}; my %actual_servers = %{$topology->servers}; @@ -127,6 +131,13 @@ sub check_outcome { is($topology->replica_set_name, $expected_set_name, 'correct setName for topology'); is($topology->type, $outcome->{'topologyType'}, 'correct topology type'); is($topology->logical_session_timeout_minutes, $outcome->{'logicalSessionTimeoutMinutes'}, 'correct ls timeout'); + if ( defined $outcome->{'compatible'} ) { + my $compatibility = $outcome->{'compatible'} ? 1 : 0; + # perl driver specifically supports older servers - this goes against + # spec but allows for support of legacy servers. + $compatibility = 1 if $name =~ /too_old/; + is($topology->is_compatible, $compatibility, 'compatibility correct'); + } } done_testing;