|
| 1 | +importtype{ChildProcess}from'node:child_process' |
| 2 | +import{fileURLToPath}from'node:url' |
| 3 | +import{afterEach,describe,expect,it,vi}from'vitest' |
| 4 | + |
| 5 | +import{ForkPool}from'../../src/dev/pool' |
| 6 | + |
| 7 | +constdevEntry=fileURLToPath(newURL('../fixtures/fork-pool-entry.mjs',import.meta.url)) |
| 8 | + |
| 9 | +constpools: ForkPool[]=[] |
| 10 | + |
| 11 | +functioncreatePool(poolSize?: number){ |
| 12 | +globalThis.__nuxt_cli__={ ...globalThis.__nuxt_cli__, devEntry }astypeofglobalThis.__nuxt_cli__ |
| 13 | +constpool=newForkPool({rawArgs: [], poolSize,listenOverrides: {}}) |
| 14 | +pools.push(pool) |
| 15 | +returnpool |
| 16 | +} |
| 17 | + |
| 18 | +asyncfunctionwaitForReady(pool: ForkPool,count: number){ |
| 19 | +awaitvi.waitFor(()=>{ |
| 20 | +expect(pool.getStats().ready).toBe(count) |
| 21 | +},{timeout: 20_000,interval: 25}) |
| 22 | +} |
| 23 | + |
| 24 | +afterEach(async()=>{ |
| 25 | +for(constpoolofpools.splice(0)){ |
| 26 | +await(poolasunknownas{killAll: (signal: number)=>void}).killAll(0) |
| 27 | +} |
| 28 | +}) |
| 29 | + |
| 30 | +describe('forkPool',()=>{ |
| 31 | +it('should kill every fork on shutdown',{timeout: 30_000},async()=>{ |
| 32 | +constpool=createPool(3) |
| 33 | +pool.startWarming() |
| 34 | +awaitwaitForReady(pool,3) |
| 35 | + |
| 36 | +constprocesses=(poolasunknownas{pool: Array<{process: ChildProcess}>}).pool.map(f=>f.process) |
| 37 | +;(poolasunknownas{killAll: (signal: number)=>void}).killAll(0) |
| 38 | + |
| 39 | +awaitvi.waitFor(()=>{ |
| 40 | +for(constchildofprocesses){ |
| 41 | +expect(child.killed).toBe(true) |
| 42 | +} |
| 43 | +},{timeout: 10_000,interval: 25}) |
| 44 | +expect(pool.getStats().total).toBe(0) |
| 45 | +}) |
| 46 | +}) |
0 commit comments