SEBWIN-596: Ensured open server connection gets closed when session start failed.

This commit is contained in:
Damian Büchel 2022-08-24 10:25:41 +02:00
parent 2d34ed30eb
commit cb3cee7e4e
2 changed files with 17 additions and 2 deletions

View file

@ -591,7 +591,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
}
[TestMethod]
public void Revert_MustDisconnectFromServer()
public void Revert_MustDisconnectFromServerWhenSessionRunning()
{
context.Current.Settings.SessionMode = SessionMode.Server;
server.Setup(s => s.Disconnect()).Returns(new ServerResponse(true));
@ -604,6 +604,21 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
Assert.AreEqual(OperationResult.Success, result);
}
[TestMethod]
public void Revert_MustDisconnectFromServerWhenSessionStartFailed()
{
context.Current = default;
context.Next.Settings.SessionMode = SessionMode.Server;
server.Setup(s => s.Disconnect()).Returns(new ServerResponse(true));
var result = sut.Revert();
fileSystem.VerifyNoOtherCalls();
server.Verify(s => s.Disconnect(), Times.Once);
Assert.AreEqual(OperationResult.Success, result);
}
[TestMethod]
public void Revert_MustFailWhenDisconnectionUnsuccesful()
{

View file

@ -122,7 +122,7 @@ namespace SafeExamBrowser.Runtime.Operations
{
var result = OperationResult.Success;
if (Context.Current?.Settings.SessionMode == SessionMode.Server)
if (Context.Current?.Settings.SessionMode == SessionMode.Server || Context.Next.Settings.SessionMode == SessionMode.Server)
{
logger.Info("Finalizing server...");
StatusChanged?.Invoke(TextKey.OperationStatus_FinalizeServer);