From 1c3c5ce8caca017c6320eaabdcda9b622a17aa09 Mon Sep 17 00:00:00 2001 From: Harsh Modi Date: Tue, 2 Jan 2024 20:33:57 -0800 Subject: [PATCH] Fix bug in invocation reconstruction --- blade/db/postgres/mod.rs | 14 ++++++++------ blade/routes/test.rs | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/blade/db/postgres/mod.rs b/blade/db/postgres/mod.rs index 2da4fdf..87f1957 100644 --- a/blade/db/postgres/mod.rs +++ b/blade/db/postgres/mod.rs @@ -159,12 +159,15 @@ impl state::DB for Postgres { .select(models::TestRun::as_select()) .load(&mut self.conn)?; - let mut test_artifacts: std::collections::VecDeque<_> = schema::testartifacts::table + let mut test_artifacts: HashMap> = HashMap::new(); + schema::testartifacts::table .select(models::TestArtifact::as_select()) .filter(schema::testartifacts::dsl::invocation_id.eq(id)) .load(&mut self.conn)? - .grouped_by(&test_runs) - .into(); + .into_iter().for_each(|a: models::TestArtifact| { + let v = test_artifacts.entry(a.test_run_id.clone()).or_insert(Vec::new()); + v.push(a); + }); let test_runs = test_runs.grouped_by(&tests); tests.into_iter().zip(test_runs).for_each(|(test, trs)| { ret.tests.insert( @@ -183,10 +186,9 @@ impl state::DB for Postgres { status: state::Status::parse(&tr.status), details: tr.details, duration: std::time::Duration::from_secs_f64(tr.duration_s), - files: test_artifacts - .pop_front() + files: test_artifacts.get_mut(&tr.id) .map(|v| { - v.into_iter() + v.drain(..) .map(|ta| { ( ta.name, diff --git a/blade/routes/test.rs b/blade/routes/test.rs index c7923a2..3102074 100644 --- a/blade/routes/test.rs +++ b/blade/routes/test.rs @@ -79,7 +79,7 @@ fn get_run( } } -#[derive(PartialEq, Params)] +#[derive(PartialEq, Params, Debug)] struct TestParams { target: Option, run: Option,