internal static ScaleVote GetAggregateScaleVote(List <ScaleVote> votes, ScaleStatusContext context, ILogger logger) { ScaleVote vote = ScaleVote.None; if (votes.Any()) { // aggregate all the votes into a single vote if (votes.Any(p => p == ScaleVote.ScaleOut)) { // scale out if at least 1 monitor requires it logger.LogDebug("Scaling out based on votes"); vote = ScaleVote.ScaleOut; } else if (context.WorkerCount > 0 && votes.All(p => p == ScaleVote.ScaleIn)) { // scale in only if all monitors vote scale in logger.LogDebug("Scaling in based on votes"); vote = ScaleVote.ScaleIn; } } else if (context.WorkerCount > 0) { // if no functions exist or are enabled we'll scale in logger.LogDebug("No enabled functions or scale votes so scaling in"); vote = ScaleVote.ScaleIn; } return(vote); }
public async Task GetScaleStatus_NoMonitors_ReturnsExpectedStatus(int workerCount, ScaleVote expected) { var context = new ScaleStatusContext { WorkerCount = workerCount }; var status = await _scaleManager.GetScaleStatusAsync(context); Assert.Equal(expected, status.Vote); }
public void GetAggregateScaleVote_ReturnsExpectedResult(int workerCount, int numScaleOutVotes, int numScaleInVotes, ScaleVote expected) { var context = new ScaleStatusContext { WorkerCount = workerCount }; List <ScaleVote> votes = new List <ScaleVote>(); for (int i = 0; i < numScaleOutVotes; i++) { votes.Add(ScaleVote.ScaleOut); } for (int i = 0; i < numScaleInVotes; i++) { votes.Add(ScaleVote.ScaleIn); } var vote = FunctionsScaleManager.GetAggregateScaleVote(votes, context, _testLogger); Assert.Equal(expected, vote); }