Skip to content

Commit

Permalink
test-renderers: log universe construction times.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Jul 19, 2024
1 parent 9e86526 commit f7b89d1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
31 changes: 28 additions & 3 deletions test-renderers/src/harness.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::{btree_map, BTreeMap, HashSet};
use std::future::Future;
use std::io::Write as _;
use std::path::PathBuf;
use std::process::ExitCode;
Expand All @@ -25,11 +26,35 @@ use crate::{

type BoxedTestFn = Box<dyn Fn(RenderTestContext) -> BoxFuture<'static, ()> + Send + Sync>;

/// Wrapper for a `Future` which produces a `Universe` that may be used by multiple
/// render tests (and should not be mutated).
#[derive(Clone, Debug)]
#[allow(clippy::exhaustive_structs)]
pub struct UniverseFuture {
pub label: String,
pub future: Shared<BoxFuture<'static, Arc<Universe>>>,
label: String,
future: Shared<BoxFuture<'static, Arc<Universe>>>,
}
impl UniverseFuture {
pub fn new(label: &str, f: impl Future<Output = Arc<Universe>> + Send + 'static) -> Self {
let label = label.to_owned();
let label2 = label.clone();

let boxed: BoxFuture<'static, Arc<Universe>> = Box::pin(async move {
let start_time = Instant::now();
let universe = f.await;
let elapsed = start_time.elapsed();
log::trace!(
"universe {label2} ready in {elapsed}",
elapsed = elapsed.refmt(&ConciseDebug)
);
universe
});

UniverseFuture {
label,
future: boxed.shared(),
}
}
}
impl PartialEq for UniverseFuture {
fn eq(&self, other: &Self) -> bool {
Expand Down Expand Up @@ -321,7 +346,7 @@ where
async {
let test_id_tc = test_id.clone();
let comparison_log_tc = comparison_log.clone();
// This handle serves to act as a catch_unwind for the test case itself.
// This spawned task acts as a catch_unwind for the test case itself.
let test_case_handle = tokio::spawn(async move {
let context = RenderTestContext {
test_id: test_id_tc,
Expand Down
6 changes: 1 addition & 5 deletions test-renderers/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ pub fn u(
label: &str,
f: impl Future<Output = Arc<Universe>> + Send + 'static,
) -> Option<UniverseFuture> {
let boxed: BoxFuture<'static, Arc<Universe>> = Box::pin(f);
Some(UniverseFuture {
label: label.to_owned(),
future: boxed.shared(),
})
Some(UniverseFuture::new(label, f))
}

// --- Test cases ---------------------------------------------------------------------------------
Expand Down

0 comments on commit f7b89d1

Please sign in to comment.