public string[] EvaluateRunspacesToRemove(IRunspacesStatsMonitor.RunspaceType runspaceType) { IRunspaceStats[] runspacesToEvaluate = new IRunspaceStats[] {}; lock (this) { runspacesToEvaluate = _runspaceStats.ToArray(); } List <string> result = new List <string>(); foreach (var runspaceStats in runspacesToEvaluate) { runspaceStats.Refresh(); if (_retentionPolicy.ShouldRemove(runspaceStats)) { if (runspaceStats.IsWebConsole && runspaceType == IRunspacesStatsMonitor.RunspaceType.WebConsole) { result.Add(runspaceStats.RunspaceId); } if (!runspaceStats.IsWebConsole && runspaceType == IRunspacesStatsMonitor.RunspaceType.Runspace) { result.Add(runspaceStats.RunspaceId); } } } return(result.ToArray()); }
public void PolicyKeepsWhenAllRulesKeep() { // Arrange var rule1Mock = new Mock <IRunspaceRetentionRule>(); rule1Mock.Setup(r => r.ShouldRemove(It.IsAny <IRunspaceStats>())).Returns(false); var rule2Mock = new Mock <IRunspaceRetentionRule>(); rule2Mock.Setup(r => r.ShouldRemove(It.IsAny <IRunspaceStats>())).Returns(false); var policy = new RunspaceRetentionPolicy(new[] { rule1Mock.Object, rule2Mock.Object }); // Act var actual = policy.ShouldRemove(null); // Assert Assert.IsFalse(actual); }
public string[] EvaluateRunspacesToRemove() { IRunspaceStats[] runspacesToEvaluate = new IRunspaceStats[] {}; lock (this) { runspacesToEvaluate = _runspaceStats.ToArray(); } List <string> result = new List <string>(); foreach (var runspaceStats in runspacesToEvaluate) { runspaceStats.Refresh(); if (_retentionPolicy.ShouldRemove(runspaceStats)) { result.Add(runspaceStats.RunspaceId); } } return(result.ToArray()); }