diff --git a/Cargo.lock b/Cargo.lock index 21d28deb9..0fcebb018 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1281,7 +1281,6 @@ dependencies = [ "assert_matches", "http", "janus_core", - "janus_test_util", "mockito", "prio", "reqwest", @@ -1302,6 +1301,7 @@ dependencies = [ "base64", "bytes", "chrono", + "futures", "hex", "hpke-dispatch", "num_enum", @@ -1314,6 +1314,9 @@ dependencies = [ "serde_json", "thiserror", "tokio", + "tracing", + "tracing-log", + "tracing-subscriber", ] [[package]] @@ -1337,7 +1340,6 @@ dependencies = [ "itertools", "janus_core", "janus_server", - "janus_test_util", "lazy_static", "libc", "mockito", @@ -1377,23 +1379,6 @@ dependencies = [ "warp", ] -[[package]] -name = "janus_test_util" -version = "0.1.0" -dependencies = [ - "assert_matches", - "chrono", - "futures", - "janus_core", - "prio", - "rand", - "ring", - "tokio", - "tracing", - "tracing-log", - "tracing-subscriber", -] - [[package]] name = "js-sys" version = "0.3.57" @@ -1574,7 +1559,6 @@ dependencies = [ "janus_client", "janus_core", "janus_server", - "janus_test_util", "lazy_static", "prio", "rand", diff --git a/Cargo.toml b/Cargo.toml index 3156e6847..2a9e9255f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,3 @@ [workspace] -members = ["janus_core", "janus_client", "janus_server", "monolithic_integration_test", "test_util"] +members = ["janus_core", "janus_client", "janus_server", "monolithic_integration_test"] +resolver = "2" diff --git a/Dockerfile b/Dockerfile index 1af199492..e808c7262 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,6 @@ COPY janus_core /src/janus_core COPY janus_client /src/janus_client COPY janus_server /src/janus_server COPY monolithic_integration_test /src/monolithic_integration_test -COPY test_util /src/test_util COPY db/schema.sql /src/db/schema.sql RUN --mount=type=cache,target=/usr/local/cargo/registry --mount=type=cache,target=/src/target cargo build --release --bin $BINARY --features=prometheus && cp /src/target/release/$BINARY /$BINARY diff --git a/janus_client/Cargo.toml b/janus_client/Cargo.toml index 1d3fb8e3c..e37716cbd 100644 --- a/janus_client/Cargo.toml +++ b/janus_client/Cargo.toml @@ -22,7 +22,6 @@ url = "2.2.2" [dev-dependencies] assert_matches = "1" janus_core = { path = "../janus_core", features = ["test-util"]} -janus_test_util = { path = "../test_util" } mockito = "0.31.0" tracing-log = "0.1.3" tracing-subscriber = { version = "0.3", features = ["std", "env-filter", "fmt"] } diff --git a/janus_client/src/lib.rs b/janus_client/src/lib.rs index 60353b182..d7b08221c 100644 --- a/janus_client/src/lib.rs +++ b/janus_client/src/lib.rs @@ -206,8 +206,11 @@ where mod tests { use super::*; use assert_matches::assert_matches; - use janus_core::{hpke::test_util::generate_hpke_config_and_private_key, message::TaskId}; - use janus_test_util::{install_test_trace_subscriber, MockClock}; + use janus_core::{ + hpke::test_util::generate_hpke_config_and_private_key, + message::TaskId, + test_util::{install_test_trace_subscriber, MockClock}, + }; use mockito::mock; use prio::vdaf::prio3::Prio3; use url::Url; diff --git a/janus_core/Cargo.toml b/janus_core/Cargo.toml index fd3c2a508..9c72d140f 100644 --- a/janus_core/Cargo.toml +++ b/janus_core/Cargo.toml @@ -11,7 +11,7 @@ rust-version = "1.58" [features] database = ["bytes", "postgres-protocol", "postgres-types"] -test-util = [] +test-util = ["assert_matches", "serde_json", "futures", "tracing", "tracing-log", "tracing-subscriber", "tokio/macros", "tokio/sync"] [dependencies] anyhow = "1" @@ -30,6 +30,10 @@ serde = { version = "1.0.138", features = ["derive"] } thiserror = "1.0" tokio = { version = "^1.19", features = ["rt"] } -[dev-dependencies] -assert_matches = "1" -serde_json = "1.0.82" +# Dependencies required only if feature "test-util" is enabled +assert_matches = { version = "1", optional = true } +serde_json = { version = "1.0.82", optional = true } +futures = { version = "0.3.21", optional = true } +tracing = { version = "0.1.34", optional = true } +tracing-log = { version = "0.1.3", optional = true } +tracing-subscriber = { version = "0.3", features = ["std", "env-filter", "fmt"], optional = true } diff --git a/janus_core/src/lib.rs b/janus_core/src/lib.rs index c4b38ea0d..eb754e9c5 100644 --- a/janus_core/src/lib.rs +++ b/janus_core/src/lib.rs @@ -4,6 +4,8 @@ use tokio::task::JoinHandle; pub mod hpke; pub mod message; pub mod task; +#[cfg(feature = "test-util")] +pub mod test_util; pub mod time; /// This trait provides a mockable facade for [`tokio::task::spawn`]. diff --git a/test_util/src/dummy_vdaf.rs b/janus_core/src/test_util/dummy_vdaf.rs similarity index 100% rename from test_util/src/dummy_vdaf.rs rename to janus_core/src/test_util/dummy_vdaf.rs diff --git a/test_util/src/lib.rs b/janus_core/src/test_util/mod.rs similarity index 98% rename from test_util/src/lib.rs rename to janus_core/src/test_util/mod.rs index f456f0a42..b23d15ca9 100644 --- a/test_util/src/lib.rs +++ b/janus_core/src/test_util/mod.rs @@ -1,8 +1,8 @@ -use assert_matches::assert_matches; -use janus_core::{ +use crate::{ message::{Duration, Nonce, Time}, time::Clock, }; +use assert_matches::assert_matches; use prio::{ codec::Encode, vdaf::{self, PrepareTransition, VdafError}, @@ -17,7 +17,7 @@ pub mod dummy_vdaf; pub mod runtime; /// The Janus database schema. -pub static SCHEMA: &str = include_str!("../../db/schema.sql"); +pub static SCHEMA: &str = include_str!("../../../db/schema.sql"); /// This macro injects definitions of `DbHandle` and `ephemeral_datastore()`, for use in tests. /// It should be invoked once per binary target, and then `ephemeral_datastore()` can be called @@ -168,7 +168,7 @@ macro_rules! define_ephemeral_datastore { ::tracing::trace!("Postgres container is up with URL {}", connection_string); // Create a random (ephemeral) key. - let datastore_key_bytes = ::janus_test_util::generate_aead_key_bytes(); + let datastore_key_bytes = ::janus_core::test_util::generate_aead_key_bytes(); DbHandle{ _db_container: db_container, diff --git a/test_util/src/runtime.rs b/janus_core/src/test_util/runtime.rs similarity index 99% rename from test_util/src/runtime.rs rename to janus_core/src/test_util/runtime.rs index 7023ad8e7..566371104 100644 --- a/test_util/src/runtime.rs +++ b/janus_core/src/test_util/runtime.rs @@ -1,5 +1,5 @@ +use crate::Runtime; use futures::FutureExt; -use janus_core::Runtime; use std::{ collections::HashMap, future::Future, diff --git a/janus_server/Cargo.toml b/janus_server/Cargo.toml index 5ee19cfc5..273bfd200 100644 --- a/janus_server/Cargo.toml +++ b/janus_server/Cargo.toml @@ -11,7 +11,11 @@ tokio-console = ["console-subscriber"] jaeger = ["tracing-opentelemetry", "opentelemetry-jaeger"] otlp = ["tracing-opentelemetry", "opentelemetry-otlp", "opentelemetry-semantic-conventions", "tonic"] prometheus = ["opentelemetry-prometheus", "dep:prometheus"] +<<<<<<< HEAD test-util = ["dep:janus_test_util", "dep:lazy_static", "dep:testcontainers"] +======= +test-util = ["janus_core/test-util", "lazy_static", "testcontainers"] +>>>>>>> 8a0ce54 (Move `test_util` crate to `janus_core`) [dependencies] anyhow = "1" @@ -62,6 +66,10 @@ url = { version = "2.2.2", features = ["serde"] } uuid = { version = "1.1.2", features = ["v4"] } warp = { version = "^0.3", features = ["tls"] } +# Optional dependencies enabled by feature "test-util" +lazy_static = { version = "1", optional = true } +testcontainers = { version = "0.14.0", optional = true } + [dev-dependencies] assert_matches = "1" hex = { version = "0.4.3", features = ["serde"] } diff --git a/janus_server/src/aggregator.rs b/janus_server/src/aggregator.rs index eafe58cf2..f51ebdfc1 100644 --- a/janus_server/src/aggregator.rs +++ b/janus_server/src/aggregator.rs @@ -70,7 +70,7 @@ use warp::{ }; #[cfg(test)] -use janus_test_util::dummy_vdaf; +use janus_core::test_util::dummy_vdaf; #[cfg(test)] use prio::vdaf::VdafError; @@ -2091,8 +2091,8 @@ mod tests { HpkePrivateKey, Label, }, message::{Duration, HpkeCiphertext, HpkeConfig, TaskId, Time}, + test_util::{dummy_vdaf, install_test_trace_subscriber, run_vdaf, MockClock}, }; - use janus_test_util::{dummy_vdaf, install_test_trace_subscriber, run_vdaf, MockClock}; use prio::{ codec::Decode, field::Field64, diff --git a/janus_server/src/aggregator/aggregate_share.rs b/janus_server/src/aggregator/aggregate_share.rs index e89cea0b2..d1a69eaaa 100644 --- a/janus_server/src/aggregator/aggregate_share.rs +++ b/janus_server/src/aggregator/aggregate_share.rs @@ -85,7 +85,7 @@ impl CollectJobDriver { #[cfg(test)] VdafInstance::Fake => { - type FakeVdaf = janus_test_util::dummy_vdaf::VdafWithAggregationParameter; + type FakeVdaf = janus_core::test_util::dummy_vdaf::VdafWithAggregationParameter; const VERIFY_KEY_LENGTH: usize = FakeVdaf::VERIFY_KEY_LENGTH; self.step_collect_job_generic::( datastore, @@ -438,14 +438,14 @@ mod tests { use assert_matches::assert_matches; use janus_core::{ message::{Duration, HpkeCiphertext, HpkeConfigId, Interval, Nonce, Report, Role, TaskId}, + test_util::{ + dummy_vdaf::{AggregateShare, OutputShare, VdafWithAggregationParameter}, + install_test_trace_subscriber, + runtime::TestRuntimeManager, + MockClock, + }, Runtime, }; - use janus_test_util::{ - dummy_vdaf::{AggregateShare, OutputShare, VdafWithAggregationParameter}, - install_test_trace_subscriber, - runtime::TestRuntimeManager, - MockClock, - }; use mockito::mock; use std::str; use url::Url; diff --git a/janus_server/src/aggregator/aggregation_job_creator.rs b/janus_server/src/aggregator/aggregation_job_creator.rs index ef26c32a1..ad0b234a1 100644 --- a/janus_server/src/aggregator/aggregation_job_creator.rs +++ b/janus_server/src/aggregator/aggregation_job_creator.rs @@ -35,7 +35,10 @@ pub trait VdafHasAggregationParameter: private::Sealed {} impl VdafHasAggregationParameter for prio::vdaf::poplar1::Poplar1 {} #[cfg(test)] -impl VdafHasAggregationParameter for janus_test_util::dummy_vdaf::VdafWithAggregationParameter {} +impl VdafHasAggregationParameter + for janus_core::test_util::dummy_vdaf::VdafWithAggregationParameter +{ +} mod private { pub trait Sealed {} @@ -43,7 +46,7 @@ mod private { impl Sealed for prio::vdaf::poplar1::Poplar1 {} #[cfg(test)] - impl Sealed for janus_test_util::dummy_vdaf::VdafWithAggregationParameter {} + impl Sealed for janus_core::test_util::dummy_vdaf::VdafWithAggregationParameter {} } pub struct AggregationJobCreator { @@ -409,11 +412,11 @@ mod tests { use janus_core::{ message::{Interval, Nonce, Report, Role, TaskId, Time}, task::VdafInstance, + test_util::{ + dummy_vdaf::VdafWithAggregationParameter, install_test_trace_subscriber, MockClock, + }, time::Clock, }; - use janus_test_util::{ - dummy_vdaf::VdafWithAggregationParameter, install_test_trace_subscriber, MockClock, - }; use prio::{ codec::ParameterizedDecode, vdaf::{ diff --git a/janus_server/src/aggregator/aggregation_job_driver.rs b/janus_server/src/aggregator/aggregation_job_driver.rs index 1927c1f7e..4adc7f96b 100644 --- a/janus_server/src/aggregator/aggregation_job_driver.rs +++ b/janus_server/src/aggregator/aggregation_job_driver.rs @@ -803,11 +803,11 @@ mod tests { }, message::{Duration, HpkeConfig, Interval, Nonce, NonceChecksum, Report, Role, TaskId}, task::VdafInstance, + test_util::{ + install_test_trace_subscriber, run_vdaf, runtime::TestRuntimeManager, MockClock, + }, Runtime, }; - use janus_test_util::{ - install_test_trace_subscriber, run_vdaf, runtime::TestRuntimeManager, MockClock, - }; use mockito::mock; use prio::{ codec::Encode, diff --git a/janus_server/src/binary_utils/job_driver.rs b/janus_server/src/binary_utils/job_driver.rs index 604acde4f..93fb7e651 100644 --- a/janus_server/src/binary_utils/job_driver.rs +++ b/janus_server/src/binary_utils/job_driver.rs @@ -200,8 +200,10 @@ where mod tests { use super::*; use crate::{message::AggregationJobId, task::VdafInstance}; - use janus_core::message::TaskId; - use janus_test_util::{install_test_trace_subscriber, runtime::TestRuntimeManager, MockClock}; + use janus_core::{ + message::TaskId, + test_util::{install_test_trace_subscriber, runtime::TestRuntimeManager, MockClock}, + }; use tokio::sync::Mutex; #[tokio::test] diff --git a/janus_server/src/datastore.rs b/janus_server/src/datastore.rs index abd8f18d2..4bc9945c2 100644 --- a/janus_server/src/datastore.rs +++ b/janus_server/src/datastore.rs @@ -2918,7 +2918,7 @@ pub mod test_util { use super::{Crypter, Datastore}; use janus_core::time::Clock; - janus_test_util::define_ephemeral_datastore!(); + janus_core::define_ephemeral_datastore!(); } #[cfg(test)] @@ -2938,10 +2938,10 @@ mod tests { use janus_core::{ hpke::{self, associated_data_for_aggregate_share, HpkeApplicationInfo, Label}, message::{Duration, ExtensionType, HpkeConfigId, Interval, Role, Time}, - }; - use janus_test_util::{ - dummy_vdaf::{self, VdafWithAggregationParameter}, - generate_aead_key, install_test_trace_subscriber, MockClock, + test_util::{ + dummy_vdaf::{self, VdafWithAggregationParameter}, + generate_aead_key, install_test_trace_subscriber, MockClock, + }, }; use prio::{ field::{Field128, Field64}, diff --git a/janus_server/tests/server_shutdown.rs b/janus_server/tests/server_shutdown.rs index 473509b67..d31dcc868 100644 --- a/janus_server/tests/server_shutdown.rs +++ b/janus_server/tests/server_shutdown.rs @@ -22,7 +22,7 @@ use std::{ }; use wait_timeout::ChildExt; -janus_test_util::define_ephemeral_datastore!(); +janus_core::define_ephemeral_datastore!(); /// Try to find an open port by binding to an ephemeral port, saving the port /// number, and closing the listening socket. This may still fail due to race diff --git a/monolithic_integration_test/Cargo.toml b/monolithic_integration_test/Cargo.toml index dc757febd..21e44c712 100644 --- a/monolithic_integration_test/Cargo.toml +++ b/monolithic_integration_test/Cargo.toml @@ -10,7 +10,7 @@ publish = false chrono = "0.4.19" deadpool-postgres = "0.10.1" futures = "0.3.21" -janus_core = { path = "../janus_core" } +janus_core = { path = "../janus_core", features = ["test-util"] } janus_client = { path = "../janus_client" } janus_server = { path = "../janus_server", features = ["test-util"] } lazy_static = "1" @@ -19,7 +19,6 @@ rand = "0.8" reqwest = { version = "0.11.11", default-features = false, features = ["rustls-tls"] } ring = "0.16.20" testcontainers = "0.14.0" -janus_test_util = { path = "../test_util" } tokio = { version = "^1.19", features = ["full", "tracing"] } tokio-postgres = { version = "0.7.6", features = ["with-chrono-0_4"] } tracing = "0.1.34" diff --git a/monolithic_integration_test/tests/integration_test.rs b/monolithic_integration_test/tests/integration_test.rs index 34ab20a67..9cd5cda94 100644 --- a/monolithic_integration_test/tests/integration_test.rs +++ b/monolithic_integration_test/tests/integration_test.rs @@ -6,6 +6,7 @@ use janus_core::{ }, message::{Duration, HpkeConfig, Interval, Role, TaskId}, task::VdafInstance, + test_util::install_test_trace_subscriber, time::{Clock, RealClock}, TokioRuntime, }; @@ -19,7 +20,6 @@ use janus_server::{ message::{CollectReq, CollectResp}, task::{test_util::generate_aggregator_auth_token, Task, PRIO3_AES128_VERIFY_KEY_LENGTH}, }; -use janus_test_util::install_test_trace_subscriber; use prio::{ codec::{Decode, Encode}, field::Field64, @@ -46,7 +46,7 @@ use tokio::{ }; use url::Url; -janus_test_util::define_ephemeral_datastore!(); +janus_core::define_ephemeral_datastore!(); #[tokio::test(flavor = "multi_thread")] async fn end_to_end() { diff --git a/test_util/Cargo.toml b/test_util/Cargo.toml deleted file mode 100644 index 207899424..000000000 --- a/test_util/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "janus_test_util" -version = "0.1.0" -edition = "2021" -license = "MPL-2.0" -rust-version = "1.58" -publish = false - -[dependencies] -assert_matches = "1" -chrono = "0.4" -futures = "0.3.21" -janus_core = { path = "../janus_core" } -prio = "0.8.0" -rand = "0.8" -ring = "0.16.20" -tracing = "0.1.34" -tracing-log = "0.1.3" -tracing-subscriber = { version = "0.3", features = ["std", "env-filter", "fmt"] } -tokio = { version = "^1.19", features = ["rt", "sync"] } - -[dev-dependencies] -tokio = { version = "*", features = ["macros"] }