@@ -218,6 +218,26 @@ describe('step scaling policy', () => {
218218
219219 } ) ;
220220
221+ test ( 'step scaling with invalid evaluation period throws error' , ( ) => {
222+ // GIVEN
223+ const stack = new cdk . Stack ( ) ;
224+ const target = createScalableTarget ( stack ) ;
225+
226+ // THEN
227+ expect ( ( ) => {
228+ target . scaleOnMetric ( 'Tracking' , {
229+ metric : new cloudwatch . Metric ( { namespace : 'Test' , metricName : 'Metric' , statistic : 'p99' } ) ,
230+ scalingSteps : [
231+ { upper : 0 , change : - 1 } ,
232+ { lower : 100 , change : + 1 } ,
233+ { lower : 500 , change : + 5 } ,
234+ ] ,
235+ evaluationPeriods : 0 ,
236+ metricAggregationType : appscaling . MetricAggregationType . MAXIMUM ,
237+ } ) ;
238+ } ) . toThrow ( / e v a l u a t i o n P e r i o d s c a n n o t b e l e s s t h a n 1 , g o t : 0 / ) ;
239+ } ) ;
240+
221241 test ( 'step scaling with evaluation period & data points to alarm configured' , ( ) => {
222242 // GIVEN
223243 const stack = new cdk . Stack ( ) ;
@@ -274,6 +294,47 @@ describe('step scaling policy', () => {
274294 } ) . toThrow ( 'datapointsToAlarm cannot be less than 1, got: 0' ) ;
275295 } ) ;
276296
297+ test ( 'step scaling with datapointsToAlarm is greater than evaluationPeriods throws error' , ( ) => {
298+ // GIVEN
299+ const stack = new cdk . Stack ( ) ;
300+ const target = createScalableTarget ( stack ) ;
301+
302+ // THEN
303+ expect ( ( ) => {
304+ target . scaleOnMetric ( 'Tracking' , {
305+ metric : new cloudwatch . Metric ( { namespace : 'Test' , metricName : 'Metric' , statistic : 'p99' } ) ,
306+ scalingSteps : [
307+ { upper : 0 , change : - 1 } ,
308+ { lower : 100 , change : + 1 } ,
309+ { lower : 500 , change : + 5 } ,
310+ ] ,
311+ evaluationPeriods : 10 ,
312+ datapointsToAlarm : 15 ,
313+ metricAggregationType : appscaling . MetricAggregationType . MAXIMUM ,
314+ } ) ;
315+ } ) . toThrow ( / d a t a p o i n t s T o A l a r m m u s t b e l e s s t h a n o r e q u a l t o e v a l u a t i o n P e r i o d s , g o t d a t a p o i n t s T o A l a r m : 1 5 , e v a l u a t i o n P e r i o d s : 1 0 / ) ;
316+ } ) ;
317+
318+ test ( 'step scaling with datapointsToAlarm without evaluationPeriods throws error' , ( ) => {
319+ // GIVEN
320+ const stack = new cdk . Stack ( ) ;
321+ const target = createScalableTarget ( stack ) ;
322+
323+ // THEN
324+ expect ( ( ) => {
325+ target . scaleOnMetric ( 'Tracking' , {
326+ metric : new cloudwatch . Metric ( { namespace : 'Test' , metricName : 'Metric' , statistic : 'p99' } ) ,
327+ scalingSteps : [
328+ { upper : 0 , change : - 1 } ,
329+ { lower : 100 , change : + 1 } ,
330+ { lower : 500 , change : + 5 } ,
331+ ] ,
332+ datapointsToAlarm : 15 ,
333+ metricAggregationType : appscaling . MetricAggregationType . MAXIMUM ,
334+ } ) ;
335+ } ) . toThrow ( / e v a l u a t i o n P e r i o d s m u s t b e s e t i f d a t a p o i n t s T o A l a r m i s s e t / ) ;
336+ } ) ;
337+
277338 test ( 'scalingSteps must have at least 2 steps' , ( ) => {
278339 // GIVEN
279340 const stack = new cdk . Stack ( ) ;
0 commit comments