Skip to content

Commit

Permalink
Revert "Skip post-submit task status update when build hasn't started" (
Browse files Browse the repository at this point in the history
#2960)

Reverts #2958
  • Loading branch information
ricardoamador authored Jul 28, 2023
1 parent 8eb603e commit 69c64f5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 51 deletions.
6 changes: 4 additions & 2 deletions app_dart/lib/src/model/appengine/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ class Task extends Model<int> {

if (build.status == Status.started) {
return status = statusInProgress;
} else if (build.status == Status.scheduled) {
// Check for scheduled.
return status = statusNew;
}

switch (build.result) {
Expand All @@ -451,8 +454,7 @@ class Task extends Model<int> {
case Result.failure:
return status = statusFailed;
default:
log.warning('keep task status as build result is ${build.result}.');
return status;
throw BadRequestException('${build.result} is unknown');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,9 @@ class PostsubmitLuciSubscription extends SubscriptionHandler {
}
log.fine('Found $task');

final String oldTaskStatus = task.status;
task.updateFromBuild(build);
if (task.status != oldTaskStatus) {
await datastore.insert(<Task>[task]);
log.fine('Updated task status from $oldTaskStatus to ${task.status}');
} else {
log.fine('Skip updating task as status remains unchanged: ${task.status}');
return Body.empty;
}
await datastore.insert(<Task>[task]);
log.fine('Updated datastore');

final Commit commit = await datastore.lookupByValue<Commit>(commitKey);
final CiYaml ciYaml = await scheduler.getCiYaml(commit);
Expand Down
17 changes: 0 additions & 17 deletions app_dart/test/model/task_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,6 @@ void main() {
task.updateFromBuild(build);
expect(task.status, Task.statusCancelled);
});

test('does not update when build result is null', () {
final pm.Build build = generatePushMessageBuild(
1,
status: pm.Status.scheduled,
result: null,
);
final Task task = generateTask(
1,
buildNumber: 1,
status: Task.statusNew,
);

expect(task.status, Task.statusNew);
task.updateFromBuild(build);
expect(task.status, Task.statusNew);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,6 @@ void main() {
expect(task.endTimestamp, 1565049193786);
});

test('keep task status when build is with null result', () async {
final Commit commit = generateCommit(1, sha: '87f88734747805589f2131753620d61b22922822');
final Task task = generateTask(
4507531199512576,
name: 'Linux A',
parent: commit,
status: Task.statusNew,
);
config.db.values[task.key] = task;
config.db.values[commit.key] = commit;
tester.message = createBuildbucketPushMessage(
'SCHEDULED',
builderName: 'Linux A',
result: null,
userData: '{\\"task_key\\":\\"${task.key.id}\\", \\"commit_key\\":\\"${task.key.parent?.id}\\"}',
);

expect(task.status, Task.statusNew);
expect(task.attempts, 1);
expect(await tester.post(handler), Body.empty);
expect(task.status, Task.statusNew);
});

test('does not fail on empty user data', () async {
tester.message = createBuildbucketPushMessage(
'COMPLETED',
Expand Down
2 changes: 1 addition & 1 deletion app_dart/test/src/utilities/entity_generators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ push_message.Build generatePushMessageBuild(
String bucket = 'prod',
String name = 'Linux test_builder',
push_message.Status? status = push_message.Status.completed,
push_message.Result? result = push_message.Result.success,
push_message.Result result = push_message.Result.success,
List<String>? tags,
int buildNumber = 1,
DateTime? completedTimestamp,
Expand Down

0 comments on commit 69c64f5

Please sign in to comment.