Skip to content

Commit 7caebdf

Browse files
author
Andrew Witten
authored
RUST-1044 Update evergreen config to test compressors. (#486)
Update evergreen config to use compressors.
1 parent 6c1f687 commit 7caebdf

File tree

7 files changed

+106
-17
lines changed

7 files changed

+106
-17
lines changed

.evergreen/check-clippy.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ set -o errexit
44

55
. ~/.cargo/env
66
cargo clippy --all-targets -p mongodb -- -D warnings
7+
# check clippy with compressors separately
8+
cargo clippy --all-targets -p mongodb --features zstd-compression,snappy-compression,zlib-compression -- -D warnings
79
cargo clippy --all-targets --no-default-features --features async-std-runtime -p mongodb -- -D warnings
810
cargo clippy --all-targets --no-default-features --features sync -p mongodb -- -D warnings

.evergreen/compile-only-tokio.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ set -o errexit
44

55
. ~/.cargo/env
66

7-
rustup run $RUST_VERSION cargo build
7+
# Enable snappy, zlib unconditionally
8+
FEATURE_FLAGS=snappy-compression,zlib-compression
9+
10+
# Zstd requires Rust version 1.54
11+
if [[ $RUST_VERSION == "nightly" ]]; then
12+
FEATURE_FLAGS=$FEATURE_FLAGS,zstd-compression
13+
fi
14+
15+
rustup run $RUST_VERSION cargo build --features $FEATURE_FLAGS

.evergreen/config.yml

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ functions:
259259
ECS_SRC_DIR=$AUTH_AWS_DIR/src
260260
261261
mkdir -p $ECS_SRC_DIR/.evergreen
262-
262+
263263
# fix issue with `TestData` in SERVER-46340
264264
sed -i '1s+^+TestData = {};\n+' $AUTH_AWS_DIR/lib/ecs_hosted_test.js
265265
@@ -294,7 +294,7 @@ functions:
294294
export MONGODB_URI="${MONGODB_URI}"
295295
export SSL="${SSL}"
296296
. .evergreen/generate-uri.sh
297-
297+
298298
export CERT_PATH=$DRIVERS_TOOLS/.evergreen/x509gen/client.pem
299299
300300
.evergreen/run-x509-tests.sh
@@ -320,7 +320,7 @@ functions:
320320
${PREPARE_SHELL}
321321
322322
.evergreen/run-connection-string-tests.sh
323-
323+
324324
"prepare resources":
325325
- command: shell.exec
326326
params:
@@ -369,6 +369,9 @@ functions:
369369
export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}"
370370
. .evergreen/generate-uri.sh
371371
372+
SNAPPY_COMPRESSION_ENABLED=${SNAPPY_COMPRESSION_ENABLED} \
373+
ZLIB_COMPRESSION_ENABLED=${ZLIB_COMPRESSION_ENABLED} \
374+
ZSTD_COMPRESSION_ENABLED=${ZSTD_COMPRESSION_ENABLED} \
372375
SINGLE_THREAD=${SINGLE_THREAD} \
373376
ASYNC_RUNTIME=${ASYNC_RUNTIME} \
374377
MONGODB_API_VERSION=${MONGODB_API_VERSION} \
@@ -546,7 +549,7 @@ functions:
546549
params:
547550
script: |
548551
${PREPARE_SHELL}
549-
552+
550553
cd "$MONGO_ORCHESTRATION_HOME"
551554
# source the mongo-orchestration virtualenv if it exists
552555
if [ -f venv/bin/activate ]; then
@@ -615,7 +618,7 @@ functions:
615618
- command: expansions.update
616619
params:
617620
file: lb-expansion.yml
618-
621+
619622
"stop load balancer":
620623
- command: shell.exec
621624
params:
@@ -836,7 +839,7 @@ tasks:
836839
MONGODB_VERSION: "latest"
837840
TOPOLOGY: "sharded_cluster"
838841
- func: "run tests"
839-
842+
840843
- name: "test-latest-load_balancer"
841844
tags: ["latest", "load_balancer"]
842845
commands:
@@ -1314,6 +1317,24 @@ axes:
13141317
AUTH: "noauth"
13151318
SSL: "nossl"
13161319

