Skip to content

Commit 0c90822

Browse files
DAG-1992 Generate only burn_in tasks when --burn-in is passed (#47)
1 parent 9c0c749 commit 0c90822

File tree

9 files changed

+160
-20
lines changed

9 files changed

+160
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 0.6.0 - 2022-08-26
4+
* Generate only burn_in tasks when --burn-in is passed.
5+
36
## 0.5.3 - 2022-08-19
47
* Distribute tests without historic runtime data evenly between subsuites.
58

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mongo-task-generator"
3-
version = "0.5.3"
3+
version = "0.6.0"
44
repository = "https://github.com/mongodb/mongo-task-generator"
55
authors = ["Decision Automation Group <[email protected]>"]
66
edition = "2018"

docs/generating_tasks.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,49 @@ of the task definition. When this tag is present, both the extra setup steps and
157157
of multiversion sub-tasks will be preformed. In order to only perform the extra setup steps
158158
the `"no_version_combinations"` tag should also be included.
159159

160+
### Burn in tests and burn in tags
161+
162+
Newly added or modified tests might become flaky. In order to avoid that, those tests can be run
163+
continuously multiple times in a row to see if the results are consistent. This process is called
164+
burn-in.
165+
166+
`burn_in_tests_gen` task is used to generate burn-in tasks on the same buildvariant the task is
167+
added to. The [example](https://github.com/mongodb/mongo/blob/81c41bdfdc56f05973fae70e80e80919f18f50c9/etc/evergreen_yml_components/definitions.yml#L3252-L3256)
168+
of task configuration:
169+
170+
```yaml
171+
- <<: *gen_task_template
172+
name: burn_in_tests_gen
173+
tags: []
174+
commands:
175+
- func: "generate resmoke tasks"
176+
```
177+
178+
`burn_in_tags_gen` task is used to generate separate burn-in buildvariants. This way we can burn-in
179+
on the requested buildvariant as well as the other, additional buildvariants to ensure there is no
180+
difference between them.
181+
182+
The [example](https://github.com/mongodb/mongo/blob/81c41bdfdc56f05973fae70e80e80919f18f50c9/etc/evergreen_yml_components/definitions.yml#L4317-L4321)
183+
of task configuration:
184+
185+
```yaml
186+
- <<: *gen_task_template
187+
name: burn_in_tags_gen
188+
tags: []
189+
commands:
190+
- func: "generate resmoke tasks"
191+
```
192+
193+
`burn_in_tag_buildvariants` buildvariant expansion is used to configure base buildvariant names.
194+
Base buildvariant names should be delimited by spaces. The [example](https://github.com/mongodb/mongo/blob/81c41bdfdc56f05973fae70e80e80919f18f50c9/etc/evergreen.yml#L1257)
195+
of `burn_in_tag_buildvariants` buildvariant expansion:
196+
197+
```yaml
198+
burn_in_tag_buildvariants: enterprise-rhel-80-64-bit-inmem enterprise-rhel-80-64-bit-multiversion
199+
```
200+
201+
Burn-in related tasks are generated when `--burn-in` is passed.
202+
160203
## Working with generated tasks
161204

162205
A generated tasks is typically composed of a number of related sub-tasks. Because evergreen does
@@ -221,6 +264,11 @@ if the default value does not apply.
221264
store your resmokeconfig is a different directory, you can adjust this value:
222265
`python buildscripts/resmoke.py --configDir=path/to/resmokeconfig`.
223266
* **target-directory**: Directory to write generated configuration to. This defaults to `generated_resmoke_config`.
267+
* **burn-in**: Whether to generate burn_in related tasks. If specified only burn_in tasks will be
268+
generated.
269+
* **burn-in-tests-command**: How to invoke the burn_in_tests command. The burn_in_tests command is
270+
used to discover modified or added tests and the tasks they being run on. It defaults to
271+
`python buildscripts/burn_in_tests.py`.
224272

225273
## Usage help
226274

@@ -232,6 +280,10 @@ USAGE:
232280
mongo-task-generator [OPTIONS] --expansion-file <EXPANSION_FILE>
233281
234282
OPTIONS:
283+
--burn-in
284+
Generate burn_in related tasks
285+
--burn-in-tests-command <BURN_IN_TESTS_COMMAND>
286+
Command to invoke burn_in_tests [default: "python buildscripts/burn_in_tests.py"]
235287
--evg-auth-file <EVG_AUTH_FILE>
236288
File with information on how to authenticate against the evergreen API [default:
237289
~/.evergreen.yml]
@@ -240,7 +292,7 @@ OPTIONS:
240292
--expansion-file <EXPANSION_FILE>
241293
File containing expansions that impact task generation
242294
--generate-sub-tasks-config <GENERATE_SUB_TASKS_CONFIG>
243-
File containing configuration for generating sub-tasks
295+
File containing configuration for generating sub-tasks
244296
-h, --help
245297
Print help information
246298
--resmoke-command <RESMOKE_COMMAND>

src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ pub struct ExecutionConfiguration<'a> {
128128
pub config_location: &'a str,
129129
/// Should burn_in tasks be generated.
130130
pub gen_burn_in: bool,
131+
/// Command to execute burn_in_tests.
132+
pub burn_in_tests_command: &'a str,
131133
}
132134

133135
/// Collection of services needed to execution.
@@ -208,7 +210,7 @@ impl Dependencies {
208210
execution_config.gen_burn_in,
209211
));
210212

211-
let burn_in_discovery = Arc::new(BurnInProxy::new());
213+
let burn_in_discovery = Arc::new(BurnInProxy::new(execution_config.burn_in_tests_command));
212214
let burn_in_service = Arc::new(BurnInServiceImpl::new(
213215
burn_in_discovery,
214216
gen_resmoke_task_service,
@@ -467,8 +469,8 @@ impl GenerateTasksService for GenerateTasksServiceImpl {
467469
for task in &build_variant.tasks {
468470
// Burn in tasks could be different for each build variant, so we will always
469471
// handle them.
470-
if task.name == BURN_IN_TESTS {
471-
if self.gen_burn_in {
472+
if self.gen_burn_in {
473+
if task.name == BURN_IN_TESTS {
472474
thread_handles.push(create_burn_in_worker(
473475
deps,
474476
task_map.clone(),
@@ -477,11 +479,8 @@ impl GenerateTasksService for GenerateTasksServiceImpl {
477479
generated_tasks.clone(),
478480
));
479481
}
480-
continue;
481-
}
482482

483-
if task.name == BURN_IN_TAGS {
484-
if self.gen_burn_in {
483+
if task.name == BURN_IN_TAGS {
485484
for base_bv_name in self
486485
.evg_config_utils
487486
.lookup_and_split_by_whitespace_build_variant_expansion(
@@ -501,6 +500,11 @@ impl GenerateTasksService for GenerateTasksServiceImpl {
501500
));
502501
}
503502
}
503+
504+
continue;
505+
}
506+
507+
if task.name == BURN_IN_TESTS || task.name == BURN_IN_TAGS {
504508
continue;
505509
}
506510

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use tracing_subscriber::fmt::format;
1616
const DEFAULT_EVG_AUTH_FILE: &str = "~/.evergreen.yml";
1717
const DEFAULT_EVG_PROJECT_FILE: &str = "etc/evergreen.yml";
1818
const DEFAULT_RESMOKE_COMMAND: &str = "python buildscripts/resmoke.py";
19+
const DEFAULT_BURN_IN_TESTS_COMMAND: &str = "python buildscripts/burn_in_tests.py";
1920
const DEFAULT_TARGET_DIRECTORY: &str = "generated_resmoke_config";
2021

2122
/// Expansions from evergreen to determine settings for how task should be generated.
@@ -84,6 +85,10 @@ struct Args {
8485
/// Generate burn_in related tasks.
8586
#[clap(long)]
8687
burn_in: bool,
88+
89+
/// Command to invoke burn_in_tests.
90+
#[clap(long, default_value = DEFAULT_BURN_IN_TESTS_COMMAND)]
91+
burn_in_tests_command: String,
8792
}
8893

8994
/// Configure logging for the command execution.
@@ -116,6 +121,7 @@ async fn main() {
116121
generating_task: &evg_expansions.task_name,
117122
config_location: &evg_expansions.config_location(),
118123
gen_burn_in: args.burn_in,
124+
burn_in_tests_command: &args.burn_in_tests_command,
119125
};
120126
let deps = Dependencies::new(execution_config).unwrap();
121127

src/resmoke/burn_in_proxy.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,27 @@ pub trait BurnInDiscovery: Send + Sync {
3636
fn discover_tasks(&self, build_variant: &str) -> Result<Vec<DiscoveredTask>>;
3737
}
3838

39-
pub struct BurnInProxy {}
39+
pub struct BurnInProxy {
40+
/// Primary command to invoke burn_in_tests (usually `python`).
41+
burn_in_tests_cmd: String,
42+
/// Script to invoke burn_in_tests.
43+
burn_in_tests_script: Vec<String>,
44+
}
4045

4146
impl BurnInProxy {
42-
pub fn new() -> Self {
43-
BurnInProxy {}
47+
/// Create a new `BurnInProxy` instance.
48+
///
49+
/// # Arguments
50+
///
51+
/// * `burn_in_tests_cmd` - Command to invoke resmoke.
52+
pub fn new(burn_in_tests_cmd: &str) -> Self {
53+
let cmd_parts: Vec<_> = burn_in_tests_cmd.split(' ').collect();
54+
let cmd = cmd_parts[0];
55+
let script = cmd_parts[1..].iter().map(|s| s.to_string()).collect();
56+
Self {
57+
burn_in_tests_cmd: cmd.to_string(),
58+
burn_in_tests_script: script,
59+
}
4460
}
4561
}
4662

@@ -55,13 +71,15 @@ impl BurnInDiscovery for BurnInProxy {
5571
///
5672
/// A list of tasks/tests that were discovered by burn_in_tests.
5773
fn discover_tasks(&self, build_variant: &str) -> Result<Vec<DiscoveredTask>> {
58-
let cmd = vec![
59-
"python",
60-
"buildscripts/burn_in_tests.py",
61-
"--build-variant",
62-
build_variant,
63-
"--yaml",
64-
];
74+
let mut cmd = vec![self.burn_in_tests_cmd.as_str()];
75+
cmd.append(
76+
&mut self
77+
.burn_in_tests_script
78+
.iter()
79+
.map(|s| s.as_str())
80+
.collect(),
81+
);
82+
cmd.append(&mut vec!["--build-variant", build_variant, "--yaml"]);
6583
let start = Instant::now();
6684

6785
let cmd_output = run_command(&cmd)?;

tests/integration_test.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,38 @@ fn test_end2end_execution() {
3030
let files = std::fs::read_dir(tmp_dir_path).unwrap();
3131
assert_eq!(2647, files.into_iter().collect::<Vec<_>>().len());
3232
}
33+
34+
#[test]
35+
fn test_end2end_burn_in_execution() {
36+
let mut cmd = Command::cargo_bin("mongo-task-generator").unwrap();
37+
let tmp_dir = TempDir::new("generated_resmoke_config").unwrap();
38+
39+
cmd.args(&[
40+
"--target-directory",
41+
tmp_dir.path().to_str().unwrap(),
42+
"--expansion-file",
43+
"tests/data/sample_expansions.yml",
44+
"--evg-project-file",
45+
"tests/data/evergreen.yml",
46+
"--evg-auth-file",
47+
"tests/data/sample_evergreen_auth.yml",
48+
"--resmoke-command",
49+
"python3 tests/mocks/resmoke.py",
50+
"--use-task-split-fallback",
51+
"--generate-sub-tasks-config",
52+
"tests/data/sample_generate_subtasks_config.yml",
53+
"--burn-in",
54+
"--burn-in-tests-command",
55+
"python3 tests/mocks/burn_in_tests.py",
56+
])
57+
.assert()
58+
.success();
59+
60+
let tmp_dir_path = tmp_dir.path();
61+
assert!(tmp_dir_path.exists());
62+
63+
let files = std::fs::read_dir(tmp_dir_path).unwrap();
64+
// Only one file `evergreen_config.json` should be generated.
65+
// That means non-burn-in tasks are NOT generated.
66+
assert_eq!(1, files.into_iter().collect::<Vec<_>>().len());
67+
}

tests/mocks/burn_in_tests.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Mock of burn_in_tests.py for testing task generation."""
2+
def burn_in_discovery():
3+
print("""
4+
discovered_tasks:
5+
- task_name: jsCore
6+
test_list:
7+
- tests/data/tests/test_0.js
8+
- task_name: sharding_jscore_passthrough
9+
test_list:
10+
- tests/data/tests/test_0.js
11+
- task_name: replica_sets_jscore_passthrough
12+
test_list:
13+
- tests/data/tests/test_0.js
14+
""")
15+
16+
17+
def main():
18+
burn_in_discovery()
19+
20+
21+
if __name__ == '__main__':
22+
main()

0 commit comments

Comments
 (0)