Skip to content

Commit 1c940f3

Browse files
test: align runner tests with provider modules (github-aws-runners#5232)
## Description Align test-file ownership with the runner-provider module layout introduced in github-aws-runners#5203 and requested in github-aws-runners#5230. This PR only renames or relocates existing tests. Provider-neutral tests remain beside the shared orchestration modules, while EC2-specific tests move beside their EC2 implementations. I plan to create following PR to reduced some duplicated tests. I didn't change in this PR to prevent a hard review ### Test cases moved or renamed - Renamed `control-plane/src/aws/runners.test.ts` to `ec2-runners.test.ts`. - Renamed `webhook/src/runners/dynamic-labels-policy.test.ts` to `ec2-dynamic-labels-policy.test.ts`. - Moved 19 existing `canRunJob` test declarations from `dispatch.test.ts` to `labels.test.ts`. - Moved four existing AWS dynamic-label test declarations from `dispatch.test.ts` to `aws-dynamic-labels.test.ts`. - Moved three existing EC2 dynamic-label test declarations from `dispatch.test.ts` to `ec2-dynamic-labels.test.ts`; 18 dispatch integration tests remain in `dispatch.test.ts`. - Moved four existing EC2 pool-size test declarations from `pool.test.ts` to `ec2-pool.test.ts`; 17 provider-neutral pool tests remain in `pool.test.ts`. - Moved 20 existing EC2 scale-down test declarations from `scale-down.test.ts` to `ec2-scale-down.test.ts`; four provider-neutral eviction-order tests remain in `scale-down.test.ts`. - Moved 251 existing EC2 scale-up test declarations from `scale-up.test.ts` to `ec2-scale-up.test.ts`; the provider-selection test remains in `scale-up.test.ts`. ### Test cases created None. ### Duplicated test cases merged None. ### Test cases deleted None. The test titles and coverage from `origin/main` are preserved. ## Test Plan - Renamed EC2 suites: 85 tests passed. - Webhook runner suites: 44 tests passed. - Pool suites: 21 tests passed. - Scale-down suites: 130 tests passed. - Scale-up suites: 254 tests passed. - ESLint passed for every affected test file. - `git diff --check` passed. - Repository pre-commit hooks passed for all five commits. ## Related Issues Closes github-aws-runners#5230
1 parent 9045340 commit 1c940f3

12 files changed

Lines changed: 4729 additions & 4664 deletions

lambdas/functions/control-plane/src/aws/runners.test.ts renamed to lambdas/functions/control-plane/src/aws/ec2-runners.test.ts

File renamed without changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { bootTimeExceeded } from '../aws/ec2-runners';
2+
import type { RunnerList } from '../aws/ec2-runners.d';
3+
import { calculateEc2PoolSize } from './ec2-pool';
4+
import { beforeEach, describe, expect, it, vi } from 'vitest';
5+
6+
vi.mock('../aws/ec2-runners', () => ({
7+
bootTimeExceeded: vi.fn(),
8+
}));
9+
10+
const mockBootTimeExceeded = vi.mocked(bootTimeExceeded);
11+
12+
describe('calculateEc2PoolSize', () => {
13+
beforeEach(() => {
14+
vi.clearAllMocks();
15+
});
16+
17+
it('counts registered online idle runners', () => {
18+
const runners: RunnerList[] = [{ instanceId: 'i-idle' }];
19+
const runnerStatus = new Map([['i-idle', { busy: false, status: 'online' }]]);
20+
21+
expect(calculateEc2PoolSize(runners, runnerStatus)).toBe(1);
22+
expect(mockBootTimeExceeded).not.toHaveBeenCalled();
23+
});
24+
25+
it('does not count registered busy or offline runners', () => {
26+
const runners: RunnerList[] = [{ instanceId: 'i-busy' }, { instanceId: 'i-offline' }];
27+
const runnerStatus = new Map([
28+
['i-busy', { busy: true, status: 'online' }],
29+
['i-offline', { busy: false, status: 'offline' }],
30+
]);
31+
32+
expect(calculateEc2PoolSize(runners, runnerStatus)).toBe(0);
33+
expect(mockBootTimeExceeded).not.toHaveBeenCalled();
34+
});
35+
36+
it('counts unregistered runners that are still booting', () => {
37+
const runners: RunnerList[] = [{ instanceId: 'i-booting' }];
38+
mockBootTimeExceeded.mockReturnValue(false);
39+
40+
expect(calculateEc2PoolSize(runners, new Map())).toBe(1);
41+
});
42+
43+
it('does not count unregistered runners whose boot time expired', () => {
44+
const runners: RunnerList[] = [{ instanceId: 'i-expired' }];
45+
mockBootTimeExceeded.mockReturnValue(true);
46+
47+
expect(calculateEc2PoolSize(runners, new Map())).toBe(0);
48+
});
49+
});

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

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import { Octokit } from '@octokit/rest';
22
import moment from 'moment-timezone';
33
import * as nock from 'nock';
44

5-
import { bootTimeExceeded, listEC2Runners } from '../aws/ec2-runners';
6-
import type { RunnerList } from '../aws/ec2-runners.d';
5+
import { listEC2Runners } from '../aws/ec2-runners';
76
import * as ghAuth from '../github/auth';
87
import { createRunners } from '../scale-runners/ec2';
98
import { getGitHubEnterpriseApiUrl } from '../scale-runners/github-runner';
109
import { adjust } from './pool';
11-
import { calculateEc2PoolSize } from './ec2-pool';
1210
import { describe, it, expect, beforeEach, vi, MockedClass } from 'vitest';
1311

1412
const mockOctokit = {
@@ -57,7 +55,6 @@ const mockedAppAuth = vi.mocked(ghAuth.createGithubAppAuth);
5755
const mockedInstallationAuth = vi.mocked(ghAuth.createGithubInstallationAuth);
5856
const mockCreateClient = vi.mocked(ghAuth.createOctokitClient);
5957
const mockListRunners = vi.mocked(listEC2Runners);
60-
const mockBootTimeExceeded = vi.mocked(bootTimeExceeded);
6158

6259
const cleanEnv = process.env;
6360

@@ -496,42 +493,3 @@ describe('Test simple pool.', () => {
496493
});
497494
});
498495
});
499-
500-
describe('calculateEc2PoolSize', () => {
501-
beforeEach(() => {
502-
vi.clearAllMocks();
503-
});
504-
505-
it('counts registered online idle runners', () => {
506-
const runners: RunnerList[] = [{ instanceId: 'i-idle' }];
507-
const runnerStatus = new Map([['i-idle', { busy: false, status: 'online' }]]);
508-
509-
expect(calculateEc2PoolSize(runners, runnerStatus)).toBe(1);
510-
expect(mockBootTimeExceeded).not.toHaveBeenCalled();
511-
});
512-
513-
it('does not count registered busy or offline runners', () => {
514-
const runners: RunnerList[] = [{ instanceId: 'i-busy' }, { instanceId: 'i-offline' }];
515-
const runnerStatus = new Map([
516-
['i-busy', { busy: true, status: 'online' }],
517-
['i-offline', { busy: false, status: 'offline' }],
518-
]);
519-
520-
expect(calculateEc2PoolSize(runners, runnerStatus)).toBe(0);
521-
expect(mockBootTimeExceeded).not.toHaveBeenCalled();
522-
});
523-
524-
it('counts unregistered runners that are still booting', () => {
525-
const runners: RunnerList[] = [{ instanceId: 'i-booting' }];
526-
mockBootTimeExceeded.mockReturnValue(false);
527-
528-
expect(calculateEc2PoolSize(runners, new Map())).toBe(1);
529-
});
530-
531-
it('does not count unregistered runners whose boot time expired', () => {
532-
const runners: RunnerList[] = [{ instanceId: 'i-expired' }];
533-
mockBootTimeExceeded.mockReturnValue(true);
534-
535-
expect(calculateEc2PoolSize(runners, new Map())).toBe(0);
536-
});
537-
});

0 commit comments

Comments
 (0)