Skip to content

Commit

Permalink
Additional YAML serialization format tests (#3062)
Browse files Browse the repository at this point in the history
* Add deserializationt tests of metrics config

* Fix compilation of aggregator package by itself

* Add query type deserialization test case

* Add a YAML deserialization test for VdafInstance
  • Loading branch information
divergentdave authored Apr 25, 2024
1 parent 06acb8e commit ee809a1
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ janus_aggregator = { path = ".", features = ["fpvec_bounded_l2", "test-util"] }
janus_aggregator_core = { workspace = true, features = ["test-util"] }
mockito = { workspace = true }
opentelemetry_sdk = { workspace = true, features = ["testing"] }
prio = { workspace = true, features = ["multithreaded"] }
rstest.workspace = true
tempfile = { workspace = true }
tokio = { workspace = true, features = ["test-util"] } # ensure this remains compatible with the non-dev dependency
Expand Down
2 changes: 1 addition & 1 deletion aggregator/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use {
#[cfg(all(tokio_unstable, feature = "prometheus"))]
pub(crate) mod tokio_runtime;

#[cfg(all(test, feature = "prometheus"))]
#[cfg(test)]
mod tests;

/// Errors from initializing metrics provider, registry, and exporter.
Expand Down
53 changes: 53 additions & 0 deletions aggregator/src/metrics/tests/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use crate::metrics::{
MetricsConfiguration, MetricsExporterConfiguration, OtlpExporterConfiguration,
};

#[test]
fn metrics_configuration_serde() {
let config = serde_yaml::from_str::<MetricsConfiguration>("---").unwrap();
assert_eq!(
config,
MetricsConfiguration {
exporter: None,
tokio: None
}
);

let config = serde_yaml::from_str::<MetricsConfiguration>(
"---
exporter:
prometheus:
host: 0.0.0.0
port: 9464",
)
.unwrap();
assert_eq!(
config,
MetricsConfiguration {
exporter: Some(MetricsExporterConfiguration::Prometheus {
host: Some("0.0.0.0".into()),
port: Some(9464),
}),
tokio: None,
}
);

let config = serde_yaml::from_str::<MetricsConfiguration>(
"---
exporter:
otlp:
endpoint: https://example.com/",
)
.unwrap();
assert_eq!(
config,
MetricsConfiguration {
exporter: Some(MetricsExporterConfiguration::Otlp(
OtlpExporterConfiguration {
endpoint: "https://example.com/".into()
}
)),
tokio: None
}
);
}
3 changes: 3 additions & 0 deletions aggregator/src/metrics/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod config;
#[cfg(feature = "prometheus")]
mod prometheus;
File renamed without changes.
12 changes: 12 additions & 0 deletions aggregator_core/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1939,5 +1939,17 @@ mod tests {
batch_time_window_size: None,
})
);
assert_matches!(
serde_yaml::from_str(
"---
!FixedSize
max_batch_size: 10
batch_time_window_size: 3600"
),
Ok(QueryType::FixedSize {
max_batch_size: Some(10),
batch_time_window_size: Some(duration),
}) => assert_eq!(duration, Duration::from_seconds(3600))
);
}
}
11 changes: 11 additions & 0 deletions core/src/vdaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ macro_rules! vdaf_dispatch {
#[cfg(test)]
mod tests {
use super::VdafInstance;
use assert_matches::assert_matches;
use serde_test::{assert_tokens, Token};

#[test]
Expand Down Expand Up @@ -666,5 +667,15 @@ mod tests {
variant: "FakeFailsPrepStep",
}],
);

// Backwards compatibility
assert_matches!(
serde_yaml::from_str(
"---
!Prio3Sum
bits: 12"
),
Ok(VdafInstance::Prio3Sum { bits: 12 })
);
}
}

0 comments on commit ee809a1

Please sign in to comment.