Skip to content

Commit cb24f4a

Browse files
authored
RUST-1370 Only check specific fields for hello equality (#892)
1 parent 9ef3ada commit cb24f4a

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/hello.rs

-23
Original file line numberDiff line numberDiff line change
@@ -182,29 +182,6 @@ pub(crate) struct HelloCommandResponse {
182182
pub connection_id: Option<i32>,
183183
}
184184

185-
impl PartialEq for HelloCommandResponse {
186-
fn eq(&self, other: &Self) -> bool {
187-
self.server_type() == other.server_type()
188-
&& self.min_wire_version == other.min_wire_version
189-
&& self.max_wire_version == other.max_wire_version
190-
&& self.me == other.me
191-
&& self.hosts == other.hosts
192-
&& self.passives == other.passives
193-
&& self.arbiters == other.arbiters
194-
&& self.tags == other.tags
195-
&& self.set_name == other.set_name
196-
&& self.set_version == other.set_version
197-
&& self.election_id == other.election_id
198-
&& self.primary == other.primary
199-
&& self.logical_session_timeout_minutes == other.logical_session_timeout_minutes
200-
&& self.max_bson_object_size == other.max_bson_object_size
201-
&& self.max_write_batch_size == other.max_write_batch_size
202-
&& self.service_id == other.service_id
203-
&& self.max_message_size_bytes == other.max_message_size_bytes
204-
&& self.topology_version == other.topology_version
205-
}
206-
}
207-
208185
impl HelloCommandResponse {
209186
pub(crate) fn server_type(&self) -> ServerType {
210187
if self.msg.as_deref() == Some("isdbgrid") {

src/sdam/description/server.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
bson_util,
99
client::ClusterTime,
1010
error::{Error, ErrorKind, Result},
11-
hello::HelloReply,
11+
hello::{HelloCommandResponse, HelloReply},
1212
options::ServerAddress,
1313
selection_criteria::TagSet,
1414
};
@@ -137,6 +137,25 @@ pub(crate) struct ServerDescription {
137137
pub(crate) reply: Result<Option<HelloReply>>,
138138
}
139139

140+
// Server description equality has a specific notion of what fields in a hello command response
141+
// should be compared (https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#serverdescription).
142+
fn hello_command_eq(a: &HelloCommandResponse, b: &HelloCommandResponse) -> bool {
143+
a.server_type() == b.server_type()
144+
&& a.min_wire_version == b.min_wire_version
145+
&& a.max_wire_version == b.max_wire_version
146+
&& a.me == b.me
147+
&& a.hosts == b.hosts
148+
&& a.passives == b.passives
149+
&& a.arbiters == b.arbiters
150+
&& a.tags == b.tags
151+
&& a.set_name == b.set_name
152+
&& a.set_version == b.set_version
153+
&& a.election_id == b.election_id
154+
&& a.primary == b.primary
155+
&& a.logical_session_timeout_minutes == b.logical_session_timeout_minutes
156+
&& a.topology_version == b.topology_version
157+
}
158+
140159
impl PartialEq for ServerDescription {
141160
fn eq(&self, other: &Self) -> bool {
142161
if self.address != other.address || self.server_type != other.server_type {
@@ -148,7 +167,11 @@ impl PartialEq for ServerDescription {
148167
let self_response = self_reply.as_ref().map(|r| &r.command_response);
149168
let other_response = other_reply.as_ref().map(|r| &r.command_response);
150169

151-
self_response == other_response
170+
match (self_response, other_response) {
171+
(Some(a), Some(b)) => hello_command_eq(a, b),
172+
(None, None) => true,
173+
_ => false,
174+
}
152175
}
153176
(Err(self_err), Err(other_err)) => {
154177
match (self_err.kind.as_ref(), other_err.kind.as_ref()) {

0 commit comments

Comments
 (0)