SEBWIN-226: Simplified timeouts for client operation.

This commit is contained in:
dbuechel 2019-03-29 16:02:05 +01:00
parent 06497258fd
commit 21d0a82b43
5 changed files with 15 additions and 20 deletions

View file

@ -65,7 +65,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
sessionContext.Next = session.Object;
proxyFactory.Setup(f => f.CreateClientProxy(It.IsAny<string>())).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<string>(), It.IsAny<string[]>())).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();

View file

@ -62,7 +62,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
sessionContext.Next = session.Object;
proxyFactory.Setup(f => f.CreateClientProxy(It.IsAny<string>())).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]

View file

@ -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);

View file

@ -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;

View file

@ -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)
{
}