Skip to content

Commit 07edfbd

Browse files
authored
Merge pull request #2196 from Jamesbarford/chore/modify-try-commit-type
Chore; make `tag` optional for Try benchmark requests
2 parents 62972dc + 317f4b5 commit 07edfbd

File tree

4 files changed

+47
-36
lines changed

4 files changed

+47
-36
lines changed

database/src/lib.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ impl<'a> tokio_postgres::types::FromSql<'a> for BenchmarkRequestStatus {
842842
pub enum BenchmarkRequestType {
843843
/// A Try commit
844844
Try {
845-
sha: String,
845+
sha: Option<String>,
846846
parent_sha: Option<String>,
847847
pr: u32,
848848
},
@@ -915,7 +915,7 @@ impl BenchmarkRequest {
915915
}
916916

917917
pub fn create_try(
918-
sha: &str,
918+
sha: Option<&str>,
919919
parent_sha: Option<&str>,
920920
pr: u32,
921921
created_at: DateTime<Utc>,
@@ -926,7 +926,7 @@ impl BenchmarkRequest {
926926
Self {
927927
commit_type: BenchmarkRequestType::Try {
928928
pr,
929-
sha: sha.to_string(),
929+
sha: sha.map(|it| it.to_string()),
930930
parent_sha: parent_sha.map(|it| it.to_string()),
931931
},
932932
created_at,
@@ -962,10 +962,11 @@ impl BenchmarkRequest {
962962

963963
/// Get either the `sha` for a `try` or `master` commit or a `tag` for a
964964
/// `release`
965-
pub fn tag(&self) -> &str {
965+
pub fn tag(&self) -> Option<&str> {
966966
match &self.commit_type {
967-
BenchmarkRequestType::Try { sha, .. } | BenchmarkRequestType::Master { sha, .. } => sha,
968-
BenchmarkRequestType::Release { tag } => tag,
967+
BenchmarkRequestType::Try { sha, .. } => sha.as_deref(),
968+
BenchmarkRequestType::Master { sha, .. } => Some(sha),
969+
BenchmarkRequestType::Release { tag } => Some(tag),
969970
}
970971
}
971972

@@ -984,10 +985,7 @@ impl BenchmarkRequest {
984985

985986
pub fn parent_sha(&self) -> Option<&str> {
986987
match &self.commit_type {
987-
BenchmarkRequestType::Try { parent_sha, .. } => match parent_sha {
988-
Some(parent_sha) => Some(parent_sha),
989-
_ => None,
990-
},
988+
BenchmarkRequestType::Try { parent_sha, .. } => parent_sha.as_deref(),
991989
BenchmarkRequestType::Master { parent_sha, .. } => Some(parent_sha),
992990
BenchmarkRequestType::Release { tag: _ } => None,
993991
}

database/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ mod tests {
409409
);
410410

411411
let try_benchmark_request = BenchmarkRequest::create_try(
412-
"b-sha-2",
412+
Some("b-sha-2"),
413413
Some("parent-sha-2"),
414414
32,
415415
time,
@@ -457,7 +457,7 @@ mod tests {
457457
);
458458

459459
let try_benchmark_request = BenchmarkRequest::create_try(
460-
"b-sha-2",
460+
Some("b-sha-2"),
461461
Some("parent-sha-2"),
462462
32,
463463
time,

database/src/pool/postgres.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ static MIGRATIONS: &[&str] = &[
301301
);
302302
CREATE INDEX IF NOT EXISTS benchmark_request_status_idx on benchmark_request (status) WHERE status != 'completed';
303303
"#,
304+
// Remove that tag cannot be NULL
305+
r#"ALTER TABLE benchmark_request ALTER COLUMN tag DROP NOT NULL;"#,
306+
// Prevent multiple try commits without a `sha` and the same `pr` number
307+
// being added to the table
308+
r#"CREATE UNIQUE INDEX benchmark_request_pr_commit_type_idx ON benchmark_request (pr, commit_type) WHERE status != 'completed';"#,
304309
];
305310

306311
#[async_trait::async_trait]
@@ -1457,7 +1462,7 @@ where
14571462
match commit_type {
14581463
"try" => {
14591464
let mut try_benchmark = BenchmarkRequest::create_try(
1460-
tag,
1465+
Some(tag),
14611466
parent_sha,
14621467
pr.unwrap() as u32,
14631468
created_at,

site/src/job_queue.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,16 @@ fn sort_benchmark_requests(done: &HashSet<String>, request_queue: &mut [Benchmar
182182
)
183183
});
184184
for c in level {
185-
done.insert(c.tag().to_string());
185+
// As the only `commit_type` that will not have a `tag` is a `Try`
186+
// with the status of `AwaitingArtifacts` and we have asserted above
187+
// that all of the statuses of the benchmark requests are
188+
// `ArtifactsReady` it is implausable for this `expect(...)` to be
189+
// hit.
190+
done.insert(
191+
c.tag()
192+
.expect("Tag should exist on a benchmark request being sorted")
193+
.to_string(),
194+
);
186195
}
187196
finished += level_len;
188197
}
@@ -241,7 +250,7 @@ pub async fn build_queue(
241250

242251
release_artifacts.sort_unstable_by(|a, b| {
243252
a.tag()
244-
.cmp(b.tag())
253+
.cmp(&b.tag())
245254
.then_with(|| a.created_at.cmp(&b.created_at))
246255
});
247256

@@ -258,7 +267,7 @@ async fn enqueue_next_job(conn: &mut dyn database::pool::Connection) -> anyhow::
258267
.get_benchmark_requests_by_status(&[BenchmarkRequestStatus::Completed])
259268
.await?
260269
.into_iter()
261-
.map(|request| request.tag().to_string())
270+
.filter_map(|request| request.tag().map(|tag| tag.to_string()))
262271
.collect();
263272

264273
let queue = build_queue(conn, &completed).await?;
@@ -360,7 +369,7 @@ mod tests {
360369

361370
fn create_try(sha: &str, parent: &str, pr: u32, age_days: &str) -> BenchmarkRequest {
362371
BenchmarkRequest::create_try(
363-
sha,
372+
Some(sha),
364373
Some(parent),
365374
pr,
366375
days_ago(age_days),
@@ -390,7 +399,10 @@ mod tests {
390399
}
391400

392401
fn queue_order_matches(queue: &[BenchmarkRequest], expected: &[&str]) {
393-
let queue_shas: Vec<&str> = queue.iter().map(|req| req.tag()).collect();
402+
let queue_shas: Vec<&str> = queue
403+
.iter()
404+
.filter_map(|request| request.tag().map(|tag| tag))
405+
.collect();
394406
assert_eq!(queue_shas, expected)
395407
}
396408

@@ -423,23 +435,23 @@ mod tests {
423435
* +------------+
424436
* | r "v1.2.3" |
425437
* +------------+
438+
*
439+
*
440+
*
426441
* 1: Currently `in_progress`
427-
* +---------------+
428-
* +--->| t "t1" IP pr1 |
429-
* | +---------------+
430-
* +-----------+ |
431-
* | m "rrr" C | -----+-->
432-
* +-----------+ |
433-
* | +---------------+
434-
* +--->| t "yee" R pr1 | 3: a try with a low pr
435-
* +---------------+
442+
* +-----------+ +---------------+
443+
* | m "rrr" C | -----+--->| t "t1" IP pr1 |
444+
* +-----------+ +---------------+
445+
*
446+
*
447+
*
436448
* +-----------+
437449
* | m "aaa" C |
438450
* +-----------+
439451
* |
440452
* V
441453
* +----------------+
442-
* | m "mmm" R pr88 | 6: a master commit
454+
* | m "mmm" R pr88 | 5: a master commit
443455
* +----------------+
444456
*
445457
* +-----------+
@@ -448,7 +460,7 @@ mod tests {
448460
* |
449461
* V
450462
* +----------------+
451-
* | m "123" R pr11 | 4: a master commit, high pr number
463+
* | m "123" R pr11 | 3: a master commit, high pr number
452464
* +----------------+
453465
*
454466
*
@@ -458,12 +470,12 @@ mod tests {
458470
* |
459471
* V
460472
* +----------------+
461-
* | m "foo" R pr77 | 5: a master commit
473+
* | m "foo" R pr77 | 4: a master commit
462474
* +----------------+
463475
* |
464476
* V
465477
* +---------------+
466-
* | t "baz" R pr4 | 7: a try with a low pr, blocked by parent
478+
* | t "baz" R pr4 | 6: a try with a low pr, blocked by parent
467479
* +---------------+
468480
*
469481
* The master commits should take priority, then "yee" followed
@@ -476,7 +488,6 @@ mod tests {
476488
create_master("123", "345", 11, "days2"),
477489
create_try("baz", "foo", 4, "days1"),
478490
create_release("v.1.2.3", "days2"),
479-
create_try("yee", "rrr", 1, "days2"), // lower PR number takes priority
480491
create_try("t1", "rrr", 1, "days1").with_status(BenchmarkRequestStatus::InProgress),
481492
create_master("mmm", "aaa", 88, "days2"),
482493
];
@@ -492,10 +503,7 @@ mod tests {
492503

493504
let sorted: Vec<BenchmarkRequest> = build_queue(&mut *db, &completed).await.unwrap();
494505

495-
queue_order_matches(
496-
&sorted,
497-
&["t1", "v.1.2.3", "yee", "123", "foo", "mmm", "baz"],
498-
);
506+
queue_order_matches(&sorted, &["t1", "v.1.2.3", "123", "foo", "mmm", "baz"]);
499507
Ok(ctx)
500508
})
501509
.await;

0 commit comments

Comments
 (0)