@@ -68,6 +68,23 @@ let DEFAULT_RUNNERS_ORG_TO_BE_REMOVED: RunnerInfo[];
68
68
let DEFAULT_RUNNERS_ORPHANED : RunnerInfo [ ] ;
69
69
let DEFAULT_REPO_RUNNERS_ORPHANED : RunnerInfo [ ] ;
70
70
let DEFAULT_ORG_RUNNERS_ORPHANED : RunnerInfo [ ] ;
71
+
72
+ // Add table of DEFAULT_RUNNERS_ORIGINAL without launchTime and owner
73
+ // instanceId | type | notes
74
+ // i-idle-101 | Repo | idle and exceeds minimumRunningTimeInMinutes
75
+ // i-idle-102 | Org | idle and exceeds minimumRunningTimeInMinutes
76
+ // i-oldest-idle-103 | Repo | idle and exceeds minimumRunningTimeInMinutes
77
+ // i-oldest-idle-104 | Org | idle and exceeds minimumRunningTimeInMinutes
78
+ // i-running-cannot-delete-105 | Repo | unable to delete
79
+ // i-running-cannot-delete-106 | Org | unable to delete
80
+ // i-orphan-107 | Repo | orphaned no GitHub registration and exceeds minimumRunningTimeInMinutes
81
+ // i-orphan-108 | Org | orphaned no GitHub registration and exceeds minimumRunningTimeInMinutes
82
+ // i-not-registered-108 | Org | not registered and not exceeding minimumRunningTimeInMinutes
83
+ // i-not-registered-109 | Repo | not registered and not exceeding minimumRunningTimeInMinutes
84
+ // i-running-110 | Org | running and not exceeding minimumRunningTimeInMinutes
85
+ // i-running-111 | Repo | running and not exceeding minimumRunningTimeInMinutes
86
+ // i-running-112 | Org | busy
87
+ // i-running-113 | Repo | busy
71
88
const DEFAULT_RUNNERS_ORIGINAL = [
72
89
{
73
90
instanceId : 'i-idle-101' ,
@@ -102,13 +119,13 @@ const DEFAULT_RUNNERS_ORIGINAL = [
102
119
owner : TEST_DATA . repositoryOwner ,
103
120
} ,
104
121
{
105
- instanceId : 'i-running-105' ,
122
+ instanceId : 'i-running-cannot-delete- 105' ,
106
123
launchTime : moment ( new Date ( ) ) . subtract ( 25 , 'minutes' ) . toDate ( ) ,
107
124
type : 'Repo' ,
108
125
owner : `doe/another-repo` ,
109
126
} ,
110
127
{
111
- instanceId : 'i-running-106' ,
128
+ instanceId : 'i-running-cannot-delete- 106' ,
112
129
launchTime : moment ( new Date ( ) ) . subtract ( 25 , 'minutes' ) . toDate ( ) ,
113
130
type : 'Org' ,
114
131
owner : TEST_DATA . repositoryOwner ,
@@ -122,41 +139,42 @@ const DEFAULT_RUNNERS_ORIGINAL = [
122
139
owner : `doe/another-repo` ,
123
140
} ,
124
141
{
125
- instanceId : 'i-not-registered -108' ,
142
+ instanceId : 'i-orphan -108' ,
126
143
launchTime : moment ( new Date ( ) )
127
- . subtract ( minimumRunningTimeInMinutes - 1 , 'minutes' )
144
+ . subtract ( minimumRunningTimeInMinutes + 5 , 'minutes' )
128
145
. toDate ( ) ,
129
- type : 'Repo ' ,
130
- owner : `doe/another-repo` ,
146
+ type : 'Org ' ,
147
+ owner : TEST_DATA . repositoryOwner ,
131
148
} ,
132
149
{
133
150
instanceId : 'i-not-registered-109' ,
134
151
launchTime : moment ( new Date ( ) )
135
- . subtract ( minimumRunningTimeInMinutes - 2 , 'minutes' )
152
+ . subtract ( runnerBootTimeInMinutes - 2 , 'minutes' )
136
153
. toDate ( ) ,
137
- type : 'Org ' ,
138
- owner : TEST_DATA . repositoryOwner ,
154
+ type : 'Repo ' ,
155
+ owner : `doe/another-repo` ,
139
156
} ,
140
157
{
141
- instanceId : 'i-legacy -110' ,
158
+ instanceId : 'i-not-registered -110' ,
142
159
launchTime : moment ( new Date ( ) )
143
- . subtract ( minimumRunningTimeInMinutes + 5 , 'minutes' )
160
+ . subtract ( runnerBootTimeInMinutes - 2 , 'minutes' )
144
161
. toDate ( ) ,
145
- repo : `${ TEST_DATA . repositoryOwner } /${ TEST_DATA . repositoryName } ` ,
162
+ type : 'Org' ,
163
+ owner : TEST_DATA . repositoryOwner ,
146
164
} ,
147
165
{
148
166
instanceId : 'i-new-111' ,
149
167
launchTime : moment ( new Date ( ) ) . toDate ( ) ,
150
168
repo : `${ TEST_DATA . repositoryOwner } /${ TEST_DATA . repositoryName } ` ,
151
169
} ,
152
170
{
153
- instanceId : 'i-running-112' ,
171
+ instanceId : 'i-running-busy- 112' ,
154
172
launchTime : moment ( new Date ( ) ) . subtract ( 25 , 'minutes' ) . toDate ( ) ,
155
173
type : 'Repo' ,
156
174
owner : `doe/another-repo` ,
157
175
} ,
158
176
{
159
- instanceId : 'i-running-113' ,
177
+ instanceId : 'i-running-busy- 113' ,
160
178
launchTime : moment ( new Date ( ) ) . subtract ( 25 , 'minutes' ) . toDate ( ) ,
161
179
type : 'Org' ,
162
180
owner : TEST_DATA . repositoryOwner ,
@@ -182,27 +200,19 @@ const DEFAULT_REGISTERED_RUNNERS = [
182
200
} ,
183
201
{
184
202
id : 105 ,
185
- name : 'i-running-105' ,
203
+ name : 'i-running-cannot-delete- 105' ,
186
204
} ,
187
205
{
188
206
id : 106 ,
189
- name : 'i-running-106' ,
190
- } ,
191
- {
192
- id : 1121 ,
193
- name : 'i-running-112-1' ,
194
- } ,
195
- {
196
- id : 1122 ,
197
- name : 'i-running-112-2' ,
207
+ name : 'i-running-cannot-delete-106' ,
198
208
} ,
199
209
{
200
- id : 1131 ,
201
- name : 'i-running-113-1 ' ,
210
+ id : 112 ,
211
+ name : 'i-running-busy-112 ' ,
202
212
} ,
203
213
{
204
- id : 1132 ,
205
- name : 'i-running-113-2 ' ,
214
+ id : 113 ,
215
+ name : 'i-running-busy-113 ' ,
206
216
} ,
207
217
] ;
208
218
@@ -251,7 +261,7 @@ describe('scaleDown', () => {
251
261
} ) ;
252
262
253
263
mockOctokit . actions . getSelfHostedRunnerForRepo . mockImplementation ( ( repo ) => {
254
- if ( repo . runner_id === 1121 ) {
264
+ if ( repo . runner_id === 112 ) {
255
265
return {
256
266
data : { busy : true } ,
257
267
} ;
@@ -262,7 +272,7 @@ describe('scaleDown', () => {
262
272
}
263
273
} ) ;
264
274
mockOctokit . actions . getSelfHostedRunnerForOrg . mockImplementation ( ( repo ) => {
265
- if ( repo . runner_id === 1131 ) {
275
+ if ( repo . runner_id === 113 ) {
266
276
return {
267
277
data : { busy : true } ,
268
278
} ;
@@ -347,7 +357,7 @@ describe('scaleDown', () => {
347
357
} ) ;
348
358
} ) ;
349
359
350
- it ( 'Terminates 3 of 5 runners owned by repos and all orphaned' , async ( ) => {
360
+ it ( 'Terminates 3 of 5 runners owned by repos and one orphaned' , async ( ) => {
351
361
mockListRunners . mockResolvedValue ( DEFAULT_RUNNERS_REPO ) ;
352
362
await scaleDown ( ) ;
353
363
expect ( listEC2Runners ) . toBeCalledWith ( {
@@ -356,7 +366,7 @@ describe('scaleDown', () => {
356
366
357
367
expect ( mockOctokit . apps . getRepoInstallation ) . toBeCalled ( ) ;
358
368
359
- expect ( terminateRunner ) . toBeCalledTimes ( 4 ) ;
369
+ expect ( terminateRunner ) . toBeCalledTimes ( 3 ) ;
360
370
for ( const toTerminate of DEFAULT_RUNNERS_REPO_TO_BE_REMOVED ) {
361
371
expect ( terminateRunner ) . toHaveBeenCalledWith ( toTerminate . instanceId ) ;
362
372
}
@@ -365,7 +375,7 @@ describe('scaleDown', () => {
365
375
}
366
376
} ) ;
367
377
368
- it ( 'Terminates 2 of 3 runners owned by orgs and all orphaned' , async ( ) => {
378
+ it ( 'Terminates 2 of 3 runners owned by orgs and one orphaned' , async ( ) => {
369
379
mockListRunners . mockResolvedValue ( DEFAULT_RUNNERS_ORG ) ;
370
380
await scaleDown ( ) ;
371
381
expect ( listEC2Runners ) . toBeCalledWith ( {
@@ -438,7 +448,7 @@ describe('scaleDown', () => {
438
448
expect ( terminateRunner ) . not . toBeCalled ;
439
449
} ) ;
440
450
441
- it ( 'Terminates 6 runners amongst all owners and all orphaned' , async ( ) => {
451
+ it ( 'Terminates 4 runners amongst all owners and two orphaned' , async ( ) => {
442
452
mockListRunners . mockResolvedValue ( DEFAULT_RUNNERS ) ;
443
453
await scaleDown ( ) ;
444
454
@@ -448,7 +458,7 @@ describe('scaleDown', () => {
448
458
449
459
expect ( mockOctokit . apps . getRepoInstallation ) . toBeCalledTimes ( 2 ) ;
450
460
expect ( mockOctokit . apps . getOrgInstallation ) . toBeCalledTimes ( 1 ) ;
451
- expect ( terminateRunner ) . toBeCalledTimes ( 7 ) ;
461
+ expect ( terminateRunner ) . toBeCalledTimes ( 6 ) ;
452
462
for ( const toTerminate of RUNNERS_ALL_REMOVED ) {
453
463
expect ( terminateRunner ) . toHaveBeenCalledWith ( toTerminate . instanceId ) ;
454
464
}
@@ -478,15 +488,15 @@ describe('scaleDown', () => {
478
488
} ) ;
479
489
} ) ;
480
490
481
- it ( 'Terminates 3 of 5 runners owned by repos and all orphaned' , async ( ) => {
491
+ it ( 'Terminates 3 of 5 runners owned by repos and one orphaned' , async ( ) => {
482
492
mockListRunners . mockResolvedValue ( DEFAULT_RUNNERS_REPO ) ;
483
493
await scaleDown ( ) ;
484
494
expect ( listEC2Runners ) . toBeCalledWith ( {
485
495
environment : environment ,
486
496
} ) ;
487
497
488
498
expect ( mockOctokit . apps . getRepoInstallation ) . toBeCalled ( ) ;
489
- expect ( terminateRunner ) . toBeCalledTimes ( 4 ) ;
499
+ expect ( terminateRunner ) . toBeCalledTimes ( 3 ) ;
490
500
for ( const toTerminate of DEFAULT_RUNNERS_REPO_TO_BE_REMOVED ) {
491
501
expect ( terminateRunner ) . toHaveBeenCalledWith ( toTerminate . instanceId ) ;
492
502
}
@@ -495,7 +505,7 @@ describe('scaleDown', () => {
495
505
}
496
506
} ) ;
497
507
498
- it ( 'Terminates 2 of 3 runners owned by orgs and all orphaned' , async ( ) => {
508
+ it ( 'Terminates 2 of 3 runners owned by orgs and one orphaned' , async ( ) => {
499
509
mockListRunners . mockResolvedValue ( DEFAULT_RUNNERS_ORG ) ;
500
510
await scaleDown ( ) ;
501
511
expect ( listEC2Runners ) . toBeCalledWith ( {
@@ -552,7 +562,7 @@ describe('scaleDown', () => {
552
562
} ) ;
553
563
} ) ;
554
564
555
- it ( 'Terminates 6 runners amongst all owners and all orphaned' , async ( ) => {
565
+ it ( 'Terminates 4 runners amongst all owners and two orphaned' , async ( ) => {
556
566
mockListRunners . mockResolvedValue ( DEFAULT_RUNNERS ) ;
557
567
await scaleDown ( ) ;
558
568
@@ -562,7 +572,7 @@ describe('scaleDown', () => {
562
572
563
573
expect ( mockOctokit . apps . getRepoInstallation ) . toBeCalledTimes ( 2 ) ;
564
574
expect ( mockOctokit . apps . getOrgInstallation ) . toBeCalledTimes ( 1 ) ;
565
- expect ( terminateRunner ) . toBeCalledTimes ( 7 ) ;
575
+ expect ( terminateRunner ) . toBeCalledTimes ( 6 ) ;
566
576
for ( const toTerminate of RUNNERS_ALL_REMOVED ) {
567
577
expect ( terminateRunner ) . toHaveBeenCalledWith ( toTerminate . instanceId ) ;
568
578
}
0 commit comments