Skip to content

Commit f0cc9b0

Browse files
committed
Task artifacts artfact-name integration tests
Signed-off-by: Joe Batt <[email protected]>
1 parent d7752e5 commit f0cc9b0

File tree

9 files changed

+648
-113
lines changed

9 files changed

+648
-113
lines changed

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/StepDefinitions/TaskStatusUpdateStepDefinitions.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void WhenIPublishATaskUpdateMessageWithStatus(string name, string updateS
5858
}
5959

6060
[When(@"I publish a Task Update Message (.*) with artifacts (.*) in minio")]
61-
public async Task WhenIPublishATaskUpdateMessageWithObjects(string name, string folderName)
61+
public async Task WhenIPublishATaskUpdateMessageWithArtifacts(string name, string folderName)
6262
{
6363
var taskUpdateMessage = DataHelper.GetTaskUpdateTestData(name, "succeeded");
6464

@@ -74,7 +74,21 @@ public async Task WhenIPublishATaskUpdateMessageWithObjects(string name, string
7474
}
7575

7676
var message = new JsonMessage<TaskUpdateEvent>(
77-
DataHelper.GetTaskUpdateTestData(name, "succeeded"),
77+
taskUpdateMessage,
78+
"16988a78-87b5-4168-a5c3-2cfc2bab8e54",
79+
Guid.NewGuid().ToString(),
80+
string.Empty);
81+
82+
TaskUpdatePublisher.PublishMessage(message.ToMessage());
83+
}
84+
85+
[When(@"I publish a Task Update Message (.*) with no artifacts")]
86+
public void WhenIPublishATaskUpdateMessageWithNoArtifacts(string name)
87+
{
88+
var taskUpdateMessage = DataHelper.GetTaskUpdateTestData(name, "succeeded");
89+
90+
var message = new JsonMessage<TaskUpdateEvent>(
91+
taskUpdateMessage,
7892
"16988a78-87b5-4168-a5c3-2cfc2bab8e54",
7993
Guid.NewGuid().ToString(),
8094
string.Empty);
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/*
2+
* Copyright 2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using BoDi;
18+
using Monai.Deploy.WorkflowManager.IntegrationTests.Support;
19+
using Monai.Deploy.WorkflowManager.WorkflowExecutor.IntegrationTests.Support;
20+
using Polly;
21+
using Polly.Retry;
22+
using TechTalk.SpecFlow.Infrastructure;
23+
24+
namespace Monai.Deploy.WorkflowManager.WorkflowExecutor.IntegrationTests.StepDefinitions
25+
{
26+
[Binding]
27+
internal class WorkflowInstanceStepDefintions
28+
{
29+
private RabbitPublisher WorkflowPublisher { get; set; }
30+
private RabbitConsumer TaskDispatchConsumer { get; set; }
31+
private MongoClientUtil MongoClient { get; set; }
32+
private Assertions Assertions { get; set; }
33+
private DataHelper DataHelper { get; set; }
34+
private readonly ISpecFlowOutputHelper _outputHelper;
35+
public MinioDataSeeding MinioDataSeeding { get; }
36+
private RetryPolicy RetryPolicy { get; set; }
37+
38+
public WorkflowInstanceStepDefintions(ObjectContainer objectContainer, ISpecFlowOutputHelper outputHelper)
39+
{
40+
WorkflowPublisher = objectContainer.Resolve<RabbitPublisher>("WorkflowPublisher");
41+
TaskDispatchConsumer = objectContainer.Resolve<RabbitConsumer>("TaskDispatchConsumer");
42+
MongoClient = objectContainer.Resolve<MongoClientUtil>();
43+
Assertions = new Assertions(objectContainer);
44+
DataHelper = objectContainer.Resolve<DataHelper>();
45+
_outputHelper = outputHelper;
46+
MinioDataSeeding = new MinioDataSeeding(objectContainer.Resolve<MinioClientUtil>(), DataHelper, _outputHelper);
47+
RetryPolicy = Policy.Handle<Exception>().WaitAndRetry(retryCount: 20, sleepDurationProvider: _ => TimeSpan.FromMilliseconds(500));
48+
}
49+
50+
[Given(@"I have a Workflow Instance (.*) with no artifacts")]
51+
public void GivenIHaveAWorkflowInstance(string name)
52+
{
53+
_outputHelper.WriteLine($"Retrieving workflow instance with name={name}");
54+
MongoClient.CreateWorkflowInstanceDocument(DataHelper.GetWorkflowInstanceTestData(name));
55+
_outputHelper.WriteLine("Retrieved workflow instance");
56+
}
57+
58+
[Given(@"I have a Workflow Instance (.*) with artifacts (.*) in minio")]
59+
public async Task GivenIHaveAWorkflowInstanceWithArtifacts(string name, string folderName)
60+
{
61+
var workflowInstance = DataHelper.GetWorkflowInstanceTestData(name);
62+
_outputHelper.WriteLine("Seeding minio with workflow input artifacts");
63+
await MinioDataSeeding.SeedWorkflowInputArtifacts(workflowInstance.PayloadId, folderName);
64+
65+
_outputHelper.WriteLine($"Retrieving workflow instance with name={name}");
66+
MongoClient.CreateWorkflowInstanceDocument(workflowInstance);
67+
_outputHelper.WriteLine("Retrieved workflow instance");
68+
}
69+
70+
[Given(@"I have (.*) Workflow Instances")]
71+
public void GivenIHaveWorkflowInstances(int count)
72+
{
73+
_outputHelper.WriteLine($"Retrieving {count} workflow instances");
74+
foreach (int index in Enumerable.Range(0, count))
75+
{
76+
_outputHelper.WriteLine($"Retrieving workflow instances with index={index}");
77+
MongoClient.CreateWorkflowInstanceDocument(DataHelper.GetWorkflowInstanceTestDataByIndex(index));
78+
_outputHelper.WriteLine("Retrieved workflow instance");
79+
}
80+
}
81+
82+
[Then(@"I can see (.*) Workflow Instances are created")]
83+
[Then(@"I can see (.*) Workflow Instance is created")]
84+
public void ThenICanSeeAWorkflowInstanceIsCreated(int count)
85+
{
86+
_outputHelper.WriteLine($"Retrieving {count} workflow instance/s using the payloadid={DataHelper.WorkflowRequestMessage.PayloadId.ToString()}");
87+
var workflowInstances = DataHelper.GetWorkflowInstances(count, DataHelper.WorkflowRequestMessage.PayloadId.ToString());
88+
_outputHelper.WriteLine($"Retrieved {count} workflow instance/s");
89+
90+
if (workflowInstances != null)
91+
{
92+
foreach (var workflowInstance in workflowInstances)
93+
{
94+
var workflowRevision = DataHelper.WorkflowRevisions.OrderByDescending(x => x.Revision).FirstOrDefault(x => x.WorkflowId.Equals(workflowInstance.WorkflowId));
95+
96+
if (workflowRevision != null)
97+
{
98+
Assertions.AssertWorkflowInstanceMatchesExpectedWorkflow(workflowInstance, workflowRevision, DataHelper.WorkflowRequestMessage);
99+
100+
}
101+
else
102+
{
103+
throw new Exception($"Workflow not found for workflowId {workflowInstance.WorkflowId}");
104+
}
105+
}
106+
}
107+
}
108+
109+
[Then(@"I can see (.*) Workflow Instances are updated")]
110+
[Then(@"I can see (.*) Workflow Instance is updated")]
111+
public void ThenICanSeeAWorkflowInstanceIsUpdated(int count)
112+
{
113+
RetryPolicy.Execute(() =>
114+
{
115+
_outputHelper.WriteLine($"Retrieving {count} workflow instance/s using the payloadid={DataHelper.WorkflowInstances[0].PayloadId}");
116+
DataHelper.SeededWorkflowInstances = DataHelper.WorkflowInstances;
117+
var workflowInstances = DataHelper.GetWorkflowInstances(count, DataHelper.WorkflowInstances[0].PayloadId);
118+
_outputHelper.WriteLine($"Retrieved {count} workflow instance/s");
119+
120+
if (workflowInstances != null)
121+
{
122+
foreach (var workflowInstance in workflowInstances)
123+
{
124+
if (DataHelper.TaskUpdateEvent != null)
125+
{
126+
var workflowInstanceTask = workflowInstance.Tasks.FirstOrDefault(x => x.TaskId.Equals(DataHelper.TaskUpdateEvent.TaskId));
127+
if (workflowInstanceTask != null)
128+
{
129+
workflowInstanceTask.Status.Should().Be(DataHelper.TaskUpdateEvent.Status);
130+
Assertions.AssertOutputArtifactsForTaskUpdate(workflowInstanceTask.OutputArtifacts, DataHelper.TaskUpdateEvent.Outputs);
131+
}
132+
}
133+
}
134+
}
135+
});
136+
}
137+
138+
[Then(@"I can see Workflow Instance is updated with Task Update Information")]
139+
public void ThenICanSeeAWorkflowInstanceIsUpdatedWithTaskUpdateInformation()
140+
{
141+
RetryPolicy.Execute(() =>
142+
{
143+
_outputHelper.WriteLine($"Retrieving workflow instance using workflowInstanceId={DataHelper.TaskUpdateEvent.WorkflowInstanceId}");
144+
var workflowInstance = DataHelper.GetAllWorkflowInstance(DataHelper.TaskUpdateEvent.WorkflowInstanceId);
145+
146+
if (workflowInstance == null)
147+
{
148+
throw new Exception($"Workflow Instance not found using workflowInstanceId={DataHelper.TaskUpdateEvent.WorkflowInstanceId}");
149+
}
150+
151+
_outputHelper.WriteLine($"Retrieved workflow instance");
152+
153+
Assertions.AssertWorkflowInstanceAfterTaskUpdate(workflowInstance, DataHelper.TaskUpdateEvent);
154+
});
155+
}
156+
157+
[Then(@"I can see Workflow Instance is updated with Task Dispatch Information")]
158+
public void ThenICanSeeAWorkflowInstanceIsUpdatedWithTaskDispatchInformation()
159+
{
160+
foreach (var taskDispatch in DataHelper.TaskDispatchEvents)
161+
{
162+
RetryPolicy.Execute(() =>
163+
{
164+
_outputHelper.WriteLine($"Retrieving workflow instance using workflowInstanceId={taskDispatch.WorkflowInstanceId}");
165+
var workflowInstance = DataHelper.GetAllWorkflowInstance(taskDispatch.WorkflowInstanceId);
166+
var workflowRevision = DataHelper.GetWorkflowRevision(workflowInstance.WorkflowId);
167+
168+
if (workflowInstance == null)
169+
{
170+
throw new Exception($"Workflow Instance not found using workflowInstanceId={taskDispatch.WorkflowInstanceId}");
171+
}
172+
173+
_outputHelper.WriteLine($"Retrieved workflow instance");
174+
175+
Assertions.AssertWorkflowInstanceAfterTaskDispatch(workflowInstance, taskDispatch, workflowRevision[0]);
176+
});
177+
}
178+
}
179+
180+
[Then(@"I can see an additional Workflow Instance is not created")]
181+
public void ThenICanSeeAnAdditionalWorkflowInstanceIsNotCreated()
182+
{
183+
_outputHelper.WriteLine($"Retrieving workflow instance with payloadid={DataHelper.WorkflowRequestMessage.PayloadId}");
184+
var workflowInstances = MongoClient.GetWorkflowInstancesByPayloadId(DataHelper.WorkflowRequestMessage.PayloadId.ToString());
185+
_outputHelper.WriteLine("Retrieved workflow instance");
186+
187+
workflowInstances.Count.Should().Be(1);
188+
}
189+
}
190+
}

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/StepDefinitions/WorkflowRequestStepDefinitions.cs

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -70,38 +70,6 @@ public void GivenIHaveClinicalWorkflows(int count)
7070
}
7171
}
7272

73-
[Given(@"I have a Workflow Instance (.*) with no artifacts")]
74-
public void GivenIHaveAWorkflowInstance(string name)
75-
{
76-
_outputHelper.WriteLine($"Retrieving workflow instance with name={name}");
77-
MongoClient.CreateWorkflowInstanceDocument(DataHelper.GetWorkflowInstanceTestData(name));
78-
_outputHelper.WriteLine("Retrieved workflow instance");
79-
}
80-
81-
[Given(@"I have a Workflow Instance (.*) with artifacts (.*) in minio")]
82-
public async Task GivenIHaveAWorkflowInstanceWithArtifacts(string name, string folderName)
83-
{
84-
var workflowInstance = DataHelper.GetWorkflowInstanceTestData(name);
85-
_outputHelper.WriteLine("Seeding minio with workflow input artifacts");
86-
await MinioDataSeeding.SeedWorkflowInputArtifacts(workflowInstance.PayloadId, folderName);
87-
88-
_outputHelper.WriteLine($"Retrieving workflow instance with name={name}");
89-
MongoClient.CreateWorkflowInstanceDocument(workflowInstance);
90-
_outputHelper.WriteLine("Retrieved workflow instance");
91-
}
92-
93-
[Given(@"I have (.*) Workflow Instances")]
94-
public void GivenIHaveWorkflowInstances(int count)
95-
{
96-
_outputHelper.WriteLine($"Retrieving {count} workflow instances");
97-
foreach (int index in Enumerable.Range(0, count))
98-
{
99-
_outputHelper.WriteLine($"Retrieving workflow instances with index={index}");
100-
MongoClient.CreateWorkflowInstanceDocument(DataHelper.GetWorkflowInstanceTestDataByIndex(index));
101-
_outputHelper.WriteLine("Retrieved workflow instance");
102-
}
103-
}
104-
10573
[When(@"I publish a Workflow Request Message (.*) with artifacts (.*) in minio")]
10674
public async Task WhenIPublishAWorkflowRequestMessageWithObjects(string name, string folderName)
10775
{
@@ -134,63 +102,6 @@ public void WhenIPublishAWorkflowRequestMessageWithNoObjects(string name)
134102
_outputHelper.WriteLine($"Event published");
135103
}
136104

137-
[Then(@"I can see (.*) Workflow Instances are created")]
138-
[Then(@"I can see (.*) Workflow Instance is created")]
139-
public void ThenICanSeeAWorkflowInstanceIsCreated(int count)
140-
{
141-
_outputHelper.WriteLine($"Retrieving {count} workflow instance/s using the payloadid={DataHelper.WorkflowRequestMessage.PayloadId.ToString()}");
142-
var workflowInstances = DataHelper.GetWorkflowInstances(count, DataHelper.WorkflowRequestMessage.PayloadId.ToString());
143-
_outputHelper.WriteLine($"Retrieved {count} workflow instance/s");
144-
145-
if (workflowInstances != null)
146-
{
147-
foreach (var workflowInstance in workflowInstances)
148-
{
149-
var workflowRevision = DataHelper.WorkflowRevisions.OrderByDescending(x => x.Revision).FirstOrDefault(x => x.WorkflowId.Equals(workflowInstance.WorkflowId));
150-
151-
if (workflowRevision != null)
152-
{
153-
Assertions.AssertWorkflowInstanceMatchesExpectedWorkflow(workflowInstance, workflowRevision, DataHelper.WorkflowRequestMessage);
154-
155-
}
156-
else
157-
{
158-
throw new Exception($"Workflow not found for workflowId {workflowInstance.WorkflowId}");
159-
}
160-
}
161-
}
162-
}
163-
164-
[Then(@"I can see (.*) Workflow Instances are updated")]
165-
[Then(@"I can see (.*) Workflow Instance is updated")]
166-
public void ThenICanSeeAWorkflowInstanceIsUpdated(int count)
167-
{
168-
RetryPolicy.Execute(() =>
169-
{
170-
_outputHelper.WriteLine($"Retrieving {count} workflow instance/s using the payloadid={DataHelper.WorkflowInstances[0].PayloadId}");
171-
DataHelper.SeededWorkflowInstances = DataHelper.WorkflowInstances;
172-
var workflowInstances = DataHelper.GetWorkflowInstances(count, DataHelper.WorkflowInstances[0].PayloadId);
173-
_outputHelper.WriteLine($"Retrieved {count} workflow instance/s");
174-
175-
if (workflowInstances != null)
176-
{
177-
foreach (var workflowInstance in workflowInstances)
178-
{
179-
var taskUpdate = DataHelper.TaskUpdateEvent;
180-
if (taskUpdate != null)
181-
{
182-
var workflowInstanceTask = workflowInstance.Tasks.FirstOrDefault(x => x.TaskId.Equals(taskUpdate.TaskId));
183-
if (workflowInstanceTask != null)
184-
{
185-
workflowInstanceTask.Status.Should().Be(taskUpdate.Status);
186-
Assertions.AssertOutputArtifactsForTaskUpdate(workflowInstanceTask.OutputArtifacts, DataHelper.TaskUpdateEvent.Outputs);
187-
}
188-
}
189-
}
190-
}
191-
});
192-
}
193-
194105
[Then(@"(.*) Task Dispatch event is published")]
195106
[Then(@"(.*) Task Dispatch events are published")]
196107
public void TaskDispatchEventIsPublished(int count)
@@ -209,25 +120,14 @@ public void TaskDispatchEventIsPublished(int count)
209120

210121
if (string.IsNullOrEmpty(DataHelper.TaskUpdateEvent.ExecutionId))
211122
{
212-
Assertions.AssertTaskDispatchEvent(taskDispatchEvent, workflowInstance, workflowRevision, DataHelper.WorkflowRequestMessage);
123+
Assertions.AssertTaskDispatchEvent(taskDispatchEvent, workflowInstance, workflowRevision, DataHelper.WorkflowRequestMessage, null);
213124
}
214125
else
215126
{
216127
Assertions.AssertTaskDispatchEvent(taskDispatchEvent, workflowInstance, workflowRevision, null, DataHelper.TaskUpdateEvent);
217128
}
218129
}
219130
});
220-
221-
}
222-
223-
[Then(@"I can see an additional Workflow Instance is not created")]
224-
public void ThenICanSeeAnAdditionalWorkflowInstanceIsNotCreated()
225-
{
226-
_outputHelper.WriteLine($"Retrieving workflow instance with payloadid={DataHelper.WorkflowRequestMessage.PayloadId}");
227-
var workflowInstances = MongoClient.GetWorkflowInstancesByPayloadId(DataHelper.WorkflowRequestMessage.PayloadId.ToString());
228-
_outputHelper.WriteLine("Retrieved workflow instance");
229-
230-
workflowInstances.Count.Should().Be(1);
231131
}
232132

233133
[Then(@"A Task Dispatch event is not published")]

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/StepDefinitions/WorkflowTaskArtifactStepDefinitions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void ThenInputArtifactsAreMapped()
7373
{
7474
var workflowTask = workflowRevision.Workflow.Tasks.First(x => x.Id.Equals(task.TaskId));
7575

76-
Assertions.AssertInputArtifacts(workflowTask, PayloadId, task);
76+
Assertions.AssertInputArtifactsForWorkflowInstance(workflowTask, PayloadId, task);
7777
}
7878
}
7979
}

0 commit comments

Comments
 (0)