Skip to content

Commit 5d37889

Browse files
committed
Move integration tests into a crate instead of shell scripts
This has multiple advantages: * Less bash * Less duplication of a hand-grown "testing harness" * It's faster! * It runs as part of a regular `make test-rust` run locally
1 parent 22ffadf commit 5d37889

24 files changed

+597
-443
lines changed

.circleci/config.yml

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ commands:
8080
sudo apt update
8181
sudo apt install --yes --no-install-recommends \
8282
python3-pip \
83-
python3.10-venv
83+
python3.10-venv \
84+
faketime
8485
8586
- run:
8687
name: Install nextest
@@ -117,39 +118,6 @@ commands:
117118
name: Run Rust sample
118119
command: |
119120
cargo run -p sample
120-
- run:
121-
name: Run Rust RLB test
122-
command: |
123-
glean-core/rlb/tests/test-shutdown-blocking.sh
124-
- run:
125-
name: Run Rust RLB crash test
126-
command: |
127-
glean-core/rlb/tests/test-thread-crashing.sh
128-
- run:
129-
name: Run Rust RLB delayed ping data test
130-
command: |
131-
glean-core/rlb/tests/test-delayed-ping-data.sh
132-
- run:
133-
name: Run Rust RLB flush test
134-
command: |
135-
glean-core/rlb/tests/test-ping-lifetime-flush.sh
136-
- run:
137-
name: Run Rust RLB enabled-pings test
138-
command: |
139-
glean-core/rlb/tests/test-enabled-pings.sh
140-
- run:
141-
name: Run Rust RLB pending-gets-removed test
142-
command: |
143-
glean-core/rlb/tests/test-pending-gets-removed.sh
144-
- run:
145-
name: Run Rust RLB mps-delay test
146-
command: |
147-
sudo apt install -y faketime
148-
glean-core/rlb/tests/test-mps-delay.sh
149-
- run:
150-
name: Run Rust Rkv open test
151-
command: |
152-
glean-core/tests/test-rkv-cases.sh
153121
154122
install-rustup:
155123
steps:

Cargo.lock

