Skip to content

Commit 307d787

Browse files
fix tests
Signed-off-by: Jack Schofield <[email protected]>
1 parent 52fdeeb commit 307d787

File tree

2 files changed

+70
-128
lines changed

2 files changed

+70
-128
lines changed

src/WorkflowExecuter/Services/WorkflowExecuterService.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,7 @@ private async Task<bool> DispatchTaskDestinations(WorkflowInstance workflowInsta
387387

388388
if (string.Equals(taskExec.TaskType, TaskTypeConstants.ExportTask, StringComparison.InvariantCultureIgnoreCase))
389389
{
390-
var artifactValues = GetDicomExports(workflow, workflowInstance, taskExec);
391-
392-
if (artifactValues.Any() is false)
393-
{
394-
await HandleTaskDestinations(workflowInstance, workflow, taskExec, correlationId);
395-
}
396-
397-
await DispatchDicomExport(workflowInstance, taskExec, workflow.Workflow?.InformaticsGateway?.ExportDestinations, artifactValues, correlationId);
390+
await HandleDicomExport(workflow, workflowInstance, taskExec, correlationId);
398391

399392
continue;
400393
}

tests/UnitTests/WorkflowExecuter.Tests/Services/WorkflowExecuterServiceTests.cs

Lines changed: 69 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,75 @@ public async Task ProcessPayload_RouterTaskWithMultipleDestinations_DispatchesMu
303303
Assert.True(result);
304304
}
305305

