@@ -72,6 +72,41 @@ const ec2InstancesRegistered = [
72
72
} ,
73
73
] ;
74
74
75
+ const githubRunnersRegistered = [
76
+ {
77
+ id : 1 ,
78
+ name : 'i-1-idle' ,
79
+ os : 'linux' ,
80
+ status : 'online' ,
81
+ busy : false ,
82
+ labels : [ ] ,
83
+ } ,
84
+ {
85
+ id : 2 ,
86
+ name : 'i-2-busy' ,
87
+ os : 'linux' ,
88
+ status : 'online' ,
89
+ busy : true ,
90
+ labels : [ ] ,
91
+ } ,
92
+ {
93
+ id : 3 ,
94
+ name : 'i-3-offline' ,
95
+ os : 'linux' ,
96
+ status : 'offline' ,
97
+ busy : false ,
98
+ labels : [ ] ,
99
+ } ,
100
+ {
101
+ id : 3 ,
102
+ name : 'i-4-idle-older-than-minimum-time-running' ,
103
+ os : 'linux' ,
104
+ status : 'online' ,
105
+ busy : false ,
106
+ labels : [ ] ,
107
+ } ,
108
+ ] ;
109
+
75
110
beforeEach ( ( ) => {
76
111
nock . disableNetConnect ( ) ;
77
112
jest . resetModules ( ) ;
@@ -99,40 +134,7 @@ beforeEach(() => {
99
134
} ;
100
135
mockOctokit . actions . createRegistrationTokenForOrg . mockImplementation ( ( ) => mockTokenReturnValue ) ;
101
136
102
- mockOctokit . paginate . mockImplementation ( ( ) => [
103
- {
104
- id : 1 ,
105
- name : 'i-1-idle' ,
106
- os : 'linux' ,
107
- status : 'online' ,
108
- busy : false ,
109
- labels : [ ] ,
110
- } ,
111
- {
112
- id : 2 ,
113
- name : 'i-2-busy' ,
114
- os : 'linux' ,
115
- status : 'online' ,
116
- busy : true ,
117
- labels : [ ] ,
118
- } ,
119
- {
120
- id : 3 ,
121
- name : 'i-3-offline' ,
122
- os : 'linux' ,
123
- status : 'offline' ,
124
- busy : false ,
125
- labels : [ ] ,
126
- } ,
127
- {
128
- id : 3 ,
129
- name : 'i-4-idle-older-than-minimum-time-running' ,
130
- os : 'linux' ,
131
- status : 'online' ,
132
- busy : false ,
133
- labels : [ ] ,
134
- } ,
135
- ] ) ;
137
+ mockOctokit . paginate . mockImplementation ( ( ) => githubRunnersRegistered ) ;
136
138
137
139
mockListRunners . mockImplementation ( async ( ) => ec2InstancesRegistered ) ;
138
140
@@ -251,4 +253,58 @@ describe('Test simple pool.', () => {
251
253
) ;
252
254
} ) ;
253
255
} ) ;
256
+
257
+ describe ( 'With Runner Name Prefix' , ( ) => {
258
+ beforeEach ( ( ) => {
259
+ process . env . RUNNER_NAME_PREFIX = 'runner-prefix_' ;
260
+ } ) ;
261
+
262
+ it ( 'Should top up with fewer runners when there are idle prefixed runners' , async ( ) => {
263
+ // Add prefixed runners to github
264
+ mockOctokit . paginate . mockImplementation ( async ( ) => [
265
+ ...githubRunnersRegistered ,
266
+ {
267
+ id : 5 ,
268
+ name : 'runner-prefix_i-5-idle' ,
269
+ os : 'linux' ,
270
+ status : 'online' ,
271
+ busy : false ,
272
+ labels : [ ] ,
273
+ } ,
274
+ {
275
+ id : 6 ,
276
+ name : 'runner-prefix_i-6-idle' ,
277
+ os : 'linux' ,
278
+ status : 'online' ,
279
+ busy : false ,
280
+ labels : [ ] ,
281
+ } ,
282
+ ] ) ;
283
+
284
+ // Add instances in ec2
285
+ mockListRunners . mockImplementation ( async ( ) => [
286
+ ...ec2InstancesRegistered ,
287
+ {
288
+ instanceId : 'i-5-idle' ,
289
+ launchTime : new Date ( ) ,
290
+ type : 'Org' ,
291
+ owner : ORG ,
292
+ } ,
293
+ {
294
+ instanceId : 'i-6-idle' ,
295
+ launchTime : new Date ( ) ,
296
+ type : 'Org' ,
297
+ owner : ORG ,
298
+ } ,
299
+ ] ) ;
300
+
301
+ await expect ( await adjust ( { poolSize : 5 } ) ) . resolves ;
302
+ // 2 idle, 2 prefixed idle top up with 1 to match a pool of 5
303
+ expect ( createRunners ) . toHaveBeenCalledWith (
304
+ expect . anything ( ) ,
305
+ expect . objectContaining ( { numberOfRunners : 1 } ) ,
306
+ expect . anything ( ) ,
307
+ ) ;
308
+ } ) ;
309
+ } ) ;
254
310
} ) ;
0 commit comments