Skip to content

Commit 71c0f50

Browse files
authored
DEVPROD-14354 avoid a division-by-zero when processing empty suites (#88)
1 parent be6ad1d commit 71c0f50

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## 0.7.22 - 2025-01-22
3+
* Avoid a division-by-zero when processing empty suites.
4+
25
## 0.7.21 - 2025-01-16
36
* Add additional logging for task generation that takes a long time.
47

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
@@ -2,7 +2,7 @@
22
name = "mongo-task-generator"
33
description = "Dynamically split evergreen tasks into subtasks for testing the mongodb/mongo project."
44
license = "Apache-2.0"
5-
version = "0.7.21"
5+
version = "0.7.22"
66
repository = "https://github.com/mongodb/mongo-task-generator"
77
authors = ["Decision Automation Group <[email protected]>"]
88
edition = "2018"

src/task_types/resmoke_tasks.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,16 @@ impl GenResmokeTaskServiceImpl {
509509
multiversion_name: Option<&str>,
510510
multiversion_tags: Option<String>,
511511
) -> Result<Vec<SubSuite>> {
512+
let mut sub_suites = vec![];
513+
512514
let origin_suite = multiversion_name.unwrap_or(&params.suite_name);
513515
let test_list = self.get_test_list(params, multiversion_name)?;
516+
if test_list.is_empty() {
517+
return Ok(sub_suites);
518+
}
514519
let n_suites = min(test_list.len(), self.config.n_suites);
515520
let tasks_per_suite = test_list.len() / n_suites;
516521

517-
let mut sub_suites = vec![];
518522
let mut current_tests = vec![];
519523
let mut i = 0;
520524
for test in test_list {
@@ -1306,6 +1310,28 @@ mod tests {
13061310
}
13071311
}
13081312

1313+
#[test]
1314+
fn test_split_task_fallback_empty_suite() {
1315+
let n_suites = 1;
1316+
let test_list = vec![];
1317+
let task_history = TaskRuntimeHistory {
1318+
task_name: "my task".to_string(),
1319+
test_map: hashmap! {},
1320+
};
1321+
let gen_resmoke_service =
1322+
build_mocked_service(test_list.clone(), task_history.clone(), n_suites);
1323+
1324+
let params = ResmokeGenParams {
1325+
..Default::default()
1326+
};
1327+
1328+
let sub_suites = gen_resmoke_service
1329+
.split_task_fallback(&params, None, None)
1330+
.unwrap();
1331+
1332+
assert_eq!(sub_suites.len(), 0);
1333+
}
1334+
13091335
// tests for get_test_list.
13101336
#[rstest]
13111337
#[case(true, 12)]

0 commit comments

Comments
 (0)