This is an automated email from the ASF dual-hosted git repository. tisonkun pushed a commit to branch rework-integration-tests in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
commit eb48009d187184c12e580a5dbdda208689606230 Author: tison <[email protected]> AuthorDate: Tue Jul 28 08:20:36 2026 +0800 more 2 Signed-off-by: tison <[email protected]> --- AGENTS.md | 5 ++ CONTRIBUTING.md | 27 ++++++++++- datasketches/Cargo.toml | 40 ---------------- datasketches/tests/serde_tests.rs | 55 ++++++++++++++++++++++ datasketches/tests/serialization_tests/bloom.rs | 5 +- datasketches/tests/serialization_tests/countmin.rs | 5 +- datasketches/tests/serialization_tests/cpc.rs | 5 +- .../tests/serialization_tests/frequencies.rs | 5 +- datasketches/tests/serialization_tests/hll.rs | 5 +- datasketches/tests/serialization_tests/tdigest.rs | 5 +- datasketches/tests/serialization_tests/theta.rs | 5 +- datasketches/tests/serialization_tests/tuple.rs | 5 +- 12 files changed, 102 insertions(+), 65 deletions(-) diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..c6b6b36 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,5 @@ +# Repository instructions for agents + +Before planning or modifying this repository, read [CONTRIBUTING.md](CONTRIBUTING.md) in full and treat its build, test, integration-test layout, and serialization snapshot guidance as repository requirements. + +For test changes, pay particular attention to the "Integration test layout" and "Serialization snapshots" sections. Keep the documented workflow synchronized with structural changes, and run the applicable `cargo x check`, `cargo x test`, and `cargo x lint` commands before handing work back. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 095b750..02e98ee 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,7 +47,7 @@ Test: ```shell cargo x test # or -cargo test --workspace --no-default-features +cargo test --workspace --all-features ``` Lint: @@ -56,6 +56,31 @@ Lint: cargo x lint ``` +## Integration test layout + +Integration tests for the `datasketches` crate live under `datasketches/tests` and use two entry-point patterns. + +### Sketch behavior tests + +Non-serialization tests are grouped into one integration-test target per sketch. The target entry point is `datasketches/tests/<sketch>_test/main.rs`, with operation-specific modules such as `update.rs`, `union.rs`, or `intersection.rs` alongside it. + +Because these entry points are nested below `tests`, Cargo does not discover them automatically. Each new sketch target must also be registered in `datasketches/Cargo.toml` with its required feature: + +```toml +[[test]] +name = "tuple_test" +path = "tests/tuple_test/main.rs" +required-features = ["tuple"] +``` + +When adding a case to an existing sketch target, add it to the appropriate module and declare any new module from that target's `main.rs`; no Cargo manifest change is needed. Add another `[[test]]` entry only when introducing a new sketch target. + +### Serialization compatibility tests + +Cargo automatically discovers `datasketches/tests/serde_tests.rs`, which aggregates the sketch-specific modules under `datasketches/tests/serialization_tests`. Each module is gated by its corresponding sketch feature in `serde_tests.rs`. + +To add serialization tests for another sketch, add `serialization_tests/<sketch>.rs` and a feature-gated module declaration in `serde_tests.rs`. Do not add a separate `[[test]]` entry. Shared path handling belongs in `serialization_tests/support.rs`, and serialization fixtures belong in the appropriate subdirectory under `serialization_tests`. + ## Manual workflow (without xtask) `cargo x lint` runs the following steps. Use these directly when you need more control or want to isolate failures: diff --git a/datasketches/Cargo.toml b/datasketches/Cargo.toml index 17f3d91..e3bdec1 100644 --- a/datasketches/Cargo.toml +++ b/datasketches/Cargo.toml @@ -82,46 +82,6 @@ name = "tuple_test" path = "tests/tuple_test/main.rs" required-features = ["tuple"] -[[test]] -name = "bloom_serialization_test" -path = "tests/serialization_tests/bloom.rs" -required-features = ["bloom"] - -[[test]] -name = "countmin_serialization_test" -path = "tests/serialization_tests/countmin.rs" -required-features = ["countmin"] - -[[test]] -name = "cpc_serialization_test" -path = "tests/serialization_tests/cpc.rs" -required-features = ["cpc"] - -[[test]] -name = "frequencies_serialization_test" -path = "tests/serialization_tests/frequencies.rs" -required-features = ["frequencies"] - -[[test]] -name = "hll_serialization_test" -path = "tests/serialization_tests/hll.rs" -required-features = ["hll"] - -[[test]] -name = "tdigest_serialization_test" -path = "tests/serialization_tests/tdigest.rs" -required-features = ["tdigest"] - -[[test]] -name = "theta_serialization_test" -path = "tests/serialization_tests/theta.rs" -required-features = ["theta"] - -[[test]] -name = "tuple_serialization_test" -path = "tests/serialization_tests/tuple.rs" -required-features = ["tuple"] - [dev-dependencies] googletest = { workspace = true } insta = { workspace = true } diff --git a/datasketches/tests/serde_tests.rs b/datasketches/tests/serde_tests.rs new file mode 100644 index 0000000..86ffea3 --- /dev/null +++ b/datasketches/tests/serde_tests.rs @@ -0,0 +1,55 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Serialization compatibility tests grouped by sketch. + +// This target is also compiled without sketch features during feature-matrix checks. +#[allow(dead_code)] +#[path = "serialization_tests/support.rs"] +mod support; + +#[cfg(feature = "bloom")] +#[path = "serialization_tests/bloom.rs"] +mod bloom; + +#[cfg(feature = "countmin")] +#[path = "serialization_tests/countmin.rs"] +mod countmin; + +#[cfg(feature = "cpc")] +#[path = "serialization_tests/cpc.rs"] +mod cpc; + +#[cfg(feature = "frequencies")] +#[path = "serialization_tests/frequencies.rs"] +mod frequencies; + +#[cfg(feature = "hll")] +#[path = "serialization_tests/hll.rs"] +mod hll; + +#[cfg(feature = "tdigest")] +#[path = "serialization_tests/tdigest.rs"] +mod tdigest; + +#[cfg(feature = "theta")] +#[path = "serialization_tests/theta.rs"] +mod theta; + +#[cfg(feature = "tuple")] +#[path = "serialization_tests/tuple.rs"] +mod tuple; diff --git a/datasketches/tests/serialization_tests/bloom.rs b/datasketches/tests/serialization_tests/bloom.rs index aaebecd..966dc8f 100644 --- a/datasketches/tests/serialization_tests/bloom.rs +++ b/datasketches/tests/serialization_tests/bloom.rs @@ -15,13 +15,12 @@ // specific language governing permissions and limitations // under the License. -mod support; - use std::fs; use std::path::PathBuf; use datasketches::bloom::BloomFilter; -use support::serialization_test_data; + +use crate::support::serialization_test_data; fn test_bloom_filter_file(path: PathBuf, expected_num_items: u64, expected_num_hashes: u16) { let bytes = fs::read(&path).unwrap(); diff --git a/datasketches/tests/serialization_tests/countmin.rs b/datasketches/tests/serialization_tests/countmin.rs index 3994651..a7499cd 100644 --- a/datasketches/tests/serialization_tests/countmin.rs +++ b/datasketches/tests/serialization_tests/countmin.rs @@ -15,14 +15,13 @@ // specific language governing permissions and limitations // under the License. -mod support; - use std::fs; use datasketches::countmin::CountMinSketch; use googletest::assert_that; use googletest::prelude::contains_substring; -use support::serialization_test_data; + +use crate::support::serialization_test_data; // This test validates binary format compatibility (deserialize + byte round-trip) for // C++ Count-Min snapshots. It intentionally does not assert estimate equivalence against diff --git a/datasketches/tests/serialization_tests/cpc.rs b/datasketches/tests/serialization_tests/cpc.rs index bd98c89..0475edc 100644 --- a/datasketches/tests/serialization_tests/cpc.rs +++ b/datasketches/tests/serialization_tests/cpc.rs @@ -15,15 +15,14 @@ // specific language governing permissions and limitations // under the License. -mod support; - use std::fs; use std::path::PathBuf; use datasketches::cpc::CpcSketch; use googletest::assert_that; use googletest::prelude::near; -use support::serialization_test_data; + +use crate::support::serialization_test_data; fn test_sketch_file(path: PathBuf, expected_cardinality: usize) { let expected = expected_cardinality as f64; diff --git a/datasketches/tests/serialization_tests/frequencies.rs b/datasketches/tests/serialization_tests/frequencies.rs index 228a5db..5f9372d 100644 --- a/datasketches/tests/serialization_tests/frequencies.rs +++ b/datasketches/tests/serialization_tests/frequencies.rs @@ -15,8 +15,6 @@ // specific language governing permissions and limitations // under the License. -mod support; - use std::fs; use datasketches::codec::SketchBytes; @@ -25,7 +23,8 @@ use datasketches::error::Error; use datasketches::error::ErrorKind; use datasketches::frequencies::FrequentItemValue; use datasketches::frequencies::FrequentItemsSketch; -use support::serialization_test_data; + +use crate::support::serialization_test_data; #[derive(Debug, PartialEq, Eq, Hash)] struct NonCloneSerializableItem(i64); diff --git a/datasketches/tests/serialization_tests/hll.rs b/datasketches/tests/serialization_tests/hll.rs index 2b4684b..dc64a74 100644 --- a/datasketches/tests/serialization_tests/hll.rs +++ b/datasketches/tests/serialization_tests/hll.rs @@ -15,15 +15,14 @@ // specific language governing permissions and limitations // under the License. -mod support; - use std::fs; use std::path::PathBuf; use datasketches::hash_value::natural_extend; use datasketches::hll::HllSketch; use datasketches::hll::HllType; -use support::serialization_test_data; + +use crate::support::serialization_test_data; fn test_sketch_file(path: PathBuf, expected_cardinality: usize, expected_lg_k: u8) { let expected = expected_cardinality as f64; diff --git a/datasketches/tests/serialization_tests/tdigest.rs b/datasketches/tests/serialization_tests/tdigest.rs index 9adb9e3..626843b 100644 --- a/datasketches/tests/serialization_tests/tdigest.rs +++ b/datasketches/tests/serialization_tests/tdigest.rs @@ -15,8 +15,6 @@ // specific language governing permissions and limitations // under the License. -mod support; - use std::fs; use std::path::PathBuf; @@ -24,7 +22,8 @@ use datasketches::tdigest::TDigestMut; use googletest::assert_that; use googletest::prelude::eq; use googletest::prelude::near; -use support::serialization_test_data; + +use crate::support::serialization_test_data; fn test_sketch_file(path: PathBuf, n: u64, with_buffer: bool, is_f32: bool) { let bytes = fs::read(&path).unwrap(); diff --git a/datasketches/tests/serialization_tests/theta.rs b/datasketches/tests/serialization_tests/theta.rs index 118fa24..1154807 100644 --- a/datasketches/tests/serialization_tests/theta.rs +++ b/datasketches/tests/serialization_tests/theta.rs @@ -15,15 +15,14 @@ // specific language governing permissions and limitations // under the License. -mod support; - use std::fs; use std::path::PathBuf; use datasketches::theta::CompactThetaSketch; use googletest::assert_that; use googletest::prelude::near; -use support::serialization_test_data; + +use crate::support::serialization_test_data; fn test_sketch_file(path: PathBuf, expected_cardinality: usize, use_compressed_round_trip: bool) { let expected = expected_cardinality as f64; diff --git a/datasketches/tests/serialization_tests/tuple.rs b/datasketches/tests/serialization_tests/tuple.rs index fd8a740..104ec88 100644 --- a/datasketches/tests/serialization_tests/tuple.rs +++ b/datasketches/tests/serialization_tests/tuple.rs @@ -15,15 +15,14 @@ // specific language governing permissions and limitations // under the License. -mod support; - use std::fs; use std::path::PathBuf; use datasketches::tuple::CompactTupleSketch; use googletest::assert_that; use googletest::prelude::near; -use support::serialization_test_data; + +use crate::support::serialization_test_data; fn test_sketch_file(path: PathBuf, expected_cardinality: usize) { let expected = expected_cardinality as f64; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
