Skip to content

Commit 0a76a13

Browse files
committed
update database test exporting & update sorting function
1 parent eec4baf commit 0a76a13

File tree

4 files changed

+40
-38
lines changed

4 files changed

+40
-38
lines changed

database/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ csv = "1"
2626
x509-cert = { version = "0.2.5", features = ["pem"] }
2727

2828
intern = { path = "../intern" }
29+
uuid = "1.16.0"
2930

3031
[dev-dependencies]
3132
uuid = { version = "1.16.0", features = ["v4"] }

database/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ pub mod interpolate;
1313
pub mod metric;
1414
pub mod pool;
1515
pub mod selector;
16-
17-
mod tests;
16+
pub mod tests;
1817

1918
pub use pool::{Connection, Pool};
2019

database/src/tests/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ pub struct TestContext {
2323
}
2424

2525
impl TestContext {
26+
#[allow(dead_code)]
2627
async fn new_postgres(db_url: &str) -> Self {
2728
let config: Config = db_url.parse().expect("Cannot parse connection string");
2829

2930
// Create a new database that will be used for this specific test
30-
let client = make_client(&db_url)
31+
let client = make_client(db_url)
3132
.await
3233
.expect("Cannot connect to database");
3334
let db_name = format!("db{}", uuid::Uuid::new_v4().to_string().replace("-", ""));
@@ -77,6 +78,7 @@ impl TestContext {
7778
}
7879
}
7980

81+
#[allow(dead_code)]
8082
async fn new_sqlite() -> Self {
8183
let pool = Pool::open(":memory:");
8284
Self {
@@ -85,10 +87,12 @@ impl TestContext {
8587
}
8688
}
8789

90+
#[allow(dead_code)]
8891
pub fn db_client(&self) -> &Pool {
8992
&self.client
9093
}
9194

95+
#[allow(dead_code)]
9296
async fn finish(self) {
9397
// Cleanup the test database
9498
// First, we need to stop using the database
@@ -114,6 +118,7 @@ impl TestContext {
114118
}
115119

116120
/// Runs a test against an actual postgres database.
121+
#[allow(dead_code)]
117122
pub async fn run_postgres_test<F, Fut>(f: F)
118123
where
119124
F: Fn(TestContext) -> Fut,
@@ -141,6 +146,7 @@ where
141146

142147
/// Runs a test against an actual database.
143148
/// Checks both Postgres and SQLite.
149+
#[allow(dead_code)]
144150
pub async fn run_db_test<F, Fut>(f: F)
145151
where
146152
F: Fn(TestContext) -> Fut + Clone,

site/src/job_queue.rs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,44 +37,30 @@ async fn create_benchmark_request_master_commits(
3737
Ok(())
3838
}
3939

40-
/// For getting the priority of the request type;
41-
/// - Release
42-
/// - Master
43-
/// - Try
44-
fn benchmark_request_commit_type_rank(commit_type: &BenchmarkRequestType) -> u8 {
45-
match commit_type {
46-
BenchmarkRequestType::Release { .. } => 0,
47-
BenchmarkRequestType::Master { .. } => 1,
48-
BenchmarkRequestType::Try { .. } => 2,
49-
}
50-
}
51-
52-
/// Sorts the priority order of the queue. It assumes that the only status
53-
/// is `ArtifactsReady`
54-
fn sort_benchmark_requests<'a>(
55-
done: &mut HashSet<String>,
56-
unordered_queue: &'a mut [BenchmarkRequest],
57-
) -> &'a [BenchmarkRequest] {
40+
/// Sorts try and master requests that are in the `ArtifactsReady` status.
41+
/// Doesn't consider in-progress requests or release artifacts.
42+
fn sort_benchmark_requests<'a>(done: &HashSet<String>, request_queue: &'a mut [BenchmarkRequest]) {
5843
// A topological sort, where each "level" is additionally altered such that
5944
// try commits come first, and then sorted by PR # (as a rough heuristic for
6045
// earlier requests).
46+
let mut done: HashSet<&str> = done.iter().map(|x| x.as_str()).collect();
6147

6248
// Ensure all the items are ready to be sorted, if they are not this is
6349
// undefined behaviour
64-
assert!(unordered_queue
65-
.iter()
66-
.all(|bmr| bmr.status == BenchmarkRequestStatus::ArtifactsReady));
67-
68-
// Ensure the queue is ordered by status and the `commit_type`
69-
unordered_queue
70-
.sort_unstable_by_key(|bmr| (benchmark_request_commit_type_rank(&bmr.commit_type)));
50+
assert!(request_queue.iter().all(|bmr| {
51+
bmr.status == BenchmarkRequestStatus::ArtifactsReady
52+
&& matches!(
53+
bmr.commit_type,
54+
BenchmarkRequestType::Master { .. } | BenchmarkRequestType::Try { .. }
55+
)
56+
}));
7157

7258
let mut finished = 0;
73-
while finished < unordered_queue.len() {
59+
while finished < request_queue.len() {
7460
// The next level is those elements in the unordered queue which
7561
// are ready to be benchmarked (i.e., those with parent in done or no
7662
// parent).
77-
let level_len = partition_in_place(unordered_queue[finished..].iter_mut(), |bmr| {
63+
let level_len = partition_in_place(request_queue[finished..].iter_mut(), |bmr| {
7864
bmr.parent_sha().is_none_or(|parent| done.contains(parent))
7965
});
8066

@@ -83,33 +69,43 @@ fn sort_benchmark_requests<'a>(
8369
// let the commits be benchmarked in the current order that we have, these benchmark runs
8470
// just won't have a parent result available.
8571
if level_len == 0 {
86-
return unordered_queue;
72+
log::warn!("No commit is ready for benchmarking");
73+
#[cfg(test)]
74+
{
75+
panic!("No commit is ready for benchmarking");
76+
}
77+
return;
8778
}
8879

89-
let level = &mut unordered_queue[finished..][..level_len];
80+
// Everything in level has the same topological order, then we sort based on heuristics
81+
let level = &mut request_queue[finished..][..level_len];
9082
level.sort_unstable_by_key(|bmr| {
9183
(
92-
bmr.parent_sha().is_some(),
84+
// Order master commits before try commits
85+
match bmr.commit_type {
86+
BenchmarkRequestType::Try { .. } => 1,
87+
BenchmarkRequestType::Master { .. } => 0,
88+
BenchmarkRequestType::Release { .. } => unreachable!(),
89+
},
9390
*bmr.pr().unwrap_or(&0),
9491
bmr.created_at,
95-
bmr.tag().to_string(),
9692
)
9793
});
9894
for c in level {
99-
done.insert(c.tag().to_string());
95+
done.insert(c.tag());
10096
}
10197
finished += level_len;
10298
}
103-
unordered_queue
10499
}
105100

106101
/// Given some pending requests and a list of completed requests determine if
107102
/// we have another request the we can process
108103
fn get_next_benchmark_request<'a>(
109104
pending: &'a mut [BenchmarkRequest],
110-
completed_set: &mut HashSet<String>,
105+
completed_set: &HashSet<String>,
111106
) -> Option<&'a BenchmarkRequest> {
112-
sort_benchmark_requests(completed_set, pending).first()
107+
sort_benchmark_requests(completed_set, pending);
108+
pending.first()
113109
}
114110

115111
/// Enqueue the job into the job_queue

0 commit comments

Comments
 (0)