306+
[Fact]
307+
public async Task ProcessPayload_WithExportTask_DispatchesExport()
308+
{
309+
var workflowId1 = Guid.NewGuid().ToString();
310+
var workflowId2 = Guid.NewGuid().ToString();
311+
var workflowRequest = new WorkflowRequestEvent
312+
{
313+
Bucket = "testbucket",
314+
CalledAeTitle = "aetitle",
315+
CallingAeTitle = "aetitle",
316+
CorrelationId = Guid.NewGuid().ToString(),
317+
Timestamp = DateTime.UtcNow,
318+
Workflows = new List<string>
319+
{
320+
workflowId1.ToString()
321+
}
322+
};
323+
324+
var workflows = new List<WorkflowRevision>
325+
{
326+
new WorkflowRevision
327+
{
328+
Id = Guid.NewGuid().ToString(),
329+
WorkflowId = workflowId1,
330+
Revision = 1,
331+
Workflow = new Workflow
332+
{
333+
Name = "Workflowname1",
334+
Description = "Workflowdesc1",
335+
Version = "1",
336+
InformaticsGateway = new InformaticsGateway
337+
{
338+
AeTitle = "aetitle",
339+
ExportDestinations = new string[] { "PROD_PACS" }
340+
},
341+
Tasks = new TaskObject[]
342+
{
343+
new TaskObject {
344+
Id = Guid.NewGuid().ToString(),
345+
Type = "export",
346+
Description = "taskdesc",
347+
Artifacts = new ArtifactMap
348+
{
349+
Input = new Artifact[] { new Artifact { Name = "dicomexport", Value = "{{ context.input }}" } }
350+
},
351+
TaskDestinations = new TaskDestination[]
352+
{
353+
}
354+
}
355+
}
356+
}
357+
}
358+
};
359+
360+
_workflowRepository.Setup(w => w.GetByWorkflowsIdsAsync(new List<string> { workflowId1.ToString() })).ReturnsAsync(workflows);
361+
_workflowRepository.Setup(w => w.GetByWorkflowIdAsync(workflowId1.ToString())).ReturnsAsync(workflows[0]);
362+
_workflowInstanceRepository.Setup(w => w.CreateAsync(It.IsAny<List<WorkflowInstance>>())).ReturnsAsync(true);
363+
_workflowInstanceRepository.Setup(w => w.UpdateTasksAsync(It.IsAny<string>(), It.IsAny<List<TaskExecution>>())).ReturnsAsync(true);
364+
_workflowInstanceRepository.Setup(w => w.GetByWorkflowsIdsAsync(It.IsAny<List<string>>())).ReturnsAsync(new List<WorkflowInstance>());
365+
_workflowInstanceRepository.Setup(w => w.UpdateTaskStatusAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TaskExecutionStatus>())).ReturnsAsync(true);
366+
_artifactMapper.Setup(a => a.ConvertArtifactVariablesToPath(It.IsAny<Artifact[]>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(new Dictionary<string, string>() { { "dicomexport", "/dcm" } });
367+
368+
var result = await WorkflowExecuterService.ProcessPayload(workflowRequest, new Payload() { Id = Guid.NewGuid().ToString() });
369+
370+
_messageBrokerPublisherService.Verify(w => w.Publish($"{_configuration.Value.Messaging.Topics.ExportRequestPrefix}.{_configuration.Value.Messaging.DicomAgents.DicomWebAgentName}", It.IsAny<Message>()), Times.Exactly(1));
371+
372+
Assert.True(result);
373+
}
374+
306375
[Fact]
307376
public async Task ProcessPayload_FileNotFound_FailsWorkflow()
308377
{
@@ -1095,126 +1164,6 @@ public async Task ProcessTaskUpdate_ValidTaskUpdateEventWithOutputArtifacts_Retu
10951164
response.Should().BeTrue();
10961165
}
10971166

1098-
[Fact]
1099-
public async Task ProcessTaskUpdate_ValidTaskUpdateHasDicomImages_ReturnsTrue()
1100-
{
1101-
var workflowInstanceId = Guid.NewGuid().ToString();
1102-
1103-
var updateEvent = new TaskUpdateEvent
1104-
{
1105-
WorkflowInstanceId = workflowInstanceId,
1106-
TaskId = "pizza",
1107-
ExecutionId = Guid.NewGuid().ToString(),
1108-
Status = TaskExecutionStatus.Succeeded,
1109-
Reason = FailureReason.None,
1110-
Message = "This is a message",
1111-
Metadata = new Dictionary<string, object>(),
1112-
CorrelationId = Guid.NewGuid().ToString(),
1113-
Outputs = new List<Messaging.Common.Storage>
1114-
{
1115-
new Messaging.Common.Storage
1116-
{
1117-
Name = "artifactname",
1118-
RelativeRootPath = "path/to/artifact"
1119-
}
1120-
}
1121-
};
1122-
1123-
var workflowId = Guid.NewGuid().ToString();
1124-
1125-
var workflow = new WorkflowRevision
1126-
{
1127-
Id = Guid.NewGuid().ToString(),
1128-
WorkflowId = workflowId,
1129-
Revision = 1,
1130-
Workflow = new Workflow
1131-
{
1132-
Name = "Workflowname2",
1133-
Description = "Workflowdesc2",
1134-
Version = "1",
1135-
InformaticsGateway = new InformaticsGateway
1136-
{
1137-
AeTitle = "aetitle",
1138-
ExportDestinations = new string[] { "PROD_PACS" }
1139-
},
1140-
Tasks = new TaskObject[]
1141-
{
1142-
new TaskObject {
1143-
Id = "pizza",
1144-
Type = "type",
1145-
Description = "taskdesc",
1146-
TaskDestinations = new TaskDestination[]
1147-
{
1148-
new TaskDestination
1149-
{
1150-
Name = "coffee"
1151-
},
1152-
new TaskDestination
1153-
{
1154-
Name = "doughnuts"
1155-
}
1156-
}
1157-
},
1158-
new TaskObject {
1159-
Id = "coffee",
1160-
Type = "type",
1161-
Description = "taskdesc"
1162-
},
1163-
new TaskObject {
1164-
Id = "doughnuts",
1165-
Type = "type",
1166-
Description = "taskdesc"
1167-
}
1168-
}
1169-
}
1170-
};
1171-
1172-
var workflowInstance = new WorkflowInstance
1173-
{
1174-
Id = workflowInstanceId,
1175-
WorkflowId = workflowId,
1176-
PayloadId = Guid.NewGuid().ToString(),
1177-
Status = Status.Created,
1178-
BucketId = "bucket",
1179-
Tasks = new List<TaskExecution>
1180-
{
1181-
new TaskExecution
1182-
{
1183-
TaskId = "pizza",
1184-
Status = TaskExecutionStatus.Dispatched,
1185-
OutputDirectory = "test/output/directory/"
1186-
},
1187-
new TaskExecution
1188-
{
1189-
TaskId = "coffee",
1190-
Status = TaskExecutionStatus.Dispatched,
1191-
OutputDirectory = "test/output/directory/"
1192-
}
1193-
}
1194-
};
1195-
1196-
var artifactDict = updateEvent.Outputs.ToArtifactDictionary();
1197-
var dicomFiles = new List<string>
1198-
{
1199-
"/test/folder/dicom.dcm",
1200-
"/dicom2.dcm"
1201-
};
1202-
1203-
_workflowInstanceRepository.Setup(w => w.UpdateTaskStatusAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TaskExecutionStatus>())).ReturnsAsync(true);
1204-
_workflowInstanceRepository.Setup(w => w.GetByWorkflowInstanceIdAsync(workflowInstance.Id)).ReturnsAsync(workflowInstance);
1205-
_workflowInstanceRepository.Setup(w => w.UpdateTasksAsync(workflowInstance.Id, It.IsAny<List<TaskExecution>>())).ReturnsAsync(true);
1206-
_workflowRepository.Setup(w => w.GetByWorkflowIdAsync(workflowInstance.WorkflowId)).ReturnsAsync(workflow);
1207-
_storageService.Setup(w => w.VerifyObjectsExistAsync(workflowInstance.BucketId, artifactDict)).ReturnsAsync(artifactDict);
1208-
_dicomService.Setup(d => d.GetDicomPathsForTaskAsync(workflowInstance.Tasks.First().OutputDirectory, workflowInstance.BucketId)).ReturnsAsync(dicomFiles);
1209-
1210-
var response = await WorkflowExecuterService.ProcessTaskUpdate(updateEvent);
1211-
1212-
_messageBrokerPublisherService.Verify(w => w.Publish(_configuration.Value.Messaging.Topics.TaskDispatchRequest, It.IsAny<Message>()), Times.Exactly(0));
1213-
_messageBrokerPublisherService.Verify(w => w.Publish($"{_configuration.Value.Messaging.Topics.ExportRequestPrefix}.{_configuration.Value.Messaging.DicomAgents.DicomWebAgentName}", It.IsAny<Message>()), Times.Exactly(1));
1214-
1215-
response.Should().BeTrue();
1216-
}
1217-
12181167
[Fact]
12191168
public async Task ProcessTaskUpdate_ValidTaskUpdateEventWorkflowDoesNotExist_ReturnsTrue()
12201169
{

0 commit comments

Comments
 (0)