Skip to content

Commit b6e9fab

Browse files
committed
Allow running multiple checks on an assignment context
1 parent 3f7ff18 commit b6e9fab

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

src/handlers/assign/tests/tests_candidates.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct AssignCtx {
1313
teams: Teams,
1414
config: AssignConfig,
1515
issue: Issue,
16-
reviewer_workqueue: ReviewerWorkqueue,
16+
reviewer_workqueue: HashMap<UserId, HashSet<PullRequestNumber>>,
1717
}
1818

1919
impl AssignCtx {
@@ -51,7 +51,7 @@ impl AssignCtx {
5151

5252
fn assign_prs(mut self, user_id: UserId, count: u64) -> Self {
5353
let prs: HashSet<PullRequestNumber> = (0..count).collect();
54-
self.reviewer_workqueue.set_user_prs(user_id, prs);
54+
self.reviewer_workqueue.insert(user_id, prs);
5555
self
5656
}
5757

@@ -89,12 +89,13 @@ impl AssignCtx {
8989
mut self,
9090
names: &[&str],
9191
expected: Result<&[&str], FindReviewerError>,
92-
) -> anyhow::Result<TestContext> {
92+
) -> anyhow::Result<Self> {
9393
let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();
9494

95+
let workqueue = ReviewerWorkqueue::new(self.reviewer_workqueue.clone());
9596
let reviewers = candidate_reviewers_from_names(
9697
self.test_ctx.db_client_mut(),
97-
Arc::new(RwLock::new(self.reviewer_workqueue)),
98+
Arc::new(RwLock::new(workqueue)),
9899
&self.teams,
99100
&self.config,
100101
&self.issue,
@@ -114,7 +115,13 @@ impl AssignCtx {
114115
(Ok(candidates), Err(_)) => panic!("expected Err, got Ok: {candidates:?}"),
115116
(Err(e), Ok(_)) => panic!("expected Ok, got Err: {e}"),
116117
};
117-
Ok(self.test_ctx)
118+
Ok(self)
119+
}
120+
}
121+
122+
impl From<AssignCtx> for TestContext {
123+
fn from(value: AssignCtx) -> Self {
124+
value.test_ctx
118125
}
119126
}
120127

@@ -462,7 +469,7 @@ async fn group_team_user_precedence() {
462469
.check(&["compiler"], Ok(&["user2"]))
463470
.await?;
464471

465-
basic_test(ctx, config, issue().call())
472+
basic_test(ctx.into(), config, issue().call())
466473
.teams(&teams)
467474
.check(&["rust-lang/compiler"], Ok(&["user2"]))
468475
.await
@@ -483,13 +490,10 @@ async fn what_do_slashes_mean() {
483490

484491
run_db_test(|ctx| async move {
485492
// Random slash names should work from groups.
486-
let ctx = basic_test(ctx, config.clone(), issue())
487-
.teams(&teams)
488-
.check(&["foo/bar"], Ok(&["foo-user"]))
489-
.await?;
490-
491493
basic_test(ctx, config, issue())
492494
.teams(&teams)
495+
.check(&["foo/bar"], Ok(&["foo-user"]))
496+
.await?
493497
.check(&["rust-lang-nursery/compiler"], Ok(&["user2"]))
494498
.await
495499
})
@@ -524,18 +528,15 @@ async fn vacation() {
524528

525529
run_db_test(|ctx| async move {
526530
// Test that `r? user` returns a specific error about the user being on vacation.
527-
let ctx = basic_test(ctx, config.clone(), issue().call())
531+
basic_test(ctx, config, issue().call())
528532
.teams(&teams)
529533
.check(
530534
&["jyn514"],
531535
Err(FindReviewerError::ReviewerOffRotation {
532536
username: "jyn514".to_string(),
533537
}),
534538
)
535-
.await?;
536-
537-
basic_test(ctx, config.clone(), issue().call())
538-
.teams(&teams)
539+
.await?
539540
.check(&["bootstrap"], Ok(&["Mark-Simulacrum"]))
540541
.await
541542
})

src/handlers/pr_tracking.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ impl ReviewerWorkqueue {
4343
.map(|prs| prs.len() as u64)
4444
.unwrap_or(0)
4545
}
46-
47-
#[cfg(test)]
48-
pub fn set_user_prs(&mut self, user_id: UserId, prs: HashSet<PullRequestNumber>) {
49-
self.reviewers.insert(user_id, prs);
50-
}
5146
}
5247

5348
pub(super) enum ReviewPrefsInput {

src/tests/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,15 @@ impl TestContext {
121121
}
122122
}
123123

124-
pub(crate) async fn run_db_test<F, Fut>(f: F)
124+
pub(crate) async fn run_db_test<F, Fut, Ctx>(f: F)
125125
where
126126
F: FnOnce(TestContext) -> Fut,
127-
Fut: Future<Output = anyhow::Result<TestContext>>,
127+
Fut: Future<Output = anyhow::Result<Ctx>>,
128+
Ctx: Into<TestContext>,
128129
{
129130
if let Ok(db_url) = std::env::var("TEST_DB_URL") {
130131
let ctx = TestContext::new(&db_url).await;
131-
let ctx = f(ctx).await.expect("Test failed");
132+
let ctx: TestContext = f(ctx).await.expect("Test failed").into();
132133
ctx.finish().await;
133134
} else {
134135
eprintln!("Skipping test because TEST_DB_URL was not passed");

0 commit comments

Comments
 (0)