Skip to content

Fix sending of workflow completed event #1201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/WorkflowCore/Services/WorkflowExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private async Task DetermineNextExecutionTime(WorkflowInstance workflow, Workflo

if (workflow.Status == WorkflowStatus.Complete)
{
PublishWorkflowCompleted(workflow);
return;
}

Expand Down Expand Up @@ -265,6 +266,11 @@ private async Task DetermineNextExecutionTime(WorkflowInstance workflow, Workflo
await middlewareRunner.RunPostMiddleware(workflow, def);
}

PublishWorkflowCompleted(workflow);
}

private void PublishWorkflowCompleted(WorkflowInstance workflow)
{
_publisher.PublishNotification(new WorkflowCompleted
{
EventTimeUtc = _datetimeProvider.UtcNow,
Expand Down
34 changes: 34 additions & 0 deletions test/WorkflowCore.UnitTests/Services/WorkflowExecutorFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using FluentAssertions;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using WorkflowCore.Models.LifeCycleEvents;
using WorkflowCore.Services;
using Xunit;

Expand Down Expand Up @@ -403,6 +404,39 @@ public void should_process_cancellations()
A.CallTo(() => CancellationProcessor.ProcessCancellations(instance, A<WorkflowDefinition>.Ignored, A<WorkflowExecutorResult>.Ignored)).MustHaveHappened();
}

[Fact(DisplayName = "Should send notification when workflow completes")]
public void should_send_notification_when_workflow_completes()
{
//arrange
var param = A.Fake<IStepParameter>();

// build a fake EndStep
WorkflowStep step1 = A.Fake<WorkflowStep>();
A.CallTo(() => step1.InitForExecution(A<WorkflowExecutorResult>.Ignored, A<WorkflowDefinition>.Ignored,
A<WorkflowInstance>.Ignored, A<ExecutionPointer>.Ignored))
.Returns(ExecutionPipelineDirective.EndWorkflow);

Given1StepWorkflow(step1, "Workflow", 1);

var instance = new WorkflowInstance
{
WorkflowDefinitionId = "Workflow",
Version = 1,
Status = WorkflowStatus.Runnable,
NextExecution = 0,
Id = "001",
ExecutionPointers = new ExecutionPointerCollection(new List<ExecutionPointer>
{
new ExecutionPointer { Id = "1", Active = true, StepId = 0 }
})
};

//act
Subject.Execute(instance);

//assert
A.CallTo(() => EventHub.PublishNotification(A<WorkflowCompleted>.Ignored)).MustHaveHappenedOnceExactly();
}

private void Given1StepWorkflow(WorkflowStep step1, string id, int version)
{
Expand Down