Skip to content

Commit

Permalink
RUST-1205 Cherrypick fixes into 3.0.0 (#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
abr-egn authored Jun 6, 2024
1 parent ae9d492 commit a70318d
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 181 deletions.
9 changes: 6 additions & 3 deletions .evergreen/aws-ecs-test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use mongodb::{bson::Document, Client};
use mongodb::{
bson::{doc, Document},
Client,
};

#[tokio::main]
async fn main() {
let uri = std::env::var("MONGODB_URI").expect("no URI given!");
let client = Client::with_uri_str(&uri).await.unwrap();

client
.database("aws")
.collection::<Document>("somecoll")
.find_one(None, None)
.find_one(doc! {})
.await
.unwrap();
}
46 changes: 31 additions & 15 deletions .evergreen/aws-lambda-test/mongodb/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use std::sync::Arc;

use lambda_runtime::{run, service_fn, Error, LambdaEvent};
use mongodb::{bson::doc, event::{cmap::CmapEvent, command::CommandEvent, sdam::SdamEvent, EventHandler}, options::ClientOptions, Client};
use mongodb::{
bson::doc,
event::{cmap::CmapEvent, command::CommandEvent, sdam::SdamEvent, EventHandler},
options::ClientOptions,
Client,
};
use serde::{Deserialize, Serialize};
use tokio::sync::OnceCell;

Expand Down Expand Up @@ -40,7 +45,8 @@ impl Stats {
}
SdamEvent::ServerHeartbeatFailed(ev) => {
assert!(!ev.awaited);
self.failed_heartbeat_durations_millis.push(ev.duration.as_millis());
self.failed_heartbeat_durations_millis
.push(ev.duration.as_millis());
}
_ => (),
}
Expand All @@ -49,10 +55,12 @@ impl Stats {
fn handle_command(&mut self, event: &CommandEvent) {
match event {
CommandEvent::Succeeded(ev) => {
self.command_succeeded_durations_millis.push(ev.duration.as_millis());
self.command_succeeded_durations_millis
.push(ev.duration.as_millis());
}
CommandEvent::Failed(ev) => {
self.command_failed_durations_millis.push(ev.duration.as_millis());
self.command_failed_durations_millis
.push(ev.duration.as_millis());
}
_ => (),
}
Expand All @@ -62,7 +70,8 @@ impl Stats {
match event {
CmapEvent::ConnectionCreated(_) => {
self.connections_open += 1;
self.max_connections_open = std::cmp::max(self.connections_open, self.max_connections_open);
self.max_connections_open =
std::cmp::max(self.connections_open, self.max_connections_open);
}
CmapEvent::ConnectionClosed(_) => {
self.connections_open -= 1;
Expand All @@ -76,23 +85,31 @@ impl State {
async fn new() -> Self {
let uri = std::env::var("MONGODB_URI")
.expect("MONGODB_URI must be set to the URI of the MongoDB deployment");
let mut options = ClientOptions::parse(uri).await.expect("Failed to parse URI");
let mut options = ClientOptions::parse(uri)
.await
.expect("Failed to parse URI");
let stats = Arc::new(std::sync::Mutex::new(Stats::new()));
{
let stats = Arc::clone(&stats);
options.sdam_event_handler = Some(EventHandler::callback(move |ev| stats.lock().unwrap().handle_sdam(&ev)));
options.sdam_event_handler = Some(EventHandler::callback(move |ev| {
stats.lock().unwrap().handle_sdam(&ev)
}));
}
{
let stats = Arc::clone(&stats);
options.command_event_handler = Some(EventHandler::callback(move |ev| stats.lock().unwrap().handle_command(&ev)));
options.command_event_handler = Some(EventHandler::callback(move |ev| {
stats.lock().unwrap().handle_command(&ev)
}));
}
{
let stats = Arc::clone(&stats);
options.cmap_event_handler = Some(EventHandler::callback(move |ev| stats.lock().unwrap().handle_cmap(&ev)));
options.cmap_event_handler = Some(EventHandler::callback(move |ev| {
stats.lock().unwrap().handle_cmap(&ev)
}));
}

let client = Client::with_options(options).expect("Failed to create MongoDB Client");

Self { client, stats }
}
}
Expand All @@ -104,14 +121,13 @@ async fn get_state() -> &'static State {
}

#[derive(Deserialize)]
struct Request {
}
struct Request {}

async fn function_handler(_event: LambdaEvent<Request>) -> Result<Stats, Error> {
let state = get_state().await;
let coll = state.client.database("faas_test").collection("faas_test");
let id = coll.insert_one(doc! { }, None).await?.inserted_id;
coll.delete_one(doc! { "id": id }, None).await?;
let id = coll.insert_one(doc! {}).await?.inserted_id;
coll.delete_one(doc! { "id": id }).await?;

let stats = {
let mut guard = state.stats.lock().unwrap();
Expand All @@ -125,4 +141,4 @@ async fn function_handler(_event: LambdaEvent<Request>) -> Result<Stats, Error>
#[tokio::main]
async fn main() -> Result<(), Error> {
run(service_fn(function_handler)).await
}
}
10 changes: 6 additions & 4 deletions .evergreen/azure-kms-test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use mongodb::{
bson::doc,
Client, client_encryption::{ClientEncryption, MasterKey}, mongocrypt::ctx::KmsProvider, Namespace,
client_encryption::{ClientEncryption, MasterKey},
error::Result,
mongocrypt::ctx::KmsProvider,
Client,
Namespace,
};

use std::env;
Expand All @@ -19,11 +22,10 @@ async fn main() -> Result<()> {
.expect("KEY_VAULT_ENDPOINT environment variable should be set");

c.create_data_key(MasterKey::Azure {
key_vault_endpoint: key_vault_endpoint,
key_name: key_name,
key_vault_endpoint,
key_name,
key_version: None,
})
.run()
.await?;

println!("Azure KMS integration test passed!");
Expand Down
1 change: 0 additions & 1 deletion .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ buildvariants:

- name: sync-api
display_name: "Sync API"
patchable: false
run_on:
- rhel87-small
expansions:
Expand Down
20 changes: 1 addition & 19 deletions .evergreen/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,13 @@ for arg; do
elif [ $arg == "junit-dependencies" ]; then
source ${CARGO_HOME}/env

# install npm/node
./.evergreen/install-node.sh

source ./.evergreen/env.sh

# Install junit-compatible test runner
cargo install cargo-nextest --locked

# Install tool for merging different junit reports into a single one
set +o errexit
set -o pipefail

npm install -g junit-report-merger --cache $(mktemp -d) 2>&1 | tee npm-install-output
RESULT=$?
MATCH=$(grep -o '/\S*-debug.log' npm-install-output)
if [[ $MATCH != "" ]]; then
echo ===== BEGIN NPM LOG =====
cat $MATCH
echo ===== END NPM LOG =====
fi

set -o errexit
if [ $RESULT -ne 0 ]; then
exit $RESULT
fi
cargo install merge-junit
elif [ $arg == "libmongocrypt" ]; then
mkdir ${PROJECT_DIRECTORY}/libmongocrypt
cd ${PROJECT_DIRECTORY}/libmongocrypt
Expand Down
109 changes: 0 additions & 109 deletions .evergreen/install-node.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .evergreen/run-aws-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ cargo_test spec::auth spec.xml
cargo_test uri_options uri_options.xml
cargo_test connection_string connection_string.xml

junit-report-merger results.xml auth_aws.xml lambda_handler.xml spec.xml uri_options.xml connection_string.xml
merge-junit -o results.xml auth_aws.xml lambda_handler.xml spec.xml uri_options.xml connection_string.xml

exit $CARGO_RESULT
2 changes: 1 addition & 1 deletion .evergreen/run-connection-string-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ cargo_test spec::auth spec.xml
cargo_test uri_options uri_options.xml
cargo_test connection_string connection_string.xml

junit-report-merger results.xml spec.xml uri_options.xml connection_string.xml
merge-junit -o results.xml spec.xml uri_options.xml connection_string.xml

exit ${CARGO_RESULT}
11 changes: 0 additions & 11 deletions .evergreen/run-csfle-kmip-servers.sh

This file was deleted.

7 changes: 0 additions & 7 deletions .evergreen/run-csfle-mock-azure-imds.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .evergreen/run-csfle-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
cargo_test test::csfle::on_demand_aws_failure failure.xml

junit-report-merger results.xml prose.xml spec.xml failure.xml
merge-junit -o results.xml prose.xml spec.xml failure.xml

exit ${CARGO_RESULT}
2 changes: 1 addition & 1 deletion .evergreen/run-serverless-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ cargo_test test::cursor cursor.xml
cargo_test test::spec::collection_management coll.xml
cargo_test test::spec::command_monitoring_unified monitoring.xml

junit-report-merger results.xml crud.xml retryable_reads.xml retryable_writes.xml versioned_api.xml sessions.xml transactions.xml load_balancers.xml cursor.xml coll.xml monitoring.xml
merge-junit -o results.xml crud.xml retryable_reads.xml retryable_writes.xml versioned_api.xml sessions.xml transactions.xml load_balancers.xml cursor.xml coll.xml monitoring.xml

exit $CARGO_RESULT
Loading

0 comments on commit a70318d

Please sign in to comment.