Skip to content

Commit 9eb099d

Browse files
committed
Auto merge of #384 - pietroalbini:ignore-blacklist, r=pietroalbini
Add a flag to ignore the blacklist for a run This PR adds a flag to ignore the blacklist only for a run. The flag will be useful when maintenance runs are done, for example when we regenerate the list of automatically skipped crates. It also adds minicrater runs with the blacklist and with the blacklist ignored.
2 parents fa42afa + e18e1f3 commit 9eb099d

File tree

15 files changed

+509
-107
lines changed

15 files changed

+509
-107
lines changed

docs/bot-usage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ beta run you can use:
115115
* `mode`: the experiment mode (default: `build-and-test`)
116116
* `crates`: the selection of crates to use (default: `full`)
117117
* `cap-lints`: the lints cap (default: `forbid`, which means no cap)
118+
* `ignore-blacklist`: whether the blacklist should be ignored (default: `false`)
118119
* `p`: the priority of the run (default: `0`)
119120

120121
[Go back to the TOC][h-toc]
@@ -140,6 +141,7 @@ priority of the `foo` experiment you can use:
140141
* `mode`: the experiment mode (default: `build-and-test`)
141142
* `crates`: the selection of crates to use (default: `full`)
142143
* `cap-lints`: the lints cap (default: `forbid`, which means no cap)
144+
* `ignore-blacklist`: whether the blacklist should be ignored (default: `false`)
143145
* `p`: the priority of the run (default: `0`)
144146

145147
[Go back to the TOC][h-toc]

src/actions/experiments/create.rs

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct CreateExperiment {
1414
pub cap_lints: CapLints,
1515
pub priority: i32,
1616
pub github_issue: Option<GitHubIssue>,
17+
pub ignore_blacklist: bool,
1718
}
1819

1920
impl CreateExperiment {
@@ -29,6 +30,7 @@ impl CreateExperiment {
2930
cap_lints: CapLints::Forbid,
3031
priority: 0,
3132
github_issue: None,
33+
ignore_blacklist: false,
3234
}
3335
}
3436

@@ -49,8 +51,8 @@ impl CreateExperiment {
4951
transaction.execute(
5052
"INSERT INTO experiments \
5153
(name, mode, cap_lints, toolchain_start, toolchain_end, priority, created_at, \
52-
status, github_issue, github_issue_url, github_issue_number) \
53-
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11);",
54+
status, github_issue, github_issue_url, github_issue_number, ignore_blacklist) \
55+
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12);",
5456
&[
5557
&self.name,
5658
&self.mode.to_str(),
@@ -63,11 +65,12 @@ impl CreateExperiment {
6365
&self.github_issue.as_ref().map(|i| i.api_url.as_str()),
6466
&self.github_issue.as_ref().map(|i| i.html_url.as_str()),
6567
&self.github_issue.as_ref().map(|i| i.number),
68+
&self.ignore_blacklist,
6669
],
6770
)?;
6871

