Skip to content

Commit f8bc290

Browse files
committed
chore: improve pool statement test coverage
1 parent eada9ce commit f8bc290

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lambdas/functions/control-plane/src/pool/pool.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ describe('Test simple pool.', () => {
266266
await expect(await adjust({ poolSize: 2 })).resolves;
267267
expect(createRunners).not.toHaveBeenCalled();
268268
});
269+
270+
it('Should not top up if pool size is invalid.', async () => {
271+
await expect(await adjust({ poolSize: -2 })).resolves;
272+
expect(createRunners).not.toHaveBeenCalled();
273+
});
269274
});
270275

271276
describe('With GHES', () => {
@@ -368,6 +373,7 @@ describe('Test simple pool.', () => {
368373
await expect(await adjust({ poolSize: -1 })).resolves;
369374
expect(createRunners).not.toHaveBeenCalled();
370375
});
376+
371377
// effective pool size is 8 (2 queued job with matching labels x 2 workflows x 2 accessible repositories)
372378
it('Should top up if there are more queued jobs with matching labels than idle runners.', async () => {
373379
mockOctokit.actions.listWorkflowRunsForRepo.mockImplementation(async ({ owner, repo }) => [
@@ -420,6 +426,46 @@ describe('Test simple pool.', () => {
420426
expect.anything(),
421427
);
422428
});
429+
430+
it('Should top up the repository runners pool dynamically', async () => {
431+
const runnerOwner = `${ORG}/my-repo-1`;
432+
process.env.RUNNER_OWNER = runnerOwner;
433+
mockOctokit.actions.listWorkflowRunsForRepo.mockImplementation(async ({ owner, repo }) => [
434+
{
435+
repository: {
436+
owner: { login: owner },
437+
name: repo,
438+
},
439+
id: 1,
440+
attempt_number: 1,
441+
},
442+
{
443+
repository: {
444+
owner: { login: owner },
445+
name: repo,
446+
},
447+
id: 2,
448+
attempt_number: 1,
449+
},
450+
]);
451+
mockOctokit.actions.listJobsForWorkflowRunAttempt.mockImplementation(async () => [
452+
{
453+
status: 'queued',
454+
labels: LABELS,
455+
},
456+
{
457+
status: 'queued',
458+
labels: LABELS,
459+
},
460+
]);
461+
await expect(await adjust({ poolSize: -1 })).resolves;
462+
expect(createRunners).toHaveBeenCalledTimes(1);
463+
expect(createRunners).toHaveBeenCalledWith(
464+
expect.objectContaining({ runnerOwner, runnerType: 'Repo' }),
465+
expect.objectContaining({ numberOfRunners: 2 }),
466+
expect.anything(),
467+
);
468+
});
423469
});
424470

425471
describe('With Multiple Runner Owners', () => {

0 commit comments

Comments
 (0)