Skip to content

RUST-670 Expect unified test format operations to succeed #388

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

Merged
merged 3 commits into from
Jul 8, 2021
Merged
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
4 changes: 3 additions & 1 deletion src/coll/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ pub struct CountOptions {
///
/// This options maps to the `maxTimeMS` MongoDB query option, so the duration will be sent
/// across the wire as an integer number of milliseconds.
#[serde(deserialize_with = "deserialize_duration_from_u64_millis")]
#[serde(default, deserialize_with = "deserialize_duration_from_u64_millis")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason these are the only fields on which you've applied the default attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

default is needed when deserialize_with is being used to default the field to None if it isn't specified. I added default to these fields specifically because they weren't properly deserializing from the test files.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Does it make more sense to include default as a container attribute instead now that the options structs aren't Options? I guess every field is optional so it doesn't matter much either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it shouldn't matter, default is only really necessary when we're overriding the default deserialization behavior with deserialize_with because the method provided there doesn't handle Options.

pub max_time: Option<Duration>,

/// The number of documents to skip before counting.
Expand Down Expand Up @@ -548,6 +548,7 @@ pub struct EstimatedDocumentCountOptions {
/// This options maps to the `maxTimeMS` MongoDB query option, so the duration will be sent
/// across the wire as an integer number of milliseconds.
#[serde(
default,
serialize_with = "serialize_duration_as_int_millis",
rename = "maxTimeMS",
deserialize_with = "deserialize_duration_from_u64_millis"
Expand Down Expand Up @@ -577,6 +578,7 @@ pub struct DistinctOptions {
/// This options maps to the `maxTimeMS` MongoDB query option, so the duration will be sent
/// across the wire as an integer number of milliseconds.
#[serde(
default,
serialize_with = "serialize_duration_as_int_millis",
rename = "maxTimeMS",
deserialize_with = "deserialize_duration_from_u64_millis"
Expand Down
9 changes: 6 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! Contains the `Error` and `Result` types that `mongodb` uses.

use std::{collections::{HashMap, HashSet}, fmt::{self, Debug}, sync::Arc};
use std::{
collections::{HashMap, HashSet},
fmt::{self, Debug},
sync::Arc,
};

use bson::Bson;
use serde::Deserialize;
Expand Down Expand Up @@ -58,8 +62,7 @@ impl Error {
ErrorKind::ConnectionPoolCleared {
message: format!(
"Connection pool for {} cleared because another operation failed with: {}",
address,
cause
address, cause
),
}
.into()
Expand Down
10 changes: 7 additions & 3 deletions src/is_master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ use crate::{
/// Construct an isMaster command.
pub(crate) fn is_master_command(api: Option<&ServerApi>) -> Command {
let command_name = if api.is_some() { "hello" } else { "isMaster" };
let mut command = Command::new(command_name.into(), "admin".into(), doc! { command_name: 1 });
let mut command = Command::new(
command_name.into(),
"admin".into(),
doc! { command_name: 1 },
);
if let Some(server_api) = api {
command.set_server_api(server_api);
}
Expand All @@ -28,8 +32,8 @@ pub(crate) async fn run_is_master(
command: Command,
conn: &mut Connection,
) -> Result<IsMasterReply> {
if !command.name.eq_ignore_ascii_case("ismaster") &&
!command.name.eq_ignore_ascii_case("hello") {
if !command.name.eq_ignore_ascii_case("ismaster") && !command.name.eq_ignore_ascii_case("hello")
{
return Err(ErrorKind::Internal {
message: format!("invalid ismaster command: {}", command.name),
}
Expand Down
5 changes: 4 additions & 1 deletion src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ pub struct DatabaseSpecification {
pub name: String,

/// The amount of disk space in bytes that is consumed by the database.
#[serde(deserialize_with = "crate::bson_util::deserialize_u64_from_bson_number")]
#[serde(
deserialize_with = "crate::bson_util::deserialize_u64_from_bson_number",
serialize_with = "crate::bson::serde_helpers::serialize_u64_as_i64"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This addition was necessary because the results from test operations are all serialized into Bson.

)]
pub size_on_disk: u64,

/// Whether the database has any data.
Expand Down
2 changes: 1 addition & 1 deletion src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod spec;
mod util;

pub(crate) use self::{
spec::{run_spec_test, RunOn, Topology},
spec::{run_single_test, run_spec_test, RunOn, Topology},
util::{
assert_matches,
CmapEvent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"description": "assertNumberConnectionsCheckedOut",
"schemaVersion": "1.3",
"createEntities": [
{
"client": {
"id": "client0",
"useMultipleMongoses": true
}
}
],
"tests": [
{
"description": "operation fails if client field is not specified",
"operations": [
{
"name": "assertNumberConnectionsCheckedOut",
"object": "testRunner",
"arguments": {
"connections": 1
}
}
]
},
{
"description": "operation fails if connections field is not specified",
"operations": [
{
"name": "assertNumberConnectionsCheckedOut",
"object": "testRunner",
"arguments": {
"client": "client0"
}
}
]
},
{
"description": "operation fails if client entity does not exist",
"operations": [
{
"name": "assertNumberConnectionsCheckedOut",
"object": "testRunner",
"arguments": {
"client": "client1"
}
}
]
},
{
"description": "operation fails if number of connections is incorrect",
"operations": [
{
"name": "assertNumberConnectionsCheckedOut",
"object": "testRunner",
"arguments": {
"client": "client0",
"connections": 1
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
description: assertNumberConnectionsCheckedOut

schemaVersion: '1.3'

createEntities:
- client:
id: &client0 client0
useMultipleMongoses: true

tests:
- description: operation fails if client field is not specified
operations:
- name: assertNumberConnectionsCheckedOut
object: testRunner
arguments:
connections: 1

- description: operation fails if connections field is not specified
operations:
- name: assertNumberConnectionsCheckedOut
object: testRunner
arguments:
client: *client0

- description: operation fails if client entity does not exist
operations:
- name: assertNumberConnectionsCheckedOut
object: testRunner
arguments:
client: client1

- description: operation fails if number of connections is incorrect
operations:
- name: assertNumberConnectionsCheckedOut
object: testRunner
arguments:
client: *client0
connections: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"description": "entity-bucket-database-undefined",
"schemaVersion": "1.0",
"createEntities": [
{
"bucket": {
"id": "bucket0",
"database": "foo"
}
}
],
"tests": [
{
"description": "foo",
"operations": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
description: "entity-bucket-database-undefined"

schemaVersion: "1.0"

createEntities:
- bucket:
id: &bucket0 "bucket0"
database: "foo"

tests:
- description: "foo"
operations: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"description": "entity-client-apiVersion-unsupported",
"schemaVersion": "1.1",
"createEntities": [
{
"client": {
"id": "client0",
"serverApi": {
"version": "server_will_never_support_this_api_version"
}
}
}
],
"tests": [
{
"description": "foo",
"operations": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
description: "entity-client-apiVersion-unsupported"

schemaVersion: "1.1"

createEntities:
- client:
id: &client0 client0
serverApi:
version: "server_will_never_support_this_api_version"

tests:
- description: "foo"
operations: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"description": "entity-client-storeEventsAsEntities-conflict_with_client_id",
"schemaVersion": "1.2",
"createEntities": [
{
"client": {
"id": "client0",
"storeEventsAsEntities": [
{
"id": "client0",
"events": [
"PoolCreatedEvent",
"PoolReadyEvent",
"PoolClearedEvent",
"PoolClosedEvent"
]
}
]
}
}
],
"tests": [
{
"description": "foo",
"operations": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
description: "entity-client-storeEventsAsEntities-conflict_with_client_id"

schemaVersion: "1.2"

createEntities:
- client:
id: &client0 client0
storeEventsAsEntities:
# Using the client ID here will ensure that test runners also detect
# conflicts with the same entity being defined
- id: *client0
events: ["PoolCreatedEvent", "PoolReadyEvent", "PoolClearedEvent", "PoolClosedEvent"]

tests:
- description: "foo"
operations: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"description": "entity-client-storeEventsAsEntities-conflict_within_different_array",
"schemaVersion": "1.2",
"createEntities": [
{
"client": {
"id": "client0",
"storeEventsAsEntities": [
{
"id": "events",
"events": [
"PoolCreatedEvent",
"PoolReadyEvent",
"PoolClearedEvent",
"PoolClosedEvent"
]
}
]
}
},
{
"client": {
"id": "client1",
"storeEventsAsEntities": [
{
"id": "events",
"events": [
"CommandStartedEvent",
"CommandSucceededEvent",
"CommandFailedEvent"
]
}
]
}
}
],
"tests": [
{
"description": "foo",
"operations": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
description: "entity-client-storeEventsAsEntities-conflict_within_different_array"

schemaVersion: "1.2"

createEntities:
- client:
id: &client0 client0
storeEventsAsEntities:
- id: &events events
events: ["PoolCreatedEvent", "PoolReadyEvent", "PoolClearedEvent", "PoolClosedEvent"]
- client:
id: &client1 client1
storeEventsAsEntities:
- id: *events
events: ["CommandStartedEvent", "CommandSucceededEvent", "CommandFailedEvent"]

tests:
- description: "foo"
operations: []
Loading