Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/multi-data-model…
Browse files Browse the repository at this point in the history
…-with-validation
  • Loading branch information
ivarne committed Sep 9, 2024
2 parents 225f934 + 0142da4 commit e7f3413
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ public async Task Execute(IProcessTask processTask, string taskId, Instance inst
throw;
}

await _eformidlingServiceTask.Execute(taskId, instance);
try
{
await _eformidlingServiceTask.Execute(taskId, instance);
}
catch (Exception e)
{
_logger.LogError(e, "Error executing eFormidling service task. Unlocking data again.");
await _processTaskDataLocker.Unlock(taskId, instance);
throw;
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,33 @@ public async Task Calls_unlock_if_pdf_fails()
_eformidlingServiceTask.Verify(p => p.Execute(taskId, instance), Times.Never);
}

[Fact]
public async Task Calls_unlock_if_eFormidling_fails()
{
EndTaskEventHandler eteh =
new(_processTaskDataLocker.Object, _processTaskFinisher.Object, ServiceTasks, _processTaskEnds, _logger);

var instance = new Instance() { Id = "1337/fa0678ad-960d-4307-aba2-ba29c9804c9d", AppId = "ttd/test", };

var taskId = "Task_1";
Mock<IProcessTask> mockProcessTask = new();

// Make PDF service task throw exception to simulate a failure situation.
_eformidlingServiceTask.Setup(x => x.Execute(It.IsAny<string>(), instance)).ThrowsAsync(new Exception());

// Expect exception to be thrown
await Assert.ThrowsAsync<Exception>(async () => await eteh.Execute(mockProcessTask.Object, taskId, instance));

// Assert normal flow until the exception is thrown
_processTaskDataLocker.Verify(p => p.Lock(taskId, instance));
_processTaskFinisher.Verify(p => p.Finalize(taskId, instance));
mockProcessTask.Verify(p => p.End(taskId, instance));
_pdfServiceTask.Verify(p => p.Execute(taskId, instance));

// Make sure unlock data is called
_processTaskDataLocker.Verify(p => p.Unlock(taskId, instance));
}

[Fact]
public void Throws_If_Missing_Pdf_ServiceTask()
{
Expand Down

0 comments on commit e7f3413

Please sign in to comment.