1320+
- id: "compressor"
1321+
display_name: "Compressor"
1322+
values:
1323+
- id: "no-compression"
1324+
display_name: No Compressor
1325+
- id: "zstd-compression"
1326+
display_name: Zstd
1327+
variables:
1328+
ZSTD_COMPRESSION_ENABLED: "true"
1329+
- id: "zlib-compression"
1330+
display_name: Zlib
1331+
variables:
1332+
ZLIB_COMPRESSION_ENABLED: "true"
1333+
- id: "snappy-compression"
1334+
display_name: Snappy
1335+
variables:
1336+
SNAPPY_COMPRESSION_ENABLED: "true"
1337+
13171338
- id: "os"
13181339
display_name: OS
13191340
values:
@@ -1370,7 +1391,18 @@ buildvariants:
13701391
- windows-64-vs2017
13711392
auth-and-tls: "*"
13721393
async-runtime: "*"
1373-
display_name: "! ${os} ${auth-and-tls} with ${async-runtime}"
1394+
compressor: "*"
1395+
exclude_spec:
1396+
- compressor: ["zlib-compression", "zstd-compression", "snappy-compression"]
1397+
auth-and-tls: "noauth-and-notls"
1398+
os: "*"
1399+
async-runtime: "*"
1400+
- compressor: ["zlib-compression", "zstd-compression", "snappy-compression"]
1401+
async-runtime: "async-std"
1402+
os: "*"
1403+
auth-and-tls: "*"
1404+
1405+
display_name: "! ${os} ${auth-and-tls} with ${async-runtime} and ${compressor}"
13741406
tasks:
13751407
- ".latest"
13761408
- ".5.0"
@@ -1386,26 +1418,30 @@ buildvariants:
13861418
os: "ubuntu-20.04"
13871419
auth-and-tls: "*"
13881420
async-runtime: "*"
1421+
compressor: "*"
13891422
then:
13901423
remove_tasks: [".3.6", ".4.0", ".4.2"]
13911424
- if:
13921425
os: "ubuntu-18.04"
13931426
auth-and-tls: "auth-and-tls"
13941427
async-runtime: "*"
1428+
compressor: "*"
13951429
then:
13961430
remove_tasks: ".3.6"
13971431
# ubuntu 1804 ARM64 only has downloads for 4.2+
13981432
- if:
13991433
os: ["ubuntu-18.04-arm64"]
14001434
auth-and-tls: "*"
14011435
async-runtime: "*"
1436+
compressor: "*"
14021437
then:
14031438
remove_tasks: [".3.6", ".4.0"]
14041439
# haproxy isn't installed on windows / ubuntu-arm
14051440
- if:
14061441
os: ["ubuntu-18.04-arm64", "windows-64-vs2017"]
14071442
auth-and-tls: "*"
14081443
async-runtime: "*"
1444+
compressor: "*"
14091445
then:
14101446
remove_tasks: ".load_balancer"
14111447
- matrix_name: "x509-auth"
@@ -1432,7 +1468,7 @@ buildvariants:
14321468
display_name: "${os} PLAIN auth with ${async-runtime}"
14331469
tasks:
14341470
- "test-plain-auth"
1435-
1471+
14361472
- matrix_name: "atlas-connect"
14371473
matrix_spec:
14381474
os:

.evergreen/run-tokio-tests.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ if [ "$SINGLE_THREAD" = true ]; then
88
OPTIONS="-- --test-threads=1"
99
fi
1010

11-
echo "cargo test options: ${OPTIONS}"
11+
FEATURE_FLAGS="zstd-compression,snappy-compression,zlib-compression"
1212

13-
RUST_BACKTRACE=1 cargo test $OPTIONS
13+
echo "cargo test options: --features $FEATURE_FLAGS ${OPTIONS}"
14+
15+
RUST_BACKTRACE=1 cargo test --features $FEATURE_FLAGS $OPTIONS

