From 21d0a82b43acd647c3d20709b13efc328e7b7afe Mon Sep 17 00:00:00 2001 From: dbuechel Date: Fri, 29 Mar 2019 16:02:05 +0100 Subject: [PATCH] SEBWIN-226: Simplified timeouts for client operation. --- .../Operations/ClientOperationTests.cs | 4 ++-- .../ClientTerminationOperationTests.cs | 2 +- SafeExamBrowser.Runtime/CompositionRoot.cs | 5 ++--- .../Operations/ClientOperation.cs | 21 ++++++++----------- .../Operations/ClientTerminationOperation.cs | 3 +-- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/SafeExamBrowser.Runtime.UnitTests/Operations/ClientOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Operations/ClientOperationTests.cs index 1ce09006..6dd03762 100644 --- a/SafeExamBrowser.Runtime.UnitTests/Operations/ClientOperationTests.cs +++ b/SafeExamBrowser.Runtime.UnitTests/Operations/ClientOperationTests.cs @@ -65,7 +65,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations sessionContext.Next = session.Object; proxyFactory.Setup(f => f.CreateClientProxy(It.IsAny())).Returns(proxy.Object); - sut = new ClientOperation(logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, sessionContext, 0, 0); + sut = new ClientOperation(logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, sessionContext, 0); } [TestMethod] @@ -112,7 +112,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations var terminateClient = new Action(() => Task.Delay(100).ContinueWith(_ => process.Raise(p => p.Terminated += null, 0))); processFactory.Setup(f => f.StartNew(It.IsAny(), It.IsAny())).Returns(process.Object).Callback(terminateClient); - sut = new ClientOperation(logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, sessionContext, ONE_SECOND, ONE_SECOND); + sut = new ClientOperation(logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, sessionContext, ONE_SECOND); before = DateTime.Now; result = sut.Perform(); diff --git a/SafeExamBrowser.Runtime.UnitTests/Operations/ClientTerminationOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Operations/ClientTerminationOperationTests.cs index b1ac3b4e..8a5a8248 100644 --- a/SafeExamBrowser.Runtime.UnitTests/Operations/ClientTerminationOperationTests.cs +++ b/SafeExamBrowser.Runtime.UnitTests/Operations/ClientTerminationOperationTests.cs @@ -62,7 +62,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations sessionContext.Next = session.Object; proxyFactory.Setup(f => f.CreateClientProxy(It.IsAny())).Returns(proxy.Object); - sut = new ClientTerminationOperation(logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, sessionContext, 0, 0); + sut = new ClientTerminationOperation(logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, sessionContext, 0); } [TestMethod] diff --git a/SafeExamBrowser.Runtime/CompositionRoot.cs b/SafeExamBrowser.Runtime/CompositionRoot.cs index dbff15a3..1ad224df 100644 --- a/SafeExamBrowser.Runtime/CompositionRoot.cs +++ b/SafeExamBrowser.Runtime/CompositionRoot.cs @@ -49,7 +49,6 @@ namespace SafeExamBrowser.Runtime internal void BuildObjectGraph(Action shutdown) { const int FIVE_SECONDS = 5000; - const int FIFTEEN_SECONDS = 15000; const int THIRTY_SECONDS = 30000; var args = Environment.GetCommandLineArgs(); @@ -80,11 +79,11 @@ namespace SafeExamBrowser.Runtime sessionOperations.Enqueue(new SessionInitializationOperation(configuration, logger, runtimeHost, sessionContext)); sessionOperations.Enqueue(new ConfigurationOperation(args, configuration, new HashAlgorithm(), logger, sessionContext)); - sessionOperations.Enqueue(new ClientTerminationOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, THIRTY_SECONDS, FIFTEEN_SECONDS)); + sessionOperations.Enqueue(new ClientTerminationOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, THIRTY_SECONDS)); sessionOperations.Enqueue(new KioskModeTerminationOperation(desktopFactory, explorerShell, logger, processFactory, sessionContext)); sessionOperations.Enqueue(new ServiceOperation(logger, serviceProxy, sessionContext)); sessionOperations.Enqueue(new KioskModeOperation(desktopFactory, explorerShell, logger, processFactory, sessionContext)); - sessionOperations.Enqueue(new ClientOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, THIRTY_SECONDS, FIFTEEN_SECONDS)); + sessionOperations.Enqueue(new ClientOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, THIRTY_SECONDS)); sessionOperations.Enqueue(new SessionActivationOperation(logger, sessionContext)); var bootstrapSequence = new OperationSequence(logger, bootstrapOperations); diff --git a/SafeExamBrowser.Runtime/Operations/ClientOperation.cs b/SafeExamBrowser.Runtime/Operations/ClientOperation.cs index 2cae4ca9..7e1663e6 100644 --- a/SafeExamBrowser.Runtime/Operations/ClientOperation.cs +++ b/SafeExamBrowser.Runtime/Operations/ClientOperation.cs @@ -21,8 +21,7 @@ namespace SafeExamBrowser.Runtime.Operations { internal class ClientOperation : SessionOperation { - private readonly int startup_timeout_ms; - private readonly int shutdown_timeout_ms; + private int timeout_ms; private ILogger logger; private IProcessFactory processFactory; private IProxyFactory proxyFactory; @@ -49,15 +48,13 @@ namespace SafeExamBrowser.Runtime.Operations IProxyFactory proxyFactory, IRuntimeHost runtimeHost, SessionContext sessionContext, - int startup_timeout_ms, - int shutdown_timeout_ms) : base(sessionContext) + int timeout_ms) : base(sessionContext) { this.logger = logger; this.processFactory = processFactory; this.proxyFactory = proxyFactory; this.runtimeHost = runtimeHost; - this.startup_timeout_ms = startup_timeout_ms; - this.shutdown_timeout_ms = shutdown_timeout_ms; + this.timeout_ms = timeout_ms; } public override OperationResult Perform() @@ -119,7 +116,7 @@ namespace SafeExamBrowser.Runtime.Operations ClientProcess.Terminated += clientTerminatedEventHandler; logger.Info("Waiting for client to complete initialization..."); - clientReady = clientReadyEvent.WaitOne(startup_timeout_ms); + clientReady = clientReadyEvent.WaitOne(timeout_ms); runtimeHost.AllowConnection = false; runtimeHost.ClientReady -= clientReadyEventHandler; @@ -132,7 +129,7 @@ namespace SafeExamBrowser.Runtime.Operations if (!clientReady) { - logger.Error($"Failed to start client within {startup_timeout_ms / 1000} seconds!"); + logger.Error($"Failed to start client within {timeout_ms / 1000} seconds!"); } if (clientTerminated) @@ -200,19 +197,19 @@ namespace SafeExamBrowser.Runtime.Operations ClientProxy.Disconnect(); logger.Info("Waiting for client to disconnect from runtime communication host..."); - disconnected = disconnectedEvent.WaitOne(shutdown_timeout_ms); + disconnected = disconnectedEvent.WaitOne(timeout_ms / 2); if (!disconnected) { - logger.Error($"Client failed to disconnect within {shutdown_timeout_ms / 1000} seconds!"); + logger.Error($"Client failed to disconnect within {timeout_ms / 2 / 1000} seconds!"); } logger.Info("Waiting for client process to terminate..."); - terminated = terminatedEvent.WaitOne(shutdown_timeout_ms); + terminated = terminatedEvent.WaitOne(timeout_ms / 2); if (!terminated) { - logger.Error($"Client failed to terminate within {shutdown_timeout_ms / 1000} seconds!"); + logger.Error($"Client failed to terminate within {timeout_ms / 2 / 1000} seconds!"); } runtimeHost.ClientDisconnected -= disconnectedEventHandler; diff --git a/SafeExamBrowser.Runtime/Operations/ClientTerminationOperation.cs b/SafeExamBrowser.Runtime/Operations/ClientTerminationOperation.cs index bb3e7e3f..c8f13b16 100644 --- a/SafeExamBrowser.Runtime/Operations/ClientTerminationOperation.cs +++ b/SafeExamBrowser.Runtime/Operations/ClientTerminationOperation.cs @@ -22,8 +22,7 @@ namespace SafeExamBrowser.Runtime.Operations IProxyFactory proxyFactory, IRuntimeHost runtimeHost, SessionContext sessionContext, - int startup_timeout_ms, - int shutdown_timeout_ms) : base(logger, processFactory, proxyFactory, runtimeHost, sessionContext, startup_timeout_ms, shutdown_timeout_ms) + int timeout_ms) : base(logger, processFactory, proxyFactory, runtimeHost, sessionContext, timeout_ms) { }