Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/MongoDB/_Topology.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 2 additions & 8 deletions t/data/SDAM/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand Down
93 changes: 93 additions & 0 deletions t/data/SDAM/rs/normalize_case_me.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
100 changes: 100 additions & 0 deletions t/data/SDAM/rs/normalize_case_me.yml
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
15 changes: 13 additions & 2 deletions t/sdam_spec.t
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,20 @@ 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);
}
};

}

sub check_outcome {

my ($topology, $outcome, $start_type) = @_;
my ($topology, $outcome, $name) = @_;

my %expected_servers = %{$outcome->{'servers'}};
my %actual_servers = %{$topology->servers};
Expand All @@ -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'} ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, if it's the /too_old/ test file then we want to force the compatibility expectation to true. (Along with a comment that Perl has to support older servers.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, have done so :)

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;