Skip to content

Commit

Permalink
Move test_util crate to janus_core
Browse files Browse the repository at this point in the history
Removes the `test_util` crate, relocating the items it defines to a
`test_util` module in `janus_core`, gated by the `test-util` feature. We
also set `resolver = "2"` in the top-level `Cargo.toml`, because
otherwise crate features get unified between dependencies and
dev-dependencies, which cause the release variants of our binary targets
to be built with the `test-util` feature (and indeed, before this PR, we
were building `tokio` with `test-util` all the time, too!). See [1] for
details.

[1]: rust-lang/cargo#4866
  • Loading branch information
tgeoghegan committed Jul 7, 2022
1 parent f81bbcf commit 5a92d88
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 86 deletions.
24 changes: 4 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion janus_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
7 changes: 5 additions & 2 deletions janus_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions janus_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }
2 changes: 2 additions & 0 deletions janus_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions test_util/src/lib.rs → janus_core/src/test_util/mod.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Runtime;
use futures::FutureExt;
use janus_core::Runtime;
use std::{
collections::HashMap,
future::Future,
Expand Down
8 changes: 8 additions & 0 deletions janus_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions janus_server/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions janus_server/src/aggregator/aggregate_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl CollectJobDriver {

#[cfg(test)]
VdafInstance::Fake => {
type FakeVdaf = janus_test_util::dummy_vdaf::VdafWithAggregationParameter<u8>;
type FakeVdaf = janus_core::test_util::dummy_vdaf::VdafWithAggregationParameter<u8>;
const VERIFY_KEY_LENGTH: usize = FakeVdaf::VERIFY_KEY_LENGTH;
self.step_collect_job_generic::<VERIFY_KEY_LENGTH, C, FakeVdaf>(
datastore,
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions janus_server/src/aggregator/aggregation_job_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ pub trait VdafHasAggregationParameter: private::Sealed {}
impl<I, P, const L: usize> VdafHasAggregationParameter for prio::vdaf::poplar1::Poplar1<I, P, L> {}

#[cfg(test)]
impl VdafHasAggregationParameter for janus_test_util::dummy_vdaf::VdafWithAggregationParameter<u8> {}
impl VdafHasAggregationParameter
for janus_core::test_util::dummy_vdaf::VdafWithAggregationParameter<u8>
{
}

mod private {
pub trait Sealed {}

impl<I, P, const L: usize> Sealed for prio::vdaf::poplar1::Poplar1<I, P, L> {}

#[cfg(test)]
impl Sealed for janus_test_util::dummy_vdaf::VdafWithAggregationParameter<u8> {}
impl Sealed for janus_core::test_util::dummy_vdaf::VdafWithAggregationParameter<u8> {}
}

pub struct AggregationJobCreator<C: Clock> {
Expand Down Expand Up @@ -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::{
Expand Down
6 changes: 3 additions & 3 deletions janus_server/src/aggregator/aggregation_job_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions janus_server/src/binary_utils/job_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions janus_server/src/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion janus_server/tests/server_shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions monolithic_integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions monolithic_integration_test/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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,
Expand All @@ -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() {
Expand Down
Loading

0 comments on commit 5a92d88

Please sign in to comment.