Skip to content

Commit 9c0c749

Browse files
DAG-1986 Distribute tests without historic runtime data evenly between subsuites (#46)
1 parent c047b72 commit 9c0c749

File tree

4 files changed

+45
-55
lines changed

4 files changed

+45
-55
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.5.3 - 2022-08-19
4+
* Distribute tests without historic runtime data evenly between subsuites.
5+
36
## 0.5.2 - 2022-08-17
47
* Improve task splitting based on historic tests runtime.
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.2"
3+
version = "0.5.3"
44
repository = "https://github.com/mongodb/mongo-task-generator"
55
authors = ["Decision Automation Group <[email protected]>"]
66
edition = "2018"

src/task_types/resmoke_tasks.rs

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ use super::{
4040
resmoke_config_writer::ResmokeConfigActor,
4141
};
4242

43-
/// Required number of tests needing stats to use historic data for task splitting.
44-
const REQUIRED_STATS_THRESHOLD: f32 = 0.8;
45-
4643
/// Parameters describing how a specific resmoke suite should be generated.
4744
#[derive(Clone, Debug, Default)]
4845
pub struct ResmokeGenParams {
@@ -385,20 +382,6 @@ impl GenResmokeTaskServiceImpl {
385382
}
386383
}
387384

388-
/// Calculate the number of tests that fit in the given percent.
389-
///
390-
/// # Arguments
391-
///
392-
/// * `n_tests` - Total number of tests.
393-
/// * `percent` - Percentage to calculate.
394-
///
395-
/// # Returns
396-
///
397-
/// Number of tests that fit in the given percentage.
398-
fn percent_of_tests(n_tests: usize, percent: f32) -> usize {
399-
(n_tests as f32 * percent) as usize
400-
}
401-
402385
impl GenResmokeTaskServiceImpl {
403386
/// Split the given task into a number of sub-tasks for parallel execution.
404387
///
@@ -421,18 +404,6 @@ impl GenResmokeTaskServiceImpl {
421404
) -> Result<Vec<SubSuite>> {
422405
let origin_suite = multiversion_name.unwrap_or(&params.suite_name);
423406
let test_list = self.get_test_list(params, multiversion_name)?;
424-
let required_stats_count = percent_of_tests(test_list.len(), REQUIRED_STATS_THRESHOLD);
425-
if task_stats.test_map.len() < required_stats_count {
426-
event!(
427-
Level::WARN,
428-
"Incomplete runtime stats for {}, using fallback, stat_count={}, test_count={}, limit={}",
429-
&params.suite_name,
430-
task_stats.test_map.len(),
431-
test_list.len(),
432-
required_stats_count
433-
);
434-
return self.split_task_fallback(params, multiversion_name, multiversion_tags);
435-
}
436407
let total_runtime = task_stats
437408
.test_map
438409
.iter()
@@ -451,20 +422,22 @@ impl GenResmokeTaskServiceImpl {
451422
let sorted_test_list = sort_tests_by_runtime(test_list, task_stats);
452423
let mut running_tests = vec![vec![]; max_tasks];
453424
let mut running_runtimes = vec![0.0; max_tasks];
425+
let mut left_tests = vec![];
454426

455427
for test in sorted_test_list {
456-
let mut min_idx = 0;
457-
for (i, value) in running_runtimes.iter().enumerate() {
458-
if value < &running_runtimes[min_idx] {
459-
min_idx = i;
460-
}
461-
}
462-
428+
let min_idx = get_min_index(&running_runtimes);
463429
let test_name = get_test_name(&test);
464430
if let Some(test_stats) = task_stats.test_map.get(&test_name) {
465431
running_runtimes[min_idx] += test_stats.average_runtime;
432+
running_tests[min_idx].push(test.clone());
433+
} else {
434+
left_tests.push(test.clone());
466435
}
467-
running_tests[min_idx].push(test.clone());
436+
}
437+
438+
let min_idx = get_min_index(&running_runtimes);
439+
for (i, test) in left_tests.iter().enumerate() {
440+
running_tests[(min_idx + i) % max_tasks].push(test.clone());
468441
}
469442

470443
let mut sub_suites = vec![];
@@ -731,6 +704,25 @@ fn sort_tests_by_runtime(
731704
sorted_test_list
732705
}
733706

707+
/// Get the index of sub suite with the least total runtime of tests.
708+
///
709+
/// # Arguments
710+
///
711+
/// * `running_runtimes` - Total runtimes of tests of sub suites.
712+
///
713+
/// # Returns
714+
///
715+
/// Index of sub suite with the least total runtime.
716+
fn get_min_index(running_runtimes: &[f64]) -> usize {
717+
let mut min_idx = 0;
718+
for (i, value) in running_runtimes.iter().enumerate() {
719+
if value < &running_runtimes[min_idx] {
720+
min_idx = i;
721+
}
722+
}
723+
min_idx
724+
}
725+
734726
#[async_trait]
735727
impl GenResmokeTaskService for GenResmokeTaskServiceImpl {
736728
/// Generate a task for running the given task in parallel.
@@ -1529,22 +1521,6 @@ mod tests {
15291521
assert_eq!(get_evg_fn_name(&commands[5]), Some("run test"));
15301522
}
15311523

1532-
// percent_of_tests tests.
1533-
#[rstest]
1534-
#[case(100, 0.8, 80)]
1535-
#[case(100, 1.0, 100)]
1536-
#[case(101, 0.8, 80)]
1537-
#[case(99, 0.8, 79)]
1538-
fn test_percent_of_tests(
1539-
#[case] n_tests: usize,
1540-
#[case] percent: f32,
1541-
#[case] expected_result: usize,
1542-
) {
1543-
let result = percent_of_tests(n_tests, percent);
1544-
1545-
assert_eq!(result, expected_result);
1546-
}
1547-
15481524
// sort_tests_by_runtime tests.
15491525
#[rstest]
15501526
#[case(vec![100.0, 50.0, 30.0, 25.0, 20.0, 15.0], vec![0, 1, 2, 3, 4, 5])]
@@ -1586,4 +1562,15 @@ mod tests {
15861562

15871563
assert_eq!(result, expected_result);
15881564
}
1565+
1566+
// get_min_index tests.
1567+
#[rstest]
1568+
#[case(vec![100.0, 50.0, 30.0, 25.0, 20.0, 15.0], 5)]
1569+
#[case(vec![15.0, 20.0, 25.0, 30.0, 50.0, 100.0], 0)]
1570+
#[case(vec![25.0, 50.0, 15.0, 30.0, 100.0, 20.0], 2)]
1571+
fn test_get_min_index(#[case] running_runtimes: Vec<f64>, #[case] expected_min_idx: usize) {
1572+
let min_idx = get_min_index(&running_runtimes);
1573+
1574+
assert_eq!(min_idx, expected_min_idx);
1575+
}
15891576
}

0 commit comments

Comments
 (0)