public void CloseOrEnqueueForClosingAddsSessionIfSessionCannotBeClosed() { // given mockSession.TryEnd().Returns(false); var target = CreateContext(); ISessionWatchdogContext targetExplicit = target; // when targetExplicit.CloseOrEnqueueForClosing(mockSession, 17); // then Assert.That(target.GetSessionsToClose().Count, Is.EqualTo(1)); }
public void CloseOrEnqueueForClosingDoesNotAddSessionIfItCanBeClosed() { // given mockSession.TryEnd().Returns(true); var target = CreateContext(); ISessionWatchdogContext targetExplicit = target; // when targetExplicit.CloseOrEnqueueForClosing(mockSession, 0); // then Assert.That(target.GetSessionsToClose().Count, Is.EqualTo(0)); mockSession.Received(1).TryEnd(); }
public void DequeueFromClosingRemovesSession() { // given var target = CreateContext(); ISessionWatchdogContext targetExplicit = target; targetExplicit.CloseOrEnqueueForClosing(mockSession, 0); Assert.That(target.GetSessionsToClose().Count, Is.EqualTo(1)); // when targetExplicit.DequeueFromClosing(mockSession); // then Assert.That(target.GetSessionsToClose().Count, Is.EqualTo(0)); }
public void CloseOrEnqueueForClosingSetsSplitByEventsGracePeriodEndTimeIfSessionCannotBeClosed() { // given const long timestamp = 10; const int gracePeriod = 5; mockTimingProvider.ProvideTimestampInMilliseconds().Returns(timestamp); mockSession.TryEnd().Returns(false); var target = CreateContext(); ISessionWatchdogContext targetExplicit = target; // when targetExplicit.CloseOrEnqueueForClosing(mockSession, gracePeriod); // then mockSession.Received(1).SplitByEventsGracePeriodEndTimeInMillis = (timestamp + gracePeriod); }
public void ExecuteEndsSessionsWithGraceEndTimeSameAsCurrentTime() { // given mockTimingProvider.ProvideTimestampInMilliseconds().Returns(5L); mockSession.TryEnd().Returns(false); var target = CreateContext(); ISessionWatchdogContext targetExplicit = target; targetExplicit.CloseOrEnqueueForClosing(mockSession, 0); // when target.Execute(); // then mockSession.Received(1).End(false); Assert.That(target.GetSessionsToClose().Count, Is.EqualTo(0)); }
public void ExecuteDoesNotEndSessionsWhenGracePeriodIsNotExpired() { // given const int gracePeriod = 1; const int now = 5; mockTimingProvider.ProvideTimestampInMilliseconds().Returns(now); mockSession.TryEnd().Returns(false); var target = CreateContext(); ISessionWatchdogContext targetExplicit = target; targetExplicit.CloseOrEnqueueForClosing(mockSession, gracePeriod); // close at now + gracePeriod // when target.Execute(); // then mockSession.Received(0).End(); mockSession.Received(1).SplitByEventsGracePeriodEndTimeInMillis = (now + gracePeriod); Assert.That(target.GetSessionsToClose().Count, Is.EqualTo(1)); }
public void ExecuteSleepsMinimumDurationToNextGracePeriodEnd() { // given const int gracePeriod = 100; const int nextSessionProxySplitTime = 200; const int currentTime = 50; mockSessionProxy.SplitSessionByTime().Returns(nextSessionProxySplitTime); mockTimingProvider.ProvideTimestampInMilliseconds().Returns(currentTime); var target = CreateContext(); ISessionWatchdogContext targetExplicit = target; targetExplicit.CloseOrEnqueueForClosing(mockSession, gracePeriod); targetExplicit.AddToSplitByTimeout(mockSessionProxy); // when target.Execute(); // then mockSessionProxy.Received(1).SplitSessionByTime(); mockSession.Received(0).End(); mockThreadSuspender.Received(1).Sleep(gracePeriod); }
void ISessionWatchdog.CloseOrEnqueueForClosing(ISessionInternals session, int closeGracePeriodInMillis) { context.CloseOrEnqueueForClosing(session, closeGracePeriodInMillis); }