6972
for krate in &crates {
70-
let skipped = config.should_skip(krate) as i32;
73+
let skipped = !self.ignore_blacklist && config.should_skip(krate);
7174
transaction.execute(
7275
"INSERT INTO experiment_crates (experiment, crate, skipped) VALUES (?1, ?2, ?3);",
7376
&[&self.name, &::serde_json::to_string(&krate)?, &skipped],
@@ -85,8 +88,9 @@ impl CreateExperiment {
8588
mod tests {
8689
use super::CreateExperiment;
8790
use crate::actions::ExperimentError;
88-
use crate::config::Config;
89-
use crate::db::Database;
91+
use crate::config::{Config, CrateConfig};
92+
use crate::crates::Crate;
93+
use crate::db::{Database, QueryUtils};
9094
use crate::experiments::{CapLints, CrateSelect, Experiment, GitHubIssue, Mode, Status};
9195
use crate::toolchain::{MAIN_TOOLCHAIN, TEST_TOOLCHAIN};
9296

@@ -112,6 +116,7 @@ mod tests {
112116
html_url: html_url.to_string(),
113117
number: 10,
114118
}),
119+
ignore_blacklist: true,
115120
}
116121
.apply(&db, &config)
117122
.unwrap();
@@ -137,6 +142,64 @@ mod tests {
137142
assert_eq!(ex.priority, 5);
138143
assert_eq!(ex.status, Status::Queued);
139144
assert!(ex.assigned_to.is_none());
145+
assert!(ex.ignore_blacklist);
146+
}
147+
148+
#[test]
149+
fn test_ignore_blacklist() {
150+
fn is_skipped(db: &Database, ex: &str, krate: &str) -> bool {
151+
let crates: Vec<Crate> = db
152+
.query(
153+
"SELECT crate FROM experiment_crates WHERE experiment = ?1 AND skipped = 0",
154+
&[&ex],
155+
|row| {
156+
let krate: String = row.get("crate");
157+
serde_json::from_str(&krate).unwrap()
158+
},
159+
)
160+
.unwrap();
161+
crates
162+
.iter()
163+
.find(|c| {
164+
if let Crate::Local(name) = c {
165+
name == krate
166+
} else {
167+
panic!("there should be no non-local crates")
168+
}
169+
})
170+
.is_none()
171+
}
172+
173+
let db = Database::temp().unwrap();
174+
let mut config = Config::default();
175+
config.local_crates.insert(
176+
"build-pass".into(),
177+
CrateConfig {
178+
skip: true,
179+
skip_tests: false,
180+
quiet: false,
181+
update_lockfile: false,
182+
broken: false,
183+
},
184+
);
185+
186+
crate::crates::lists::setup_test_lists(&db, &config).unwrap();
187+
188+
CreateExperiment {
189+
ignore_blacklist: false,
190+
..CreateExperiment::dummy("foo")
191+
}
192+
.apply(&db, &config)
193+
.unwrap();
194+
assert!(is_skipped(&db, "foo", "build-pass"));
195+
196+
CreateExperiment {
197+
ignore_blacklist: true,
198+
..CreateExperiment::dummy("bar")
199+
}
200+
.apply(&db, &config)
201+
.unwrap();
202+
assert!(!is_skipped(&db, "bar", "build-pass"));
140203
}
141204

142205
#[test]
@@ -155,6 +218,7 @@ mod tests {
155218
cap_lints: CapLints::Forbid,
156219
priority: 0,
157220
github_issue: None,
221+
ignore_blacklist: false,
158222
}
159223
.apply(&db, &config)
160224
.unwrap_err();
@@ -181,6 +245,7 @@ mod tests {
181245
cap_lints: CapLints::Forbid,
182246
priority: 0,
183247
github_issue: None,
248+
ignore_blacklist: false,
184249
}
185250
.apply(&db, &config)
186251
.unwrap();
@@ -194,6 +259,7 @@ mod tests {
194259
cap_lints: CapLints::Forbid,
195260
priority: 0,
196261
github_issue: None,
262+
ignore_blacklist: false,
197263
}
198264
.apply(&db, &config)
199265
.unwrap_err();

src/actions/experiments/edit.rs

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct EditExperiment {
1212
pub mode: Option<Mode>,
1313
pub cap_lints: Option<CapLints>,
1414
pub priority: Option<i32>,
15+
pub ignore_blacklist: Option<bool>,
1516
}
1617

1718
impl EditExperiment {
@@ -24,6 +25,7 @@ impl EditExperiment {
2425
crates: None,
2526
cap_lints: None,
2627
priority: None,
28+
ignore_blacklist: None,
2729
}
2830
}
2931

@@ -61,10 +63,29 @@ impl EditExperiment {
6163
}
6264
}
6365

64-
// Try to update the list of crates
65-
if let Some(crates) = self.crates {
66-
let crates_vec = crate::crates::lists::get_crates(crates, db, config)?;
66+
// Try to update the ignore_blacklist field
67+
// The list of skipped crates will be recalculated afterwards
68+
if let Some(ignore_blacklist) = self.ignore_blacklist {
69+
let changes = t.execute(
70+
"UPDATE experiments SET ignore_blacklist = ?1 WHERE name = ?2;",
71+
&[&ignore_blacklist, &self.name],
72+
)?;
73+
assert_eq!(changes, 1);
6774

75+
ex.ignore_blacklist = ignore_blacklist;
76+
has_changed = true;
77+
}
78+
79+
// Try to update the list of crates
80+
// This is also done if ignore_blacklist is changed to recalculate the skipped crates
81+
let new_crates = if let Some(crates) = self.crates {
82+
Some(crate::crates::lists::get_crates(crates, db, config)?)
83+
} else if self.ignore_blacklist.is_some() {
84+
Some(ex.crates.clone())
85+
} else {
86+
None
87+
};
88+
if let Some(crates_vec) = new_crates {
6889
// Recreate the list of crates without checking if it was the same
6990
// This is done to allow reloading the list of crates in an existing experiment
7091
t.execute(
@@ -78,7 +99,7 @@ impl EditExperiment {
7899
&[
79100
&self.name,
80101
&::serde_json::to_string(&krate)?,
81-
&config.should_skip(krate),
102+
&(!ex.ignore_blacklist && config.should_skip(krate)),
82103
],
83104
)?;
84105
}
@@ -132,8 +153,9 @@ impl EditExperiment {
132153
mod tests {
133154
use super::EditExperiment;
134155
use crate::actions::{CreateExperiment, ExperimentError};
135-
use crate::config::Config;
136-
use crate::db::Database;
156+
use crate::config::{Config, CrateConfig};
157+
use crate::crates::Crate;
158+
use crate::db::{Database, QueryUtils};
137159
use crate::experiments::{CapLints, CrateSelect, Experiment, Mode, Status};
138160
use crate::toolchain::{MAIN_TOOLCHAIN, TEST_TOOLCHAIN};
139161

@@ -168,6 +190,7 @@ mod tests {
168190
cap_lints: CapLints::Forbid,
169191
priority: 0,
170192
github_issue: None,
193+
ignore_blacklist: false,
171194
}
172195
.apply(&db, &config)
173196
.unwrap();
@@ -183,6 +206,7 @@ mod tests {
183206
crates: Some(CrateSelect::Local),
184207
cap_lints: Some(CapLints::Warn),
185208
priority: Some(10),
209+
ignore_blacklist: Some(true),
186210
}
187211
.apply(&db, &config)
188212
.unwrap();
@@ -195,13 +219,79 @@ mod tests {
195219
assert_eq!(ex.mode, Mode::CheckOnly);
196220
assert_eq!(ex.cap_lints, CapLints::Warn);
197221
assert_eq!(ex.priority, 10);
222+
assert_eq!(ex.ignore_blacklist, true);
198223

199224
assert_eq!(
200225
ex.crates,
201226
crate::crates::lists::get_crates(CrateSelect::Local, &db, &config).unwrap()
202227
);
203228
}
204229

230+
#[test]
231+
fn test_ignore_blacklist() {
232+
fn is_skipped(db: &Database, ex: &str, krate: &str) -> bool {
233+
let crates: Vec<Crate> = db
234+
.query(
235+
"SELECT crate FROM experiment_crates WHERE experiment = ?1 AND skipped = 0",
236+
&[&ex],
237+
|row| {
238+
let krate: String = row.get("crate");
239+
serde_json::from_str(&krate).unwrap()
240+
},
241+
)
242+
.unwrap();
243+
crates
244+
.iter()
245+
.find(|c| {
246+
if let Crate::Local(name) = c {
247+
name == krate
248+
} else {
249+
panic!("there should be no non-local crates")
250+
}
251+
})
252+
.is_none()
253+
}
254+
255+
let db = Database::temp().unwrap();
256+
let mut config = Config::default();
257+
config.local_crates.insert(
258+
"build-pass".into(),
259+
CrateConfig {
260+
skip: true,
261+
skip_tests: false,
262+
quiet: false,
263+
update_lockfile: false,
264+
broken: false,
265+
},
266+
);
267+
268+
crate::crates::lists::setup_test_lists(&db, &config).unwrap();
269+
270+
CreateExperiment {
271+
ignore_blacklist: false,
272+
..CreateExperiment::dummy("foo")
273+
}
274+
.apply(&db, &config)
275+
.unwrap();
276+
assert!(is_skipped(&db, "foo", "build-pass"));
277+
278+
EditExperiment {
279+
ignore_blacklist: Some(true),
280+
..EditExperiment::dummy("foo")
281+
}
282+
.apply(&db, &config)
283+
.unwrap();
284+
assert!(!is_skipped(&db, "foo", "build-pass"));
285+
286+
EditExperiment {
287+
ignore_blacklist: Some(false),
288+
..EditExperiment::dummy("foo")
289+
}
290+
.apply(&db, &config)
291+
.unwrap();
292+
assert!(is_skipped(&db, "foo", "build-pass"));
293+
}
294+
205295
#[test]
206296
fn test_duplicate_toolchains() {
207297
let db = Database::temp().unwrap();

0 commit comments

Comments
 (0)