From e98b9b772020699f36e0a2b78962579b8c66f1d3 Mon Sep 17 00:00:00 2001 From: munishchouhan Date: Thu, 5 Feb 2026 03:55:08 +0100 Subject: [PATCH] added isCompleted check in getNumSpotInterruptions Signed-off-by: munishchouhan --- .../nextflow/cloud/aws/batch/AwsBatchTaskHandler.groovy | 2 +- .../cloud/aws/batch/AwsBatchTaskHandlerTest.groovy | 9 +++++++-- .../cloud/google/batch/GoogleBatchTaskHandler.groovy | 2 +- .../cloud/google/batch/GoogleBatchTaskHandlerTest.groovy | 6 +++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/plugins/nf-amazon/src/main/nextflow/cloud/aws/batch/AwsBatchTaskHandler.groovy b/plugins/nf-amazon/src/main/nextflow/cloud/aws/batch/AwsBatchTaskHandler.groovy index 2e4efdadc5..1ceb64320e 100644 --- a/plugins/nf-amazon/src/main/nextflow/cloud/aws/batch/AwsBatchTaskHandler.groovy +++ b/plugins/nf-amazon/src/main/nextflow/cloud/aws/batch/AwsBatchTaskHandler.groovy @@ -925,7 +925,7 @@ class AwsBatchTaskHandler extends TaskHandler implements BatchHandler> false + 2 * handler.isCompleted() >> false 1 * handler.getMachineInfo() >> new CloudMachineInfo('x1.large', 'us-east-1b', PriceModel.spot) and: @@ -1195,12 +1195,14 @@ class AwsBatchTaskHandlerTest extends Specification { when: def resultNoAttempts = handler.getNumSpotInterruptions('job-123') then: + 1 * handler.isCompleted() >> true 1 * handler.describeJob('job-123') >> JobDetail.builder().attempts([]).build() resultNoAttempts == 0 when: def resultNonSpot = handler.getNumSpotInterruptions('job-456') then: + 1 * handler.isCompleted() >> true 1 * handler.describeJob('job-456') >> JobDetail.builder().attempts([attempt1, attempt2]).build() resultNonSpot == 0 } @@ -1212,18 +1214,21 @@ class AwsBatchTaskHandlerTest extends Specification { when: def resultNotCompleted = handler.getNumSpotInterruptions('job-123') then: - 1 * handler.describeJob(_) + 1 * handler.isCompleted() >> false + 0 * handler.describeJob(_) resultNotCompleted == null when: def resultNullJobId = handler.getNumSpotInterruptions(null) then: + 0 * handler.isCompleted() 0 * handler.describeJob(_) resultNullJobId == null when: def resultException = handler.getNumSpotInterruptions('job-789') then: + 1 * handler.isCompleted() >> true 1 * handler.describeJob('job-789') >> { throw new RuntimeException("Error") } resultException == null } diff --git a/plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy b/plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy index 5132fbdbf9..dada5e6c48 100644 --- a/plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy +++ b/plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy @@ -655,7 +655,7 @@ class GoogleBatchTaskHandler extends TaskHandler implements FusionAwareTask { */ protected Integer getNumSpotInterruptions(String jobId) { - if (!jobId || !taskId) { + if (!jobId || !taskId || !isCompleted()) { return null } diff --git a/plugins/nf-google/src/test/nextflow/cloud/google/batch/GoogleBatchTaskHandlerTest.groovy b/plugins/nf-google/src/test/nextflow/cloud/google/batch/GoogleBatchTaskHandlerTest.groovy index c8d12b0dc3..16321723dc 100644 --- a/plugins/nf-google/src/test/nextflow/cloud/google/batch/GoogleBatchTaskHandlerTest.groovy +++ b/plugins/nf-google/src/test/nextflow/cloud/google/batch/GoogleBatchTaskHandlerTest.groovy @@ -419,7 +419,7 @@ class GoogleBatchTaskHandlerTest extends Specification { when: def trace = handler.getTraceRecord() then: - 1 * handler.isCompleted() >> true + 2 * handler.isCompleted() >> true 1 * client.getTaskStatus('xyz-123', '0') >> taskStatus and: trace.native_id == 'xyz-123/0/789' @@ -869,6 +869,7 @@ class GoogleBatchTaskHandlerTest extends Specification { def result = handler.getNumSpotInterruptions('job-123') then: + handler.isCompleted() >> true result == 0 } @@ -900,6 +901,7 @@ class GoogleBatchTaskHandlerTest extends Specification { def result = handler.getNumSpotInterruptions('job-123') then: + handler.isCompleted() >> true result == 2 } @@ -913,6 +915,7 @@ class GoogleBatchTaskHandlerTest extends Specification { def resultIncompleteTask = handler.getNumSpotInterruptions('job-123') then: + handler.isCompleted() >> false resultNullJobId == null resultIncompleteTask == null } @@ -929,6 +932,7 @@ class GoogleBatchTaskHandlerTest extends Specification { def result = handler.getNumSpotInterruptions('job-123') then: + handler.isCompleted() >> true result == null }