-
Notifications
You must be signed in to change notification settings - Fork 176
RUST-1373 Update unified test format runner to support SDAM integration tests #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
079de3b
83dae89
1f1a55b
4740214
5751d18
86f13bb
f06c578
778a596
8387618
e5d9bc4
5c3b40c
362785d
c0243c3
06e7997
c565cca
1b9c9f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ authors = [ | |
"Kaitlin Mahar <[email protected]>", | ||
] | ||
description = "The official MongoDB driver for Rust" | ||
edition = "2018" | ||
edition = "2021" | ||
keywords = ["mongo", "mongodb", "database", "bson", "nosql"] | ||
categories = ["asynchronous", "database", "web-programming"] | ||
repository = "https://github.com/mongodb/mongo-rust-driver" | ||
|
@@ -163,6 +163,7 @@ function_name = "0.2.1" | |
futures = "0.3" | ||
home = "0.5" | ||
pretty_assertions = "1.1.0" | ||
serde = { version = "*", features = ["rc"] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little surprised a bare There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, or more like the dev dependency doesn't place any additional bounds on the version. got this trick from: https://stackoverflow.com/questions/27872009/how-do-i-use-a-feature-of-a-dependency-only-for-testing |
||
serde_json = "1.0.64" | ||
semver = "1.0.0" | ||
time = "0.3.9" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ use serde::{Deserialize, Serialize}; | |
|
||
use crate::{ | ||
bson::{oid::ObjectId, DateTime}, | ||
bson_util, | ||
client::ClusterTime, | ||
error::{ErrorKind, Result}, | ||
hello::HelloReply, | ||
options::ServerAddress, | ||
selection_criteria::TagSet, | ||
|
@@ -106,7 +108,8 @@ pub(crate) struct ServerDescription { | |
// allows us to ensure that only valid states are possible (e.g. preventing that both an error | ||
// and a reply are present) while still making it easy to define helper methods on | ||
// ServerDescription for information we need from the hello reply by propagating with `?`. | ||
pub(crate) reply: Result<Option<HelloReply>, String>, | ||
#[serde(serialize_with = "bson_util::serialize_result_error_as_string")] | ||
pub(crate) reply: Result<Option<HelloReply>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fact that we store There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why were we storing it to begin with, and why do we need to preserve the string behavior in the serialize implementation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was originally converted to being String to preserve the See #301 for the full context. As far as preserving the serialize implementation, I just kept it as-is to avoid breaking any existing tests that might be relying on it. I think workload executor uses it, but I'm not sure. cc @isabelatkinson There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at least for the workload executor it doesn't really matter what the format is. all of the serialized stuff just gets dumped into JSON logs |
||
} | ||
|
||
impl PartialEq for ServerDescription { | ||
|
@@ -122,17 +125,22 @@ impl PartialEq for ServerDescription { | |
|
||
self_response == other_response | ||
} | ||
(Err(self_err), Err(other_err)) => self_err == other_err, | ||
(Err(self_err), Err(other_err)) => { | ||
match (self_err.kind.as_ref(), other_err.kind.as_ref()) { | ||
( | ||
ErrorKind::Command(self_command_err), | ||
ErrorKind::Command(other_command_err), | ||
) => self_command_err.code == other_command_err.code, | ||
_ => self_err.to_string() == other_err.to_string(), | ||
kmahar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
impl ServerDescription { | ||
pub(crate) fn new( | ||
mut address: ServerAddress, | ||
hello_reply: Option<Result<HelloReply, String>>, | ||
) -> Self { | ||
pub(crate) fn new(mut address: ServerAddress, hello_reply: Option<Result<HelloReply>>) -> Self { | ||
address = ServerAddress::Tcp { | ||
host: address.host().to_lowercase(), | ||
port: address.port(), | ||
|
@@ -231,7 +239,7 @@ impl ServerDescription { | |
None | ||
} | ||
|
||
pub(crate) fn set_name(&self) -> Result<Option<String>, String> { | ||
pub(crate) fn set_name(&self) -> Result<Option<String>> { | ||
let set_name = self | ||
.reply | ||
.as_ref() | ||
|
@@ -241,7 +249,7 @@ impl ServerDescription { | |
Ok(set_name) | ||
} | ||
|
||
pub(crate) fn known_hosts(&self) -> Result<impl Iterator<Item = &String>, String> { | ||
pub(crate) fn known_hosts(&self) -> Result<impl Iterator<Item = &String>> { | ||
let known_hosts = self | ||
.reply | ||
.as_ref() | ||
|
@@ -262,7 +270,7 @@ impl ServerDescription { | |
Ok(known_hosts.into_iter().flatten()) | ||
} | ||
|
||
pub(crate) fn invalid_me(&self) -> Result<bool, String> { | ||
pub(crate) fn invalid_me(&self) -> Result<bool> { | ||
if let Some(ref reply) = self.reply.as_ref().map_err(Clone::clone)? { | ||
if let Some(ref me) = reply.command_response.me { | ||
return Ok(&self.address.to_string() != me); | ||
|
@@ -272,7 +280,7 @@ impl ServerDescription { | |
Ok(false) | ||
} | ||
|
||
pub(crate) fn set_version(&self) -> Result<Option<i32>, String> { | ||
pub(crate) fn set_version(&self) -> Result<Option<i32>> { | ||
let me = self | ||
.reply | ||
.as_ref() | ||
|
@@ -282,7 +290,7 @@ impl ServerDescription { | |
Ok(me) | ||
} | ||
|
||
pub(crate) fn election_id(&self) -> Result<Option<ObjectId>, String> { | ||
pub(crate) fn election_id(&self) -> Result<Option<ObjectId>> { | ||
let me = self | ||
.reply | ||
.as_ref() | ||
|
@@ -293,7 +301,7 @@ impl ServerDescription { | |
} | ||
|
||
#[cfg(test)] | ||
pub(crate) fn min_wire_version(&self) -> Result<Option<i32>, String> { | ||
pub(crate) fn min_wire_version(&self) -> Result<Option<i32>> { | ||
let me = self | ||
.reply | ||
.as_ref() | ||
|
@@ -303,7 +311,7 @@ impl ServerDescription { | |
Ok(me) | ||
} | ||
|
||
pub(crate) fn max_wire_version(&self) -> Result<Option<i32>, String> { | ||
pub(crate) fn max_wire_version(&self) -> Result<Option<i32>> { | ||
let me = self | ||
.reply | ||
.as_ref() | ||
|
@@ -313,7 +321,7 @@ impl ServerDescription { | |
Ok(me) | ||
} | ||
|
||
pub(crate) fn last_write_date(&self) -> Result<Option<DateTime>, String> { | ||
pub(crate) fn last_write_date(&self) -> Result<Option<DateTime>> { | ||
match self.reply { | ||
Ok(None) => Ok(None), | ||
Ok(Some(ref reply)) => Ok(reply | ||
|
@@ -325,7 +333,7 @@ impl ServerDescription { | |
} | ||
} | ||
|
||
pub(crate) fn logical_session_timeout(&self) -> Result<Option<Duration>, String> { | ||
pub(crate) fn logical_session_timeout(&self) -> Result<Option<Duration>> { | ||
match self.reply { | ||
Ok(None) => Ok(None), | ||
Ok(Some(ref reply)) => Ok(reply | ||
|
@@ -336,7 +344,7 @@ impl ServerDescription { | |
} | ||
} | ||
|
||
pub(crate) fn cluster_time(&self) -> Result<Option<ClusterTime>, String> { | ||
pub(crate) fn cluster_time(&self) -> Result<Option<ClusterTime>> { | ||
match self.reply { | ||
Ok(None) => Ok(None), | ||
Ok(Some(ref reply)) => Ok(reply.cluster_time.clone()), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ use serde::Serialize; | |
pub use crate::sdam::description::{server::ServerType, topology::TopologyType}; | ||
use crate::{ | ||
bson::DateTime, | ||
error::Error, | ||
hello::HelloCommandResponse, | ||
options::ServerAddress, | ||
sdam::ServerDescription, | ||
|
@@ -100,6 +101,11 @@ impl<'a> ServerInfo<'a> { | |
pub fn tags(&self) -> Option<&TagSet> { | ||
self.command_response_getter(|r| r.tags.as_ref()) | ||
} | ||
|
||
/// Gets the error this server encountered, if any. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could we make this a little more descriptive to clarify it's whatever error caused the server state to change and not just any error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
pub fn error(&self) -> Option<&Error> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed RUST-1432 for this change. |
||
self.description.reply.as_ref().err() | ||
} | ||
} | ||
|
||
impl<'a> fmt::Debug for ServerInfo<'a> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Disjoint capture in closures feature of the 2021 edition helped make using lifetimes in the runner a lot easier, so I bumped it here. Now that the MSRV is updated to the minimum for this edition, this shouldn't be a problem.