From 193eae1b412717cc7c6a114d379d8cb594cef56e Mon Sep 17 00:00:00 2001 From: Tim Geoghegan Date: Wed, 19 Apr 2023 14:05:08 -0700 Subject: [PATCH] Update remaining datastore tests --- aggregator_core/src/datastore.rs | 158 +++++++++++++++++-------------- 1 file changed, 86 insertions(+), 72 deletions(-) diff --git a/aggregator_core/src/datastore.rs b/aggregator_core/src/datastore.rs index 1433b5113..7f0ab1432 100644 --- a/aggregator_core/src/datastore.rs +++ b/aggregator_core/src/datastore.rs @@ -5409,8 +5409,7 @@ mod tests { ReportAggregationState, SqlInterval, }, test_util::{ - ephemeral_datastore, ephemeral_datastore_max_schema_version, generate_aead_key, - EphemeralDatastore, + ephemeral_datastore_max_schema_version, generate_aead_key, EphemeralDatastore, }, Crypter, Datastore, Error, Transaction, }, @@ -5593,10 +5592,10 @@ mod tests { assert_eq!(want_tasks, got_tasks); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn get_task_metrics() { + async fn get_task_metrics(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; ds.run_tx(|tx| { @@ -5728,10 +5727,10 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn get_task_ids() { + async fn get_task_ids(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; ds.run_tx(|tx| { @@ -5768,10 +5767,10 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn roundtrip_report() { + async fn roundtrip_report(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let task = TaskBuilder::new( @@ -5869,10 +5868,10 @@ mod tests { assert_matches!(result, Err(Error::MutationTargetAlreadyExists)); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn report_not_found() { + async fn report_not_found(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let rslt = ds @@ -5892,10 +5891,10 @@ mod tests { assert_eq!(rslt, None); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn get_unaggregated_client_report_ids_for_task() { + async fn get_unaggregated_client_report_ids_for_task(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let time_precision = Duration::from_seconds(1000); @@ -6050,10 +6049,12 @@ mod tests { ); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn get_unaggregated_client_report_ids_with_agg_param_for_task() { + async fn get_unaggregated_client_report_ids_with_agg_param_for_task( + ephemeral_datastore: EphemeralDatastore, + ) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let task = TaskBuilder::new( @@ -6312,10 +6313,10 @@ mod tests { assert_eq!(got_reports, expected_reports); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn count_client_reports_for_interval() { + async fn count_client_reports_for_interval(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let task = TaskBuilder::new( @@ -6423,10 +6424,10 @@ mod tests { assert_eq!(no_reports_task_report_count, 0); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn count_client_reports_for_batch_id() { + async fn count_client_reports_for_batch_id(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let task = TaskBuilder::new( @@ -6561,10 +6562,10 @@ mod tests { assert_eq!(report_count, 2); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn roundtrip_report_share() { + async fn roundtrip_report_share(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let task = TaskBuilder::new( @@ -6657,10 +6658,10 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn roundtrip_aggregation_job() { + async fn roundtrip_aggregation_job(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; // We use a dummy VDAF & fixed-size task for this test, to better exercise the @@ -6836,12 +6837,12 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn aggregation_job_acquire_release() { + async fn aggregation_job_acquire_release(ephemeral_datastore: EphemeralDatastore) { // Setup: insert a few aggregation jobs. install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; const AGGREGATION_JOB_COUNT: usize = 10; @@ -7124,10 +7125,10 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn aggregation_job_not_found() { + async fn aggregation_job_not_found(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let rslt = ds @@ -7169,11 +7170,11 @@ mod tests { assert_matches!(rslt, Err(Error::MutationTargetNotFound)); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn get_aggregation_jobs_for_task() { + async fn get_aggregation_jobs_for_task(ephemeral_datastore: EphemeralDatastore) { // Setup. install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; // We use a dummy VDAF & fixed-size task for this test, to better exercise the @@ -7421,10 +7422,10 @@ mod tests { } } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn check_report_aggregation_exists() { + async fn check_report_aggregation_exists(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let task = TaskBuilder::new( task::QueryType::TimeInterval, @@ -7546,10 +7547,10 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn report_aggregation_not_found() { + async fn report_aggregation_not_found(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let vdaf = Arc::new(dummy_vdaf::Vdaf::default()); @@ -7591,10 +7592,10 @@ mod tests { assert_matches!(rslt, Err(Error::MutationTargetNotFound)); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn get_report_aggregations_for_aggregation_job() { + async fn get_report_aggregations_for_aggregation_job(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let report_id = ReportId::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); @@ -7739,8 +7740,9 @@ mod tests { .is_err()); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn get_collection_job() { + async fn get_collection_job(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); let task = TaskBuilder::new( @@ -7761,7 +7763,6 @@ mod tests { .unwrap(); let aggregation_param = AggregationParam(13); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; ds.run_tx(|tx| { @@ -7854,12 +7855,12 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn update_collection_jobs() { + async fn update_collection_jobs(ephemeral_datastore: EphemeralDatastore) { // Setup: write collection jobs to the datastore. install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; let task = TaskBuilder::new( @@ -8117,11 +8118,13 @@ mod tests { .unwrap() } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn time_interval_collection_job_acquire_release_happy_path() { + async fn time_interval_collection_job_acquire_release_happy_path( + ephemeral_datastore: EphemeralDatastore, + ) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let task_id = random(); @@ -8254,11 +8257,13 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn fixed_size_collection_job_acquire_release_happy_path() { + async fn fixed_size_collection_job_acquire_release_happy_path( + ephemeral_datastore: EphemeralDatastore, + ) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let task_id = random(); @@ -8380,11 +8385,13 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn collection_job_acquire_no_aggregation_job_with_task_id() { + async fn collection_job_acquire_no_aggregation_job_with_task_id( + ephemeral_datastore: EphemeralDatastore, + ) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let task_id = random(); @@ -8431,11 +8438,13 @@ mod tests { .await; } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn collection_job_acquire_no_aggregation_job_with_agg_param() { + async fn collection_job_acquire_no_aggregation_job_with_agg_param( + ephemeral_datastore: EphemeralDatastore, + ) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let task_id = random(); @@ -8485,11 +8494,13 @@ mod tests { .await; } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn collection_job_acquire_report_shares_outside_interval() { + async fn collection_job_acquire_report_shares_outside_interval( + ephemeral_datastore: EphemeralDatastore, + ) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let task_id = random(); @@ -8549,11 +8560,11 @@ mod tests { .await; } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn collection_job_acquire_release_job_finished() { + async fn collection_job_acquire_release_job_finished(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let task_id = random(); @@ -8613,11 +8624,13 @@ mod tests { .await; } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn collection_job_acquire_release_aggregation_job_in_progress() { + async fn collection_job_acquire_release_aggregation_job_in_progress( + ephemeral_datastore: EphemeralDatastore, + ) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let task_id = random(); @@ -8700,11 +8713,11 @@ mod tests { .await; } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn collection_job_acquire_job_max() { + async fn collection_job_acquire_job_max(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let task_id = random(); @@ -8855,11 +8868,11 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn collection_job_acquire_state_filtering() { + async fn collection_job_acquire_state_filtering(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let task_id = random(); @@ -8993,11 +9006,11 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn roundtrip_batch_aggregation_time_interval() { + async fn roundtrip_batch_aggregation_time_interval(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; ds.run_tx(|tx| { @@ -9210,11 +9223,11 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn roundtrip_batch_aggregation_fixed_size() { + async fn roundtrip_batch_aggregation_fixed_size(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; ds.run_tx(|tx| { @@ -9340,11 +9353,11 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn roundtrip_aggregate_share_job() { + async fn roundtrip_aggregate_share_job(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(MockClock::default()).await; ds.run_tx(|tx| { @@ -9449,12 +9462,12 @@ mod tests { .unwrap(); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn roundtrip_outstanding_batch() { + async fn roundtrip_outstanding_batch(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let (task_id, batch_id) = ds @@ -9737,12 +9750,12 @@ mod tests { } } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn delete_expired_client_reports() { + async fn delete_expired_client_reports(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let vdaf = dummy_vdaf::Vdaf::new(); @@ -9868,12 +9881,12 @@ mod tests { assert_eq!(want_report_ids, got_report_ids); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn delete_expired_aggregation_artifacts() { + async fn delete_expired_aggregation_artifacts(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; let vdaf = dummy_vdaf::Vdaf::new(); @@ -10612,12 +10625,12 @@ mod tests { assert_eq!(want_report_ids, got_report_ids); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn delete_expired_collection_artifacts() { + async fn delete_expired_collection_artifacts(ephemeral_datastore: EphemeralDatastore) { install_test_trace_subscriber(); let clock = MockClock::default(); - let ephemeral_datastore = ephemeral_datastore().await; let ds = ephemeral_datastore.datastore(clock.clone()).await; // Setup. @@ -11167,9 +11180,10 @@ mod tests { assert_eq!(want_outstanding_batch_ids, got_outstanding_batch_ids); } + #[rstest_reuse::apply(schema_versions_template)] #[tokio::test] - async fn roundtrip_interval_sql() { - let ephemeral_datastore = ephemeral_datastore().await; + async fn roundtrip_interval_sql(ephemeral_datastore: EphemeralDatastore) { + install_test_trace_subscriber(); let datastore = ephemeral_datastore.datastore(MockClock::default()).await; datastore