def test_upper_limit_is_not_exceeded(self): (min, max) = (1, 30) worker_pool = self.mock.worker_pool() strategy = self.mock.auto_scaling_strategy(adjust_return=max+1) auto_scaler = AutoScaler(self.mock.simulation.environment, 10, (min, max), strategy) auto_scaler.auto_scale() worker_pool.set_capacity.assert_called_once_with(max)
def test_lower_limit_is_not_exceeded(self): (min, max) = (1, 30) service = self.mock.service() strategy = self.mock.auto_scaling_strategy(adjust_return=min - 1) auto_scaler = AutoScaler(self.mock.simulation.environment, 10, (min, max), strategy) auto_scaler.auto_scale() service.set_worker_count.assert_called_once_with(min)
def test_triggers_periodically(self): (duration, period) = (20, 10) self.mock.service() strategy = self.mock.auto_scaling_strategy(adjust_return=10) AutoScaler(self.mock.simulation.environment, 10, (1, 3), strategy) self.mock.simulation.run_until(20) self.assertEqual(duration / period, strategy.adjust.call_count)
def create_autoscaler(self, environment, autoscaling): strategy = RuleBasedStrategy(70, 80) return AutoScaler(environment, autoscaling.period, autoscaling.limits, strategy)