Skip to content

Commit

Permalink
fix: add null guard in duration format helper + test
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeSeqLabs committed Aug 17, 2023
1 parent a93504e commit dc28650
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/main/java/io/seqera/tower/cli/utils/FormatHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@

package io.seqera.tower.cli.utils;

import io.seqera.tower.model.ActionResponseDto;
import io.seqera.tower.model.ActionStatus;
import io.seqera.tower.model.ComputeEnvStatus;
import io.seqera.tower.model.ListActionsResponseActionInfo;
import io.seqera.tower.model.OrgRole;
import io.seqera.tower.model.ParticipantType;
import io.seqera.tower.model.PipelineDbDto;
import io.seqera.tower.model.WorkflowStatus;
import io.seqera.tower.model.ListLabelsResponse;
import io.seqera.tower.model.ListWorkflowsResponseListWorkflowsElement;
import io.seqera.tower.model.*;
import picocli.CommandLine;

import java.time.Duration;
Expand All @@ -39,6 +30,10 @@ public static String formatDate(OffsetDateTime date) {
}

public static String formatDurationMillis(Long duration) {
if (duration == null) {
return "";
}

Duration d = Duration.ofMillis(duration);
long days = d.toDaysPart();
long hours = d.toHoursPart();
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/io/seqera/tower/cli/runs/TaskCmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,28 @@ void testTaskDetail(MockServerClient mock) throws JsonProcessingException {
assertEquals(StringUtils.chop(new TaskView(general, command, environment, times, resources, usage).toString()), out.stdOut);
assertEquals(0, out.exitCode);
}

@Test
void testTaskDetailWithNullValues(MockServerClient mock) throws JsonProcessingException {
mock.when(
request().withMethod("GET").withPath("/workflow/5J9pBnWd6uoC3w/task/1"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("runs/task_detail_null_values")).withContentType(MediaType.APPLICATION_JSON)
);

ExecOut out = exec(mock,"runs", "view", "-i", "5J9pBnWd6uoC3w", "task", "-t", "1", "--execution-time", "--resources-requested", "--resources-usage");

Task task = parseJson(new String(loadResource("runs/task_object_null_values")), Task.class);

Map<String, Object> general = TaskCmd.parseGeneralData(task);
String command = task.getScript() != null ? task.getScript() : null;
String environment = task.getEnv() != null ? task.getEnv() : null;
Map<String, Object> times = TaskCmd.parseExecutionTimeData(task);
Map<String, Object> resources = TaskCmd.parseResourcesRequestedData(task);
Map<String, Object> usage = TaskCmd.parseResourcesUsageData(task);

assertEquals("", out.stdErr);
assertEquals(StringUtils.chop(new TaskView(general, command, environment, times, resources, usage).toString()), out.stdOut);
assertEquals(0, out.exitCode);
}
}
53 changes: 53 additions & 0 deletions src/test/resources/runcmd/runs/task_detail_null_values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"task": {
"id": 232916258,
"taskId": 1,
"status": "COMPLETED",
"dateCreated": "2021-11-15T14:59:36Z",
"lastUpdated": "2021-11-15T15:06:58Z",
"submit": "2021-11-15T14:59:36Z",
"start": "2021-11-15T15:06:38Z",
"complete": "2021-11-15T15:06:58Z",
"attempt": 1,
"scratch": null,
"workdir": "s3://nextflow-ci/scratch/5J9pBnWd6uoC3w/38/2d0f03566d485112b53f082c477338",
"env": "PYTHONNOUSERSITE=1\nR_PROFILE_USER=/.Rprofile\nR_ENVIRON_USER=/.Renviron\n",
"cloudZone": "eu-west-1a",
"priceModel": "spot",
"cost": null,
"errorAction": null,
"exitStatus": 0,
"realtime": 0,
"nativeId": "ca1878f1-169c-4013-b30d-c5807ea1a3dd",
"pcpu": 63.6,
"pmem": 0,
"rss": 10067968,
"vmem": null,
"peakRss": 10067968,
"peakVmem": 33243136,
"rchar": 673556,
"wchar": 1428,
"syscr": 242,
"syscw": 17,
"readBytes": 7213056,
"writeBytes": 12288,
"volCtxt": 15,
"invCtxt": 4,
"process": "NFCORE_RNASEQ:RNASEQ:INPUT_CHECK:SAMPLESHEET_CHECK",
"disk": null,
"container": "quay.io/biocontainers/python:3.8.3",
"queue": "TowerForge-1voNN3Mve8r49Ek6hFCN5v-work",
"cpus": 1,
"memory": 6442450944,
"machineType": "r4.large",
"executor": "awsbatch",
"tag": "samplesheet_test.csv",
"time": null,
"duration": null,
"script": "\ncheck_samplesheet.py \\\n samplesheet_test.csv \\\n samplesheet.valid.csv\n\ncat <<-END_VERSIONS > versions.yml\nSAMPLESHEET_CHECK:\n python: $(python --version | sed 's/Python //g')\nEND_VERSIONS\n",
"module": [],
"hash": "38/2d0f03",
"exit": "0",
"name": "NFCORE_RNASEQ:RNASEQ:INPUT_CHECK:SAMPLESHEET_CHECK (samplesheet_test.csv)"
}
}
51 changes: 51 additions & 0 deletions src/test/resources/runcmd/runs/task_object_null_values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"id": 232916258,
"taskId": 1,
"status": "COMPLETED",
"dateCreated": "2021-11-15T14:59:36Z",
"lastUpdated": null,
"submit": "2021-11-15T14:59:36Z",
"start": "2021-11-15T15:06:38Z",
"complete": "2021-11-15T15:06:58Z",
"attempt": 1,
"scratch": null,
"workdir": "s3://nextflow-ci/scratch/5J9pBnWd6uoC3w/38/2d0f03566d485112b53f082c477338",
"env": "PYTHONNOUSERSITE=1\nR_PROFILE_USER=/.Rprofile\nR_ENVIRON_USER=/.Renviron\n",
"cloudZone": "eu-west-1a",
"priceModel": "spot",
"cost": null,
"errorAction": null,
"exitStatus": 0,
"realtime": 0,
"nativeId": "ca1878f1-169c-4013-b30d-c5807ea1a3dd",
"pcpu": 63.6,
"pmem": 0,
"rss": 10067968,
"vmem": null,
"peakRss": 10067968,
"peakVmem": 33243136,
"rchar": 673556,
"wchar": 1428,
"syscr": 242,
"syscw": 17,
"readBytes": 7213056,
"writeBytes": 12288,
"volCtxt": 15,
"invCtxt": 4,
"process": "NFCORE_RNASEQ:RNASEQ:INPUT_CHECK:SAMPLESHEET_CHECK",
"container": "quay.io/biocontainers/python:3.8.3",
"queue": "TowerForge-1voNN3Mve8r49Ek6hFCN5v-work",
"cpus": 1,
"memory": 6442450944,
"machineType": "r4.large",
"executor": "awsbatch",
"tag": "samplesheet_test.csv",
"disk": null,
"time": null,
"duration": null,
"script": "\ncheck_samplesheet.py \\\n samplesheet_test.csv \\\n samplesheet.valid.csv\n\ncat <<-END_VERSIONS > versions.yml\nSAMPLESHEET_CHECK:\n python: $(python --version | sed 's/Python //g')\nEND_VERSIONS\n",
"module": [],
"hash": "38/2d0f03",
"exit": "0",
"name": "NFCORE_RNASEQ:RNASEQ:INPUT_CHECK:SAMPLESHEET_CHECK (samplesheet_test.csv)"
}

0 comments on commit dc28650

Please sign in to comment.