Skip to content

Commit 1b43b8a

Browse files
committed
Test Mongo against an embedded MongoDB instance, not external
1 parent 6cb8d11 commit 1b43b8a

15 files changed

Lines changed: 903 additions & 192 deletions

File tree

Cargo.lock

Lines changed: 83 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,26 @@
297297
(nightlyCraneLibFor p).cargoLlvmCov (coverageArgs
298298
// {
299299
cargoArtifacts = nightlyCargoArtifactsFor p;
300+
preConfigurePhases = ["tempHome"];
301+
tempHome = ''
302+
# Default home at this point is /homeless-shelter, which doesn't exist and so breaks things like
303+
# the Mongo downloader
304+
echo "HOME was ''${HOME}"
305+
export HOME=$(mktemp -d fake-homeXXXX --tmpdir)
306+
echo "HOME is now ''${HOME}"
307+
308+
# FIXME: This is a giant pile of hacks, as what we should be doing is downloading mongodb and patching it to work with
309+
# Nix. Several hours of patchelf rummaging later, hitting issues like "_Unwind_GetRegionStart: symbol not found" we
310+
# instead have this hacky workaround. It adds a symlink to a Nix mongod where the extractor code expects to find it,
311+
# which will work. This is the wrong version (7.0.16 v.s. 7.0.11 currently, so not so bad) but TBH our codebase is mostly
312+
# fairly version agnostic so far and 7.0.11 is picked out of the air as the one we've used elsewhere.
313+
314+
mkdir -p $HOME/.cache/mongo/extracted/7.0.11/mongodb-linux-x86_64-ubuntu2204-7.0.11/bin
315+
touch $HOME/.cache/mongo/extracted/7.0.11/extracted.marker # As needed by nativelink-store/tests/mongo_runner/mod.rs
316+
export MONGOD=$HOME/.cache/mongo/extracted/7.0.11/mongodb-linux-x86_64-ubuntu2204-7.0.11/bin/mongod
317+
ln -s ${p.mongodb}/bin/mongod ''${MONGOD}
318+
''${MONGOD} --version
319+
'';
300320
cargoExtraArgs = builtins.concatStringsSep " " [
301321
"--all"
302322
"--locked"

nativelink-error/BUILD.bazel

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ rust_library(
1616
deps = [
1717
"//nativelink-metric",
1818
"//nativelink-proto",
19+
"@crates//:mongodb",
1920
"@crates//:prost",
2021
"@crates//:prost-types",
2122
"@crates//:redis",
23+
"@crates//:reqwest",
2224
"@crates//:rustls-pki-types",
2325
"@crates//:serde",
2426
"@crates//:serde_json5",
@@ -27,6 +29,31 @@ rust_library(
2729
"@crates//:url",
2830
"@crates//:uuid",
2931
"@crates//:walkdir",
32+
"@crates//:zip",
33+
],
34+
)
35+
36+
rust_test_suite(
37+
name = "integration",
38+
timeout = "short",
39+
srcs = [
40+
"tests/error_tests.rs",
41+
],
42+
deps = [
43+
"//nativelink-error",
44+
"@crates//:walkdir",
45+
],
46+
)
47+
48+
rust_test_suite(
49+
name = "integration",
50+
timeout = "short",
51+
srcs = [
52+
"tests/error_tests.rs",
53+
],
54+
deps = [
55+
"//nativelink-error",
56+
"@crates//:walkdir",
3057
],
3158
)
3259

nativelink-error/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ version = "1.0.0-rc4"
1313
nativelink-metric = { path = "../nativelink-metric" }
1414
nativelink-proto = { path = "../nativelink-proto" }
1515

16+
mongodb = { version = "3", features = [
17+
"compat-3-0-0",
18+
"rustls-tls",
19+
], default-features = false }
1620
prost = { version = "0.13.5", default-features = false }
1721
prost-types = { version = "0.13.5", default-features = false, features = [
1822
"std",
1923
] }
2024
redis = { version = "1.0.0", default-features = false }
25+
reqwest = { version = "0.12", default-features = false }
2126
rustls-pki-types = { version = "1.13.1", default-features = false }
2227
serde = { version = "1.0.219", default-features = false }
2328
serde_json5 = { version = "0.2.1", default-features = false }
@@ -34,3 +39,4 @@ tonic = { version = "0.13.0", features = [
3439
url = { version = "2.5.7", default-features = false }
3540
uuid = { version = "1.16.0", default-features = false, features = ["std"] }
3641
walkdir = { version = "2.5.0", default-features = false }
42+
zip = { version = "7.2.0", default-features = false }

nativelink-error/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,24 @@ impl From<url::ParseError> for Error {
335335
}
336336
}
337337

338+
impl From<mongodb::error::Error> for Error {
339+
fn from(err: mongodb::error::Error) -> Self {
340+
Self::from_std_err(Code::Internal, &err)
341+
}
342+
}
343+
344+
impl From<reqwest::Error> for Error {
345+
fn from(err: reqwest::Error) -> Self {
346+
Self::from_std_err(Code::Internal, &err)
347+
}
348+
}
349+
350+
impl From<zip::result::ZipError> for Error {
351+
fn from(err: zip::result::ZipError) -> Self {
352+
Self::from_std_err(Code::Internal, &err)
353+
}
354+
}
355+
338356
pub trait ResultExt<T> {
339357
/// # Errors
340358
///

nativelink-store/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ rust_test_suite(
130130
"tests/size_partitioning_store_test.rs",
131131
"tests/verify_store_test.rs",
132132
],
133+
compile_data = [
134+
"tests/mongo_runner/mod.rs",
135+
"tests/mongo_runner/process.rs",
136+
"tests/mongo_runner/extractor.rs",
137+
"tests/mongo_runner/downloader.rs",
138+
],
133139
proc_macro_deps = [
134140
"//nativelink-macro",
135141
"@crates//:async-trait",
@@ -149,6 +155,8 @@ rust_test_suite(
149155
"@crates//:aws-smithy-types",
150156
"@crates//:bincode",
151157
"@crates//:bytes",
158+
"@crates//:dirs",
159+
"@crates//:flate2",
152160
"@crates//:futures",
153161
"@crates//:hex",
154162
"@crates//:http",
@@ -162,16 +170,19 @@ rust_test_suite(
162170
"@crates//:rand",
163171
"@crates//:redis",
164172
"@crates//:redis-test",
173+
"@crates//:reqwest",
165174
"@crates//:serde_json",
166175
"@crates//:serial_test",
167176
"@crates//:sha2",
177+
"@crates//:tar",
168178
"@crates//:tempfile",
169179
"@crates//:tokio",
170180
"@crates//:tokio-stream",
171181
"@crates//:tonic",
172182
"@crates//:tracing",
173183
"@crates//:tracing-test",
174184
"@crates//:uuid",
185+
"@crates//:zip",
175186
],
176187
)
177188

nativelink-store/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ aws-smithy-runtime-api = { version = "1.7.4", default-features = false }
126126
aws-smithy-types = { version = "1.3.0", default-features = false, features = [
127127
"http-body-1-x",
128128
] }
129+
dirs = { version = "6.0.0", default-features = false }
130+
flate2 = { version = "1.1.9", default-features = false, features = ["zlib-rs"] }
129131
futures = { version = "0.3.31", default-features = false, features = [
130132
"executor",
131133
] }
@@ -141,10 +143,14 @@ rand = { version = "0.9.0", default-features = false, features = [
141143
] }
142144
redis-test = { version = "1.0.0", default-features = false, features = ["aio"] }
143145
serde_json = { version = "1.0.140", default-features = false }
146+
tar = { version = "0.4.44", default-features = false }
144147
tempfile = { version = "3.8.1", default-features = false }
145148
tracing-test = { version = "0.2.5", default-features = false, features = [
146149
"no-env-filter",
147150
] }
151+
zip = { version = "7.2.0", default-features = false, features = [
152+
"deflate-flate2-zlib-rs",
153+
] }
148154

149155
[package.metadata.cargo-machete]
150156
# Used by nativelink_test macro
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Most of this is based off the defunct https://docs.rs/crate/mongo-embedded/1.0.0/source/ code and should be extracted out again as a separate crate at some point

0 commit comments

Comments
 (0)