src/client/options/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ impl ClientOptions {
976976
/// * `authSource`: maps to the `source` field of the `credential` field
977977
/// * `authMechanismProperties`: maps to the `mechanism_properties` field of the `credential`
978978
/// field
979-
/// * `compressors`: not yet implemented
979+
/// * `compressors`: maps to the `compressors` field
980980
/// * `connectTimeoutMS`: maps to the `connect_timeout` field
981981
/// * `direct`: maps to the `direct` field
982982
/// * `heartbeatFrequencyMS`: maps to the `heartbeat_frequency` field
@@ -1010,7 +1010,8 @@ impl ClientOptions {
10101010
/// * `w`: maps to the `w` field of the `write_concern` field
10111011
/// * `waitQueueTimeoutMS`: unsupported, does not map to any field
10121012
/// * `wTimeoutMS`: maps to the `w_timeout` field of the `write_concern` field
1013-
/// * `zlibCompressionLevel`: not yet implemented
1013+
/// * `zlibCompressionLevel`: maps to the `level` field of the `Compressor::Zlib` variant
1014+
/// (which requires the `zlib-compression` feature flag) of the [`Compressor`] enum
10141015
///
10151016
/// Note: if the `sync` feature is enabled, then this method will be replaced with [the sync
10161017
/// version](#method.parse-1).

src/compression/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ use flate2::{
1414

1515
#[cfg(feature = "zlib-compression")]
1616
use std::convert::TryInto;
17-
#[cfg(feature = "zstd-compression")]
18-
use std::io::prelude::*;
17+
18+
#[cfg(any(
19+
feature = "zstd-compression",
20+
feature = "zlib-compression",
21+
feature = "snappy-compression"
22+
))]
23+
use std::io::Write;
1924

2025
use crate::error::{Error, ErrorKind, Result};
2126

src/test/mod.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use lazy_static::lazy_static;
3737
use self::util::TestLock;
3838
use crate::{
3939
client::options::{ServerApi, ServerApiVersion},
40-
options::ClientOptions,
40+
options::{ClientOptions, Compressor},
4141
};
4242
use std::{fs::read_to_string, str::FromStr};
4343

@@ -62,6 +62,12 @@ lazy_static! {
6262
std::env::var("SINGLE_MONGOS_LB_URI").ok();
6363
pub(crate) static ref LOAD_BALANCED_MULTIPLE_URI: Option<String> =
6464
std::env::var("MULTI_MONGOS_LB_URI").ok();
65+
pub(crate) static ref ZSTD_COMPRESSION_ENABLED: bool =
66+
matches!(std::env::var("ZSTD_COMPRESSION_ENABLED"), Ok(s) if s == "true");
67+
pub(crate) static ref ZLIB_COMPRESSION_ENABLED: bool =
68+
matches!(std::env::var("ZLIB_COMPRESSION_ENABLED"), Ok(s) if s == "true");
69+
pub(crate) static ref SNAPPY_COMPRESSION_ENABLED: bool =
70+
matches!(std::env::var("SNAPPY_COMPRESSION_ENABLED"), Ok(s) if s == "true");
6571
}
6672

6773
pub(crate) fn client_options_for_uri(uri: &str) -> ClientOptions {
@@ -74,10 +80,39 @@ pub(crate) fn client_options_for_uri(uri: &str) -> ClientOptions {
7480
{
7581
options.test_options_mut().mock_service_id = true;
7682
}
77-
83+
options.compressors = get_compressors();
7884
options
7985
}
8086

87+
fn get_compressors() -> Option<Vec<Compressor>> {
88+
#[allow(unused_mut)]
89+
let mut compressors = vec![];
90+
91+
if *SNAPPY_COMPRESSION_ENABLED {
92+
#[cfg(feature = "snappy-compression")]
93+
compressors.push(Compressor::Snappy);
94+
#[cfg(not(feature = "snappy-compression"))]
95+
panic!("To use snappy compression, the \"snappy-compression\" feature flag must be set.");
96+
}
97+
if *ZLIB_COMPRESSION_ENABLED {
98+
#[cfg(feature = "zlib-compression")]
99+
compressors.push(Compressor::Zlib { level: None });
100+
#[cfg(not(feature = "zlib-compression"))]
101+
panic!("To use zlib compression, the \"zlib-compression\" feature flag must be set.");
102+
}
103+
if *ZSTD_COMPRESSION_ENABLED {
104+
#[cfg(feature = "zstd-compression")]
105+
compressors.push(Compressor::Zstd { level: None });
106+
#[cfg(not(feature = "zstd-compression"))]
107+
panic!("To use zstd compression, the \"zstd-compression\" feature flag must be set.");
108+
}
109+
if compressors.is_empty() {
110+
None
111+
} else {
112+
Some(compressors)
113+
}
114+
}
115+
81116
fn get_default_uri() -> String {
82117
if let Some(uri) = LOAD_BALANCED_SINGLE_URI.clone() {
83118
if !uri.is_empty() {

0 commit comments

Comments
 (0)