SEBWIN-183: Changed startup- and shutdown-controller to continue reverting operations, even if one or more of them fail.

This commit is contained in:
dbuechel 2017-10-09 12:11:33 +02:00
parent 451aef8cae
commit 93e84b1120
6 changed files with 73 additions and 6 deletions

View file

@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@ -84,6 +85,29 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour
Assert.IsTrue(c == 3);
}
[TestMethod]
public void MustContinueToRevertOperationsInCaseOfError()
{
var operationA = new Mock<IOperation>();
var operationB = new Mock<IOperation>();
var operationC = new Mock<IOperation>();
var operations = new Queue<IOperation>();
operationA.Setup(o => o.Revert()).Throws<Exception>();
operationB.Setup(o => o.Revert()).Throws<Exception>();
operationC.Setup(o => o.Revert()).Throws<Exception>();
operations.Enqueue(operationA.Object);
operations.Enqueue(operationB.Object);
operations.Enqueue(operationC.Object);
sut.FinalizeApplication(operations);
operationA.Verify(o => o.Revert(), Times.Once);
operationB.Verify(o => o.Revert(), Times.Once);
operationC.Verify(o => o.Revert(), Times.Once);
}
[TestMethod]
public void MustNotFailWithEmptyQueue()
{

View file

@ -149,6 +149,33 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour
Assert.IsTrue(a == 3);
}
[TestMethod]
public void MustContinueToRevertOperationsInCaseOfError()
{
var operationA = new Mock<IOperation>();
var operationB = new Mock<IOperation>();
var operationC = new Mock<IOperation>();
var operations = new Queue<IOperation>();
operationC.Setup(o => o.Perform()).Throws<Exception>();
operationC.Setup(o => o.Revert()).Throws<Exception>();
operationB.Setup(o => o.Revert()).Throws<Exception>();
operationA.Setup(o => o.Revert()).Throws<Exception>();
operations.Enqueue(operationA.Object);
operations.Enqueue(operationB.Object);
operations.Enqueue(operationC.Object);
var result = sut.TryInitializeApplication(operations);
operationA.Verify(o => o.Perform(), Times.Once);
operationA.Verify(o => o.Revert(), Times.Once);
operationB.Verify(o => o.Perform(), Times.Once);
operationB.Verify(o => o.Revert(), Times.Once);
operationC.Verify(o => o.Perform(), Times.Once);
operationC.Verify(o => o.Revert(), Times.Once);
}
[TestMethod]
public void MustSucceedWithEmptyQueue()
{

View file

@ -52,7 +52,15 @@ namespace SafeExamBrowser.Core.Behaviour
foreach (var operation in operations)
{
operation.SplashScreen = splashScreen;
operation.Revert();
try
{
operation.Revert();
}
catch (Exception e)
{
logger.Error($"Failed to revert operation '{operation.GetType().Name}'!", e);
}
}
}

View file

@ -77,7 +77,15 @@ namespace SafeExamBrowser.Core.Behaviour
{
var operation = stack.Pop();
operation.Revert();
try
{
operation.Revert();
}
catch (Exception e)
{
logger.Error($"Failed to revert operation '{operation.GetType().Name}'!", e);
}
splashScreen.Regress();
}
}

View file

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.8
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser", "SafeExamBrowser\SafeExamBrowser.csproj", "{E3AED2F8-B5DF-45D1-AC19-48066923D6D8}"
EndProject
@ -10,7 +10,6 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0A9E6674-2FB4-42EA-85DE-B2445B9AE2D9}"
ProjectSection(SolutionItems) = preProject
LICENSE.txt = LICENSE.txt
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.UserInterface.Windows10", "SafeExamBrowser.UserInterface.Windows10\SafeExamBrowser.UserInterface.Windows10.csproj", "{E1BE031A-4354-41E7-83E8-843DED4489FF}"

View file

@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Windows;
@ -65,7 +66,7 @@ namespace SafeExamBrowser
if (success)
{
MainWindow = instances.Taskbar;
MainWindow.Closing += (o, args) => ShutdownApplication();
MainWindow.Closing += MainWindow_Closing;
MainWindow.Show();
}
else
@ -74,7 +75,7 @@ namespace SafeExamBrowser
}
}
private void ShutdownApplication()
private void MainWindow_Closing(object sender, CancelEventArgs e)
{
var operations = new Queue<IOperation>(instances.StartupOperations.Reverse());