Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make task.isTeeTask() the first test in `TaskUpdateManager#running2… #585

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
- Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575)
- Refactor unnotified detectors to avoid code duplication. (#580)
- Use `==` or `!=` operators to test the equality of enums. (#584)
- Rearrange checks order to avoid call to database. (#585)
### Dependency Upgrades
- Upgrade to `iexec-common` 8.1.0-NEXT-SNAPSHOT. (#571 #575 #586)
- Add new `iexec-commons-poco` 2.0.0 dependency. (#571 #574 #586)
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/iexec/core/task/update/TaskUpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,25 +330,26 @@ void running2ConsensusReached(Task task) {
void running2Finalized2Completed(Task task) {
boolean isTaskInRunningStatus = task.getCurrentStatus() == RUNNING;
final String chainTaskId = task.getChainTaskId();
final Optional<ReplicatesList> oReplicatesList = replicatesService.getReplicatesList(chainTaskId);

if (!task.isTeeTask()) {
log.debug("Task not running in a TEE, flow running2Finalized2Completed is not possible"
+ " [chainTaskId:{}]", chainTaskId);
return;
}

if (!isTaskInRunningStatus) {
log.error("Can't transition task to `Finalized` or `Completed` when task is not `Running` " +
" [chainTaskId:{}]", chainTaskId);
return;
}

final Optional<ReplicatesList> oReplicatesList = replicatesService.getReplicatesList(chainTaskId);
if (oReplicatesList.isEmpty()) {
log.error("Can't transition task to `Finalized` or `Completed` when no replicatesList exists" +
" [chainTaskId:{}]", chainTaskId);
return;
}

if (!task.isTeeTask()) {
log.debug("Task not running in a TEE, flow running2Finalized2Completed is not possible"
+ " [chainTaskId:{}]", chainTaskId);
return;
}
final ReplicatesList replicates = oReplicatesList.get();
final int nbReplicatesWithContributeAndFinalizeStatus = replicates.getNbReplicatesWithCurrentStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ void shouldUpdateFromInitializedOrRunning2ContributionTimeout() {
void shouldNotUpdateRunning2Finalized2CompletedWhenTaskNotRunning() {
Task task = getStubTask(maxExecutionTime);
task.changeStatus(INITIALIZED);
task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG);

taskUpdateManager.running2Finalized2Completed(task);
assertThat(task.getCurrentStatus()).isEqualTo(INITIALIZED);
Expand All @@ -697,6 +698,7 @@ void shouldNotUpdateRunning2Finalized2CompletedWhenTaskNotRunning() {
void shouldNotUpdateRunning2Finalized2CompletedWhenNoReplicates() {
Task task = getStubTask(maxExecutionTime);
task.changeStatus(RUNNING);
task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG);

when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.empty());

Expand Down