@@ -32,6 +32,7 @@ export interface TestData {
3232}
3333
3434const environment = 'unit-test-environment' ;
35+ const minimumRunningTimeInMinutes = 15 ;
3536const TEST_DATA : TestData = {
3637 repositoryName : 'hello-world' ,
3738 repositoryOwner : 'Codertocat' ,
@@ -58,7 +59,17 @@ const DEFAULT_RUNNERS = [
5859 } ,
5960 {
6061 instanceId : 'i-not-registered-104' ,
61- launchTime : moment ( new Date ( ) ) . subtract ( 5 , 'minutes' ) . toDate ( ) ,
62+ launchTime : moment ( new Date ( ) )
63+ . subtract ( minimumRunningTimeInMinutes - 1 , 'minutes' )
64+ . toDate ( ) ,
65+ repo : `doe/another-repo` ,
66+ org : undefined ,
67+ } ,
68+ {
69+ instanceId : 'i-not-registered-105' ,
70+ launchTime : moment ( new Date ( ) )
71+ . subtract ( minimumRunningTimeInMinutes + 5 , 'minutes' )
72+ . toDate ( ) ,
6273 repo : `doe/another-repo` ,
6374 org : undefined ,
6475 } ,
@@ -73,7 +84,7 @@ const DEFAULT_REGISTERED_RUNNERS: any = {
7384 } ,
7485 {
7586 id : 102 ,
76- name : 'i-idle-101 ' ,
87+ name : 'i-idle-102 ' ,
7788 } ,
7889 {
7990 id : 103 ,
@@ -91,8 +102,7 @@ describe('scaleDown', () => {
91102 process . env . GITHUB_APP_CLIENT_SECRET = 'TEST_CLIENT_SECRET' ;
92103 process . env . RUNNERS_MAXIMUM_COUNT = '3' ;
93104 process . env . ENVIRONMENT = environment ;
94- const minimumRunningTimeInMinutes = '15' ;
95- process . env . MINIMUM_RUNNING_TIME_IN_MINUTES = minimumRunningTimeInMinutes ;
105+ process . env . MINIMUM_RUNNING_TIME_IN_MINUTES = minimumRunningTimeInMinutes . toString ( ) ;
96106 jest . clearAllMocks ( ) ;
97107 mockOctokit . apps . getOrgInstallation . mockImplementation ( ( ) => ( {
98108 data : {
@@ -166,15 +176,17 @@ describe('scaleDown', () => {
166176 } ) ;
167177 } ) ;
168178
169- it ( 'Terminate 2 of 4 runners for repo.' , async ( ) => {
179+ it ( 'Terminate 3 of 5 runners for repo.' , async ( ) => {
170180 await scaleDown ( ) ;
171181 expect ( listRunners ) . toBeCalledWith ( {
172182 environment : environment ,
173183 } ) ;
174184
175185 expect ( mockOctokit . apps . getRepoInstallation ) . toBeCalled ( ) ;
176-
177- expect ( terminateRunner ) . toBeCalledTimes ( 2 ) ;
186+ expect ( terminateRunner ) . toBeCalledTimes ( 3 ) ;
187+ for ( const toTerminate of [ DEFAULT_RUNNERS [ 0 ] , DEFAULT_RUNNERS [ 1 ] , DEFAULT_RUNNERS [ 4 ] ] ) {
188+ expect ( terminateRunner ) . toHaveBeenCalledWith ( toTerminate ) ;
189+ }
178190 } ) ;
179191 } ) ;
180192
@@ -187,15 +199,17 @@ describe('scaleDown', () => {
187199 } ) ;
188200 } ) ;
189201
190- it ( 'Terminate 2 of 4 runners for org.' , async ( ) => {
202+ it ( 'Terminate 3 of 5 runners for org.' , async ( ) => {
191203 await scaleDown ( ) ;
192204 expect ( listRunners ) . toBeCalledWith ( {
193205 environment : environment ,
194206 } ) ;
195207
196208 expect ( mockOctokit . apps . getOrgInstallation ) . toBeCalled ( ) ;
197-
198- expect ( terminateRunner ) . toBeCalledTimes ( 2 ) ;
209+ expect ( terminateRunner ) . toBeCalledTimes ( 3 ) ;
210+ for ( const toTerminate of [ DEFAULT_RUNNERS [ 0 ] , DEFAULT_RUNNERS [ 1 ] , DEFAULT_RUNNERS [ 4 ] ] ) {
211+ expect ( terminateRunner ) . toHaveBeenCalledWith ( toTerminate ) ;
212+ }
199213 } ) ;
200214 } ) ;
201215} ) ;
0 commit comments