Skip to content

Commit

Permalink
Skip scheduling recent failed tasks if an earlier task is already InP…
Browse files Browse the repository at this point in the history
…rogress (#2934)

Fixes: flutter/flutter#110716
  • Loading branch information
keyonghan authored Jul 14, 2023
1 parent 9080291 commit 9081694
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app_dart/lib/src/service/scheduler/policy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class BatchPolicy implements SchedulerPolicy {
required DatastoreService datastore,
}) async {
final List<Task> recentTasks = await datastore.queryRecentTasksByName(name: task.name!).toList();
// Skip scheduling if there is already a running task.
if (recentTasks.any((Task task) => task.status == Task.statusInProgress)) {
return null;
}

// Ensure task isn't considered in recentTasks
recentTasks.removeWhere((Task t) => t.commitKey == task.commitKey);
if (recentTasks.length < kBatchSize) {
Expand Down
17 changes: 17 additions & 0 deletions app_dart/test/service/scheduler/policy_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ void main() {
generateTask(1, status: Task.statusSucceeded),
];

final List<Task> failedWithRunning = <Task>[
generateTask(6),
generateTask(5),
generateTask(4),
generateTask(3, status: Task.statusFailed),
generateTask(2, status: Task.statusInProgress),
generateTask(1),
];

test('triggers if less tasks than batch size', () async {
db.addOnQuery<Task>((Iterable<Task> results) => allPending);
expect(
Expand All @@ -89,6 +98,14 @@ void main() {
);
});

test('does not trigger on recent failures if there is already a running task', () async {
db.addOnQuery<Task>((Iterable<Task> results) => failedWithRunning);
expect(
await policy.triggerPriority(task: generateTask(7), datastore: datastore),
isNull,
);
});

test('does not trigger when a test was recently scheduled', () async {
db.addOnQuery<Task>((Iterable<Task> results) => latestFinishedButRestPending);
expect(await policy.triggerPriority(task: generateTask(7), datastore: datastore), isNull);
Expand Down

0 comments on commit 9081694

Please sign in to comment.