Skip to content

Commit 4607765

Browse files
authored
Schedule bringup true targets for guaranteed policy repos (flutter#3139)
Fixes: flutter/flutter#136361
1 parent 4e9d24d commit 4607765

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

app_dart/lib/src/service/scheduler.dart

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,10 @@ class Scheduler {
142142
policy = GuaranteedPolicy();
143143
}
144144
final int? priority = await policy.triggerPriority(task: task, datastore: datastore);
145-
// Skip scheduling `bringup: true` targets. They may be newly created and
146-
// their corresponding LUCI builder configs may not be ready yet considering we
147-
// disabled the `ci_yaml roller` backfill. Existing `bringup: true` targets
148-
// can rely on backfiller to get tasks scheduled and executed.
149-
if (priority != null && !target.value.bringup) {
145+
if (_shouldSchedule(priority, target.value.bringup, policy)) {
150146
// Mark task as in progress to ensure it isn't scheduled over
151147
task.status = Task.statusInProgress;
152-
toBeScheduled.add(Tuple<Target, Task, int>(target, task, priority));
148+
toBeScheduled.add(Tuple<Target, Task, int>(target, task, priority!));
153149
}
154150
}
155151

@@ -169,6 +165,22 @@ class Scheduler {
169165
await _uploadToBigQuery(commit);
170166
}
171167

168+
/// Checks whether the task should be scheduled.
169+
///
170+
/// Skips scheduling `bringup: true` targets for BatchPolicy. For BatchPolicy,
171+
/// targets may be newly created and their corresponding LUCI builder configs may
172+
/// not be ready yet considering we disabled the `ci_yaml roller` backfill.
173+
/// Existing `bringup: true` targets can rely on backfiller to get tasks scheduled and executed.
174+
bool _shouldSchedule(int? priority, bool bringup, SchedulerPolicy policy) {
175+
if (priority == null) {
176+
return false;
177+
}
178+
if (bringup) {
179+
return policy is! BatchPolicy;
180+
}
181+
return true;
182+
}
183+
172184
/// Schedule all builds in batch requests instead of a single request.
173185
///
174186
/// Each batch request contains [Config.batchSize] builds to be scheduled.

app_dart/test/service/scheduler_test.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ targets:
408408
expect(db.values.values.whereType<Task>().where((Task task) => task.status == Task.statusInProgress).length, 1);
409409
});
410410

411-
test('skip scheduling bringup true targets', () async {
411+
test('skip scheduling bringup true targets for BatchPolicy', () async {
412412
final PullRequest mergedPr = generatePullRequest();
413413

414414
httpClient = MockClient((http.Request request) async {
@@ -423,7 +423,6 @@ targets:
423423
- name: Linux B
424424
scheduler: cocoon
425425
bringup: true
426-
427426
''',
428427
200,
429428
);
@@ -439,6 +438,37 @@ targets:
439438
expect(taskB.status, Task.statusNew);
440439
});
441440

441+
test('schedule bringup true targets for GuaranteedPolicy', () async {
442+
final PullRequest mergedPr = generatePullRequest(repo: 'engine', branch: 'main');
443+
444+
httpClient = MockClient((http.Request request) async {
445+
if (request.url.path.contains('.ci.yaml')) {
446+
return http.Response(
447+
'''
448+
enabled_branches:
449+
- main
450+
targets:
451+
- name: Linux A
452+
scheduler: cocoon
453+
- name: Linux B
454+
scheduler: cocoon
455+
bringup: true
456+
457+
''',
458+
200,
459+
);
460+
}
461+
throw Exception('Failed to find ${request.url.path}');
462+
});
463+
await scheduler.addPullRequest(mergedPr);
464+
expect(db.values.values.whereType<Commit>().length, 1);
465+
expect(db.values.values.whereType<Task>().length, 2);
466+
final Task taskA = db.values.values.whereType<Task>().where((task) => task.name == 'Linux A').single;
467+
final Task taskB = db.values.values.whereType<Task>().where((task) => task.name == 'Linux B').single;
468+
expect(taskA.status, Task.statusInProgress);
469+
expect(taskB.status, Task.statusInProgress);
470+
});
471+
442472
test('does not schedule tasks against non-merged PRs', () async {
443473
final PullRequest notMergedPr = generatePullRequest(merged: false);
444474
await scheduler.addPullRequest(notMergedPr);

0 commit comments

Comments
 (0)