Skip to content

Commit 264ee5d

Browse files
committed
test: add test to simulate JIT Config creation 503 from GitHub API
1 parent 6090d36 commit 264ee5d

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

lambdas/functions/control-plane/src/scale-runners/scale-up.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,80 @@ describe('scaleUp with GHES', () => {
336336
],
337337
});
338338
});
339+
340+
it('should create JIT config for all remaining instances even when GitHub API fails for one instance', async () => {
341+
process.env.RUNNERS_MAXIMUM_COUNT = '5';
342+
mockCreateRunner.mockImplementation(async () => {
343+
return ['i-instance-1', 'i-instance-2', 'i-instance-3'];
344+
});
345+
mockListRunners.mockImplementation(async () => {
346+
return [];
347+
});
348+
349+
let callCount = 0;
350+
mockOctokit.actions.generateRunnerJitconfigForOrg.mockImplementation(({ name }) => {
351+
callCount++;
352+
if (name === 'unit-test-i-instance-2') {
353+
// Simulate a 503 Service Unavailable error from GitHub
354+
const error = new Error('Service Unavailable') as any;
355+
error.status = 503;
356+
error.response = {
357+
status: 503,
358+
data: { message: 'Service temporarily unavailable' },
359+
};
360+
throw error;
361+
}
362+
return {
363+
data: {
364+
runner: { id: 9876543210 + callCount },
365+
encoded_jit_config: `TEST_JIT_CONFIG_${name}`,
366+
},
367+
headers: {},
368+
};
369+
});
370+
371+
await scaleUpModule.scaleUp(TEST_DATA);
372+
373+
expect(mockOctokit.actions.generateRunnerJitconfigForOrg).toHaveBeenCalledWith({
374+
org: TEST_DATA_SINGLE.repositoryOwner,
375+
name: 'unit-test-i-instance-1',
376+
runner_group_id: 1,
377+
labels: ['label1', 'label2'],
378+
});
379+
380+
expect(mockOctokit.actions.generateRunnerJitconfigForOrg).toHaveBeenCalledWith({
381+
org: TEST_DATA_SINGLE.repositoryOwner,
382+
name: 'unit-test-i-instance-2',
383+
runner_group_id: 1,
384+
labels: ['label1', 'label2'],
385+
});
386+
387+
expect(mockOctokit.actions.generateRunnerJitconfigForOrg).toHaveBeenCalledWith({
388+
org: TEST_DATA_SINGLE.repositoryOwner,
389+
name: 'unit-test-i-instance-3',
390+
runner_group_id: 1,
391+
labels: ['label1', 'label2'],
392+
});
393+
394+
expect(mockSSMClient).toHaveReceivedCommandWith(PutParameterCommand, {
395+
Name: '/github-action-runners/default/runners/config/i-instance-1',
396+
Value: 'TEST_JIT_CONFIG_unit-test-i-instance-1',
397+
Type: 'SecureString',
398+
Tags: [{ Key: 'InstanceId', Value: 'i-instance-1' }],
399+
});
400+
401+
expect(mockSSMClient).toHaveReceivedCommandWith(PutParameterCommand, {
402+
Name: '/github-action-runners/default/runners/config/i-instance-3',
403+
Value: 'TEST_JIT_CONFIG_unit-test-i-instance-3',
404+
Type: 'SecureString',
405+
Tags: [{ Key: 'InstanceId', Value: 'i-instance-3' }],
406+
});
407+
408+
expect(mockSSMClient).not.toHaveReceivedCommandWith(PutParameterCommand, {
409+
Name: '/github-action-runners/default/runners/config/i-instance-2',
410+
});
411+
});
412+
339413
it.each(RUNNER_TYPES)(
340414
'calls create start runner config of 40' + ' instances (ssm rate limit condition) to test time delay ',
341415
async (type: RunnerType) => {

0 commit comments

Comments
 (0)