Skip to content

Commit 7b08730

Browse files
DAG-1899 Randomize test order when creating sub-tasks and historic runtime information is not available (#38)
1 parent 474c561 commit 7b08730

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

CHANGELOG.md

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

3+
## 0.4.4 - 2022-06-30
4+
5+
* Randomize test order when creating sub-tasks and historic runtime information is not available.
6+
37
## 0.4.3 - 2022-06-28
48

59
* Relax requirement to have the enterprise repo configuration defined.

Cargo.lock

Lines changed: 39 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mongo-task-generator"
3-
version = "0.4.3"
3+
version = "0.4.4"
44
repository = "https://github.com/mongodb/mongo-task-generator"
55
authors = ["Decision Automation Group <[email protected]>"]
66
edition = "2018"
@@ -15,6 +15,7 @@ evg-api-rs = "0.2.2"
1515
futures = "0.3"
1616
lazy_static = "1.4"
1717
maplit = "1"
18+
rand = "0.8.5"
1819
regex = "1"
1920
serde = { version = "1.0", features = ["derive"] }
2021
serde_json = "1.0"

src/task_types/resmoke_tasks.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::{cmp::min, collections::HashMap, sync::Arc};
1212
use anyhow::Result;
1313
use async_trait::async_trait;
1414
use maplit::hashmap;
15+
use rand::{prelude::SliceRandom, thread_rng};
1516
use shrub_rs::models::{
1617
commands::{fn_call, fn_call_with_params, EvgCommand},
1718
params::ParamValue,
@@ -512,7 +513,8 @@ impl GenResmokeTaskServiceImpl {
512513
multiversion_tags: Option<String>,
513514
) -> Result<Vec<SubSuite>> {
514515
let origin_suite = multiversion_name.unwrap_or(&params.suite_name);
515-
let test_list = self.get_test_list(params, multiversion_name)?;
516+
let mut test_list = self.get_test_list(params, multiversion_name)?;
517+
test_list.shuffle(&mut thread_rng());
516518
let n_suites = min(test_list.len(), self.config.n_suites);
517519
let tasks_per_suite = test_list.len() / n_suites;
518520

@@ -1205,7 +1207,8 @@ mod tests {
12051207
#[test]
12061208
fn test_split_task_fallback_should_split_tasks_count() {
12071209
let n_suites = 3;
1208-
let test_list: Vec<String> = (0..6)
1210+
let n_tests = 6;
1211+
let test_list: Vec<String> = (0..n_tests)
12091212
.into_iter()
12101213
.map(|i| format!("test_{}.js", i))
12111214
.collect();
@@ -1225,15 +1228,15 @@ mod tests {
12251228
.unwrap();
12261229

12271230
assert_eq!(sub_suites.len(), n_suites);
1228-
let suite_0 = &sub_suites[0];
1229-
assert!(suite_0.test_list.contains(&"test_0.js".to_string()));
1230-
assert!(suite_0.test_list.contains(&"test_1.js".to_string()));
1231-
let suite_1 = &sub_suites[1];
1232-
assert!(suite_1.test_list.contains(&"test_2.js".to_string()));
1233-
assert!(suite_1.test_list.contains(&"test_3.js".to_string()));
1234-
let suite_2 = &sub_suites[2];
1235-
assert!(suite_2.test_list.contains(&"test_4.js".to_string()));
1236-
assert!(suite_2.test_list.contains(&"test_5.js".to_string()));
1231+
for sub_suite in &sub_suites {
1232+
assert_eq!(sub_suite.test_list.len(), n_tests / n_suites);
1233+
}
1234+
1235+
let all_tests: Vec<String> = sub_suites
1236+
.iter()
1237+
.flat_map(|s| s.test_list.clone())
1238+
.collect();
1239+
assert_eq!(all_tests.len(), n_tests);
12371240
}
12381241

12391242
// tests for get_test_list.

0 commit comments

Comments
 (0)