Lines changed: 95 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ resolver = "2"
44
members = [
55
"glean-core",
66
"glean-core/rlb",
7+
"glean-core/rlb-tests",
78
"glean-core/bundle",
89
"glean-core/bundle-android",
910
"glean-core/build",

Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ else
7070
cargo nextest run --all $(addprefix --target ,$(GLEAN_BUILD_TARGET))
7171
endif
7272

73-
test-rust-examples: glean-core/rlb/tests/*.sh ## Run Rust example tests
74-
@for file in $^; do \
75-
echo "=== $${file} ==="; \
76-
./$$file || exit 1; \
77-
done
78-
7973
test-rust-with-logs: ## Run all Rust tests with debug logging and single-threaded
8074
RUST_LOG=glean,glean_core cargo test --all -- --nocapture --test-threads=1 $(addprefix --target ,$(GLEAN_BUILD_TARGET))
8175

glean-core/rlb-tests/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "glean-tests"
3+
version = "0.1.0"
4+
edition = "2024"
5+
publish = false
6+
license = "MPL-2.0"
7+
8+
[dependencies]
9+
glean = { path = "../rlb" }
10+
env_logger = { version = "0.10.0", default-features = false, features = ["humantime"] }
11+
flate2 = "1.0.19"
12+
libc = "0.2"
13+
log = "0.4.8"
14+
once_cell = "1.18.0"
15+
serde_json = "1.0.44"
16+
17+
[dev-dependencies]
18+
assert_cmd = "2.1.2"
19+
tempfile = "3.1.0"

glean-core/rlb/examples/crashing-threads.rs renamed to glean-core/rlb-tests/src/bin/crashing-threads.rs

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ use std::env;
1818
use std::path::PathBuf;
1919

2020
use once_cell::sync::Lazy;
21-
use tempfile::Builder;
2221

23-
use glean::{private::PingType, ClientInfoMetrics, ConfigurationBuilder};
22+
use glean::{ClientInfoMetrics, ConfigurationBuilder, private::PingType};
2423

2524
#[cfg(unix)]
2625
mod unix {
@@ -38,42 +37,44 @@ mod unix {
3837
value: *mut c_void,
3938
) -> c_int;
4039

41-
#[no_mangle]
40+
#[unsafe(no_mangle)]
4241
pub unsafe extern "C" fn pthread_create(
4342
native: *mut libc::pthread_t,
4443
attr: *const libc::pthread_attr_t,
4544
f: extern "C" fn(*mut c_void) -> *mut c_void,
4645
value: *mut c_void,
4746
) -> c_int {
48-
let name = c"pthread_create".as_ptr();
49-
let symbol = libc::dlsym(libc::RTLD_NEXT, name);
50-
if symbol.is_null() {
51-
panic!("dlsym failed to load `pthread_create` name. Nothing we can do, we abort.");
47+
unsafe {
48+
let name = c"pthread_create".as_ptr();
49+
let symbol = libc::dlsym(libc::RTLD_NEXT, name);
50+
if symbol.is_null() {
51+
panic!("dlsym failed to load `pthread_create` name. Nothing we can do, we abort.");
52+
}
53+
54+
let real_pthread_create = *(&symbol as *const *mut _ as *const pthread_ft);
55+
56+
// thread 1 = glean.initialize
57+
// thread 2 = ping directory processor
58+
// thread 3 = MPS
59+
// thread 4 = uploader for first metrics ping <- this is the one we want to fail
60+
// thread 5 = uploader for health pings <- this is the one we want to fail
61+
// thread 6 = uploader for prototype ping <- this is the one we want to fail
62+
// thread 7 = post-init uploader <- this needs to fail, too
63+
// thread 8 = shutdown wait thread
64+
const TO_BLOCK: &[u32] = &[4, 5, 6, 7];
65+
66+
let spawned = ALLOW_THREAD_SPAWNED.fetch_add(1, Ordering::SeqCst);
67+
if TO_BLOCK.contains(&spawned) {
68+
return -1;
69+
}
70+
71+
real_pthread_create(native, attr, f, value)
5272
}
53-
54-
let real_pthread_create = *(&symbol as *const *mut _ as *const pthread_ft);
55-
56-
// thread 1 = glean.initialize
57-
// thread 2 = ping directory processor
58-
// thread 3 = MPS
59-
// thread 4 = uploader for first metrics ping <- this is the one we want to fail
60-
// thread 5 = uploader for health pings <- this is the one we want to fail
61-
// thread 6 = uploader for prototype ping <- this is the one we want to fail
62-
// thread 7 = post-init uploader <- this needs to fail, too
63-
// thread 8 = shutdown wait thread
64-
const TO_BLOCK: &[u32] = &[4, 5, 6, 7];
65-
66-
let spawned = ALLOW_THREAD_SPAWNED.fetch_add(1, Ordering::SeqCst);
67-
if TO_BLOCK.contains(&spawned) {
68-
return -1;
69-
}
70-
71-
real_pthread_create(native, attr, f, value)
7273
}
7374
}
7475

7576
pub mod glean_metrics {
76-
use glean::{private::BooleanMetric, CommonMetricData, Lifetime};
77+
use glean::{CommonMetricData, Lifetime, private::BooleanMetric};
7778

7879
#[allow(non_upper_case_globals)]
7980
pub static sample_boolean: once_cell::sync::Lazy<BooleanMetric> =
@@ -109,16 +110,10 @@ fn main() {
109110
env_logger::init();
110111

111112
let mut args = env::args().skip(1);
112-
113-
let data_path = if let Some(path) = args.next() {
114-
PathBuf::from(path)
115-
} else {
116-
let root = Builder::new().prefix("simple-db").tempdir().unwrap();
117-
root.path().to_path_buf()
118-
};
113+
let data_path = PathBuf::from(args.next().expect("need data path"));
119114

120115
_ = &*PrototypePing;
121-
let cfg = ConfigurationBuilder::new(true, data_path, "org.mozilla.glean_core.example")
116+
let cfg = ConfigurationBuilder::new(true, data_path, "crashing.threads")
122117
.with_server_endpoint("invalid-test-host")
123118
.with_use_core_mps(true)
124119
.build();

glean-core/rlb/examples/delayed-ping-data.rs renamed to glean-core/rlb-tests/src/bin/delayed-ping-data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use std::{env, process};
1010
use once_cell::sync::Lazy;
1111

1212
use flate2::read::GzDecoder;
13-
use glean::{net, private::PingType, ClientInfoMetrics, ConfigurationBuilder};
13+
use glean::{ClientInfoMetrics, ConfigurationBuilder, net, private::PingType};
1414

1515
pub mod glean_metrics {
16-
use glean::{private::CounterMetric, CommonMetricData, Lifetime};
16+
use glean::{CommonMetricData, Lifetime, private::CounterMetric};
1717

1818
#[allow(non_upper_case_globals)]
1919
pub static sample_counter: once_cell::sync::Lazy<CounterMetric> =

0 commit comments

Comments
 (0)