Skip to content

Commit ee61cf9

Browse files
committed
minor fixes
Signed-off-by: Lillie Dae <lillie.dae@answerdigital.com>
1 parent 69d7137 commit ee61cf9

File tree

8 files changed

+54
-26
lines changed

8 files changed

+54
-26
lines changed

src/WorkflowManager/Database/Repositories/ArtifactsRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static ArtifactReceivedDetails FromArtifact(Artifact artifact) =>
4646

4747
public class ArtifactReceivedItems
4848
{
49-
public BsonObjectId Id { get; set; }
49+
public string Id { get; set; }
5050

5151
/// <summary>
5252
/// Gets or Sets WorkflowInstanceId.
@@ -181,6 +181,7 @@ public async Task AddOrUpdateItemAsync(string workflowInstanceId, string taskId,
181181
}
182182
else
183183
{
184+
item.Artifacts = item.Artifacts.Concat(existing.Artifacts).ToList();
184185
var update = Builders<ArtifactReceivedItems>.Update.Set(a => a.Artifacts, item.Artifacts);
185186
await _artifactReceivedItemsCollection
186187
.UpdateOneAsync(a => a.WorkflowInstanceId == workflowInstanceId && a.TaskId == taskId, update)

src/WorkflowManager/WorkflowExecuter/Services/WorkflowExecuterService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public async Task<bool> ProcessArtifactReceivedAsync(ArtifactsReceivedEvent mess
215215
{
216216
previouslyReceivedArtifactsFromRepo = new List<ArtifactReceivedItems>() { new ArtifactReceivedItems()
217217
{
218+
Id = workflowInstanceId + taskId,
218219
TaskId = taskId,
219220
WorkflowInstanceId = workflowInstanceId,
220221
Artifacts = message.Artifacts.Select(ArtifactReceivedDetails.FromArtifact).ToList()

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/Features/ArtifactReceivedEvent.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Publishing a artifact received event is consumed by the Workflow Manager.
2121
Scenario Outline: Publish a valid Artifact Received Event which creates an entry.
2222
Given I have a clinical workflow <clinicalWorkflow> I have a Workflow Instance <workflowInstance>
2323
When I publish a Artifact Received Event <artifactReceivedEvent>
24-
Then I can see a Artifact Received Item is created
24+
Then I can see 2 Artifact Received Items is created
2525
Examples:
2626
| clinicalWorkflow | workflowInstance | artifactReceivedEvent |
2727
| Workflow_Revision_For_Artifact_ReceivedEvent_1 | Workflow_Instance_For_Artifact_ReceivedEvent_1 | Test1 |

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/Hooks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public static void ClearTestData()
168168
MongoClient?.DeleteAllWorkflowRevisionDocuments();
169169
MongoClient?.DeleteAllWorkflowInstances();
170170
MongoClient?.DeleteAllPayloadDocuments();
171+
MongoClient?.DeleteAllArtifactDocuments();
171172
}
172173

173174
[BeforeTestRun(Order = 3)]

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/StepDefinitions/ArtifactReceivedEventStepDefinitions.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,43 +84,45 @@ public async Task GivenIHaveAClinicalWorkflowIHaveAWorkflowInstance(string clini
8484
_outputHelper.WriteLine($"Retrieving workflow revision with name={clinicalWorkflowName}");
8585
await MongoClient.CreateWorkflowRevisionDocumentAsync(workflowRevision);
8686

87-
await MongoClient.CreateArtifactsEventsDocumentAsync(artifactReceivedItems);
87+
try
88+
{
89+
await MongoClient.CreateArtifactsEventsDocumentAsync(artifactReceivedItems);
90+
}
91+
catch (Exception e)
92+
{
93+
}
8894

89-
// await Task.WhenAll(task1, task2, task3, task4).ConfigureAwait(false);
9095
_outputHelper.WriteLine("Seeding Data Tasks complete");
9196
}
9297

9398
[Then(@"I can see a Artifact Received Item is created")]
9499
public void ThenICanSeeAArtifactReceivedItemIsCreated()
95100
{
96-
ThenICanSeeAArtifactReceivedItemIsCreated(1);
101+
ThenICanSeeXArtifactReceivedItemIsCreated(1);
97102
}
98103

99104
[Then(@"I can see ([1-9]*) Artifact Received Items are created")]
100105
[Then(@"I can see ([0-9]*) Artifact Received Items is created")]
101-
public void ThenICanSeeAArtifactReceivedItemIsCreated(int count)
106+
public void ThenICanSeeXArtifactReceivedItemIsCreated(int count)
102107
{
103108
_outputHelper.WriteLine($"Retrieving {count} workflow instance/s using the payloadid={DataHelper.WorkflowRequestMessage.PayloadId.ToString()}");
104109
RetryPolicy.Execute(() =>
105110
{
106111
var artifactsReceivedItems = DataHelper.GetArtifactsReceivedItemsFromDB(count, DataHelper.ArtifactsReceivedEvent);
107-
108-
foreach (var artifactsReceivedItem in artifactsReceivedItems)
112+
if (artifactsReceivedItems.Any())
109113
{
110-
var workflowInstance = DataHelper.WorkflowInstances.FirstOrDefault(x => x.Id.Equals(artifactsReceivedItem.WorkflowInstanceId));
111-
var workflowRevision = DataHelper.WorkflowRevisions
112-
.FirstOrDefault(x => x.WorkflowId.Equals(workflowInstance!.WorkflowId));
113-
114-
if (workflowRevision != null)
114+
foreach (var artifactsReceivedItem in artifactsReceivedItems)
115115
{
116-
Assertions.AssertArtifactsReceivedItemMatchesExpectedWorkflow(artifactsReceivedItem, workflowRevision);
117-
}
118-
else
119-
{
120-
throw new Exception($"Workflow not found for workflowId {artifactsReceivedItem.WorkflowInstanceId}");
116+
var wfiId = artifactsReceivedItems.FirstOrDefault().WorkflowInstanceId;
117+
var wfi = DataHelper.WorkflowInstances.FirstOrDefault(a => a.Id == wfiId);
118+
var workflow = DataHelper.WorkflowRevisions.FirstOrDefault(w => w.WorkflowId == wfi.WorkflowId);
119+
if (workflow is null)
120+
{
121+
throw new Exception("Failing Test");
122+
}
123+
Assertions.AssertArtifactsReceivedItemMatchesExpectedWorkflow(artifactsReceivedItem, workflow, wfi);
121124
}
122125
}
123-
124126
});
125127
_outputHelper.WriteLine($"Retrieved {count} workflow instance/s");
126128
}

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/Support/Assertions.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,20 @@ public void AssertExecutionStats(ExecutionStats executionStats, TaskDispatchEven
552552
Output.WriteLine("Details ExecutionStats are correct");
553553
}
554554

555-
public static void AssertArtifactsReceivedItemMatchesExpectedWorkflow(ArtifactReceivedItems artifactsReceivedItem, WorkflowRevision workflowRevision)
556-
{
557-
artifactsReceivedItem.WorkflowInstanceId.Should().Be(workflowRevision.WorkflowId);
558-
artifactsReceivedItem.TaskId.Should().Be(workflowRevision.Workflow!.Tasks[0].Id);
559-
artifactsReceivedItem.Artifacts.Count.Should().Be(workflowRevision.Workflow!.Tasks[0].Artifacts.Output.Length);
555+
public static void AssertArtifactsReceivedItemMatchesExpectedWorkflow(
556+
ArtifactReceivedItems artifactsReceivedItem, WorkflowRevision workflowRevision,
557+
WorkflowInstance? workflowInstance)
558+
{
559+
artifactsReceivedItem.WorkflowInstanceId.Should().Be(workflowInstance?.Id);
560+
var task = workflowRevision.Workflow!.Tasks.FirstOrDefault(t => t.Id == artifactsReceivedItem.TaskId);
561+
task.Should().NotBeNull();
562+
artifactsReceivedItem.TaskId.Should().Be(task!.Id);
563+
artifactsReceivedItem.Artifacts.Count.Should().Be(task.Artifacts.Output.Length);
560564
artifactsReceivedItem.Received.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(20));
561-
artifactsReceivedItem.Artifacts[0].Path.Should().Be(workflowRevision.Workflow.Tasks[0].Artifacts.Output[0].Value);
565+
foreach (var artifact in task.Artifacts.Output)
566+
{
567+
artifactsReceivedItem.Artifacts.FirstOrDefault(t => t.Type == artifact.Type).Should().NotBeNull();
568+
}
562569
}
563570
}
564571
}

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/Support/DataHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public List<ArtifactReceivedItems> GetArtifactsReceivedItemsFromDB(int count, Ar
303303
{
304304
ArtifactsReceivedItems = MongoClient.GetArtifactsReceivedItems(artifactsReceivedEvent);
305305

306-
if (ArtifactsReceivedItems.Count == count)
306+
if (ArtifactsReceivedItems.FirstOrDefault()?.Artifacts.Count == count)
307307
{
308308
return ArtifactsReceivedItems;
309309
}
@@ -600,6 +600,7 @@ public class ArtifactsEventTestData
600600
{
601601
new ArtifactReceivedItems()
602602
{
603+
Id = "e545de90-c936-40ab-ad11-19ef07f49607" + "d32d5769-4ecf-4639-a048-6ecf2cced04a",
603604
WorkflowInstanceId = "d32d5769-4ecf-4639-a048-6ecf2cced04a",
604605
TaskId = "e545de90-c936-40ab-ad11-19ef07f49607",
605606
Received = DateTime.UtcNow,

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/Support/MongoClientUtil.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,21 @@ public void DeleteAllPayloadDocuments()
239239
});
240240
}
241241

242+
public void DeleteAllArtifactDocuments()
243+
{
244+
RetryMongo.Execute(() =>
245+
{
246+
ArtifactsCollection.DeleteMany("{ }");
247+
248+
var artifacts = ArtifactsCollection.Find("{ }").ToList();
249+
250+
if (artifacts.Count > 0)
251+
{
252+
throw new Exception("All payloads are not deleted!");
253+
}
254+
});
255+
}
256+
242257
#endregion Payload
243258

244259
#region ExecutionStats

0 commit comments

Comments
 (0)