-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathproc_pool.test.ts
More file actions
72 lines (62 loc) · 2.33 KB
/
Copy pathproc_pool.test.ts
File metadata and controls
72 lines (62 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-FileCopyrightText: 2026 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0
import { Throws } from '@livekit/throws-transformer/throws';
import { describe, expect, it, vi } from 'vitest';
import type { RunningJobInfo } from '../job.js';
import { type JobExecutor, JobStatus } from './job_executor.js';
import { ProcPool } from './proc_pool.js';
function createMockExecutor() {
const executor: JobExecutor = {
started: true,
userArguments: {},
runningJob: undefined,
status: JobStatus.RUNNING,
start: vi.fn(async () => {}),
join: vi.fn(async () => {}),
initialize: vi.fn(async () => {}),
close: vi.fn(async () => {}),
launchJob: vi.fn(async () => {}),
};
return executor;
}
describe('ProcPool warmed process lock handling', () => {
it('releases lock token from the dequeued warmed process entry', async (): Promise<
Throws<void, Error>
> => {
const pool = new ProcPool('agent', 1, 1000, 1000, undefined, 0, 0);
const unlock = vi.fn();
const executor = createMockExecutor();
const jobInfo = {
acceptArguments: { name: 'n', identity: 'i', metadata: '' },
job: { id: 'job-id' },
url: 'wss://example.com',
token: 'token',
workerId: 'worker-id',
} as unknown as RunningJobInfo;
await pool.warmedProcQueue.put({ proc: executor, unlock });
await pool.launchJob(jobInfo);
expect(unlock).toHaveBeenCalledTimes(1);
expect(executor.launchJob).toHaveBeenCalledWith(jobInfo);
});
it('releases queued lock tokens during close', async () => {
const pool = new ProcPool('agent', 1, 1000, 1000, undefined, 0, 0);
const unlock = vi.fn();
const executor = createMockExecutor();
await pool.warmedProcQueue.put({ proc: executor, unlock });
pool.started = true;
await pool.close();
expect(unlock).toHaveBeenCalledTimes(1);
expect(executor.close).toHaveBeenCalledTimes(1);
});
it('releases both init and proc locks when closed before proc starts', async () => {
const pool = new ProcPool('agent', 1, 1000, 1000, undefined, 0, 0);
const initUnlock = vi.fn();
const procUnlock = vi.fn();
pool.closed = true;
pool.initMutex.lock = vi.fn(async () => initUnlock);
await pool.procWatchTask(procUnlock);
expect(initUnlock).toHaveBeenCalledTimes(1);
expect(procUnlock).toHaveBeenCalledTimes(1);
});
});