public async Task ProcessThresholdsExceeded_InProc_ReturnsExpectedResult(ThrottleState throttleState, bool expected) { var status = new ConcurrencyThrottleAggregateStatus { State = throttleState }; if (throttleState == ThrottleState.Enabled) { status.EnabledThrottles = new List <string> { "CPU", "Memory" }.AsReadOnly(); } var mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict); mockConcurrencyThrottleManager.Setup(p => p.GetStatus()).Returns(status); var mockScriptHostManager = new Mock <IScriptHostManager>(MockBehavior.Strict); var scriptHostManagerServiceProviderMock = mockScriptHostManager.As <IServiceProvider>(); scriptHostManagerServiceProviderMock.Setup(p => p.GetService(typeof(IFunctionInvocationDispatcherFactory))).Returns(null); scriptHostManagerServiceProviderMock.Setup(p => p.GetService(typeof(IConcurrencyThrottleManager))).Returns(mockConcurrencyThrottleManager.Object); _serviceProviderMock.Setup(p => p.GetService(typeof(IScriptHostManager))).Returns(mockScriptHostManager.Object); Collection <string> exceededCounters = new Collection <string>(); bool result = await _performanceManager.ProcessThresholdsExceeded(_logger); Assert.Equal(expected, result); }
public async Task ProcessThresholdsExceeded_OutOfProc_ReturnsExpectedResult(ThrottleState throttleState, bool expected) { var status = new ConcurrencyThrottleAggregateStatus { State = throttleState }; if (throttleState == ThrottleState.Enabled) { status.EnabledThrottles = new List <string> { "CPU", "Memory" }.AsReadOnly(); } var mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict); mockConcurrencyThrottleManager.Setup(p => p.GetStatus()).Returns(status); var workerStatuses = new Dictionary <string, WorkerStatus>(); for (int i = 0; i < 3; i++) { var workerStatus = new WorkerStatus { Latency = TimeSpan.FromMilliseconds(25) }; workerStatuses.Add(Guid.NewGuid().ToString(), workerStatus); } var mockDispatcher = new Mock <IFunctionInvocationDispatcher>(MockBehavior.Strict); mockDispatcher.SetupGet(p => p.State).Returns(FunctionInvocationDispatcherState.Initialized); mockDispatcher.Setup(p => p.GetWorkerStatusesAsync()).ReturnsAsync(workerStatuses); var mockDispatcherFactory = new Mock <IFunctionInvocationDispatcherFactory>(MockBehavior.Strict); mockDispatcherFactory.Setup(p => p.GetFunctionDispatcher()).Returns(mockDispatcher.Object); var mockScriptHostManager = new Mock <IScriptHostManager>(MockBehavior.Strict); var scriptHostManagerServiceProviderMock = mockScriptHostManager.As <IServiceProvider>(); scriptHostManagerServiceProviderMock.Setup(p => p.GetService(typeof(IFunctionInvocationDispatcherFactory))).Returns(mockDispatcherFactory.Object); scriptHostManagerServiceProviderMock.Setup(p => p.GetService(typeof(IConcurrencyThrottleManager))).Returns(mockConcurrencyThrottleManager.Object); _serviceProviderMock.Setup(p => p.GetService(typeof(IScriptHostManager))).Returns(mockScriptHostManager.Object); Collection <string> exceededCounters = new Collection <string>(); bool result = await _performanceManager.ProcessThresholdsExceeded(_logger); Assert.Equal(expected, result); mockDispatcher.VerifyAll(); }
public override void OnFixedUpdate() { /* update targetAPtime */ double dV = mainBody.CircVelocityAtRadius(orbit.ApR) - orbit.SwappedVelocityAtApoapsis().magnitude; targetAPtime = BurnTime(dV / 2); ThrottleState lastThrottleState = throttleState; AttitudeState lastAttitudeState = attitudeState; throttleState = throttleMapping[throttleState](); if (throttleState != lastThrottleState) { throttleMapping[throttleState](); } attitudeState = attitudeMapping[attitudeState](); if (attitudeState != lastAttitudeState) { attitudeMapping[attitudeState](); } }
protected override void OnEnable() { throttleState = ThrottleState.LAUNCH; attitudeState = AttitudeState.LAUNCH; done = false; }