优化
This commit is contained in:
@@ -34,7 +34,7 @@ async function until(check, message) {
|
||||
assert.fail(message)
|
||||
}
|
||||
|
||||
test('local-check serializes different directories, handles failures and recovers process trees', { skip: process.platform !== 'win32', timeout: 90000 }, async t => {
|
||||
test('local-check bounds different directories to two slots, handles failures and recovers process trees', { skip: process.platform !== 'win32', timeout: 120000 }, async t => {
|
||||
const state = await mkdtemp(path.join(os.tmpdir(), 'local-check-test-'))
|
||||
const processes = []
|
||||
const start = (...args) => { const result = run(state, ...args); processes.push(result); return result }
|
||||
@@ -46,19 +46,31 @@ test('local-check serializes different directories, handles failures and recover
|
||||
assert.match(result.output, /"2","--max-old-space-size=2048"/)
|
||||
assert.match(result.output, /ActiveProcessorCount=2 -Xmx1536m/)
|
||||
})
|
||||
await t.test('a running check excludes another directory and queue timeout starts nothing', async () => {
|
||||
const first = start([process.execPath, '-e', 'console.log("HOLDER_READY");setTimeout(()=>{},4000)'])
|
||||
await until(() => first.output().includes('HOLDER_READY'), first.output())
|
||||
await t.test('two directories run together; a third times out or waits until one lease is released', async () => {
|
||||
const releaseFirst = path.join(state, 'release-first'), releaseSecond = path.join(state, 'release-second')
|
||||
const hold = (file, label) => `const fs=require('fs');console.log(${JSON.stringify(label)});const timer=setInterval(()=>{if(fs.existsSync(${JSON.stringify(file)}))clearInterval(timer)},50)`
|
||||
const first = start([process.execPath, '-e', hold(releaseFirst, 'FIRST_READY')], { timeout: 30 })
|
||||
await until(() => first.output().includes('FIRST_READY'), first.output())
|
||||
const second = start([process.execPath, '-e', hold(releaseSecond, 'SECOND_READY')], { cwd: path.dirname(launcher), timeout: 30 })
|
||||
await until(() => second.output().includes('SECOND_READY'), second.output())
|
||||
assert.equal(first.child.exitCode, null)
|
||||
const owners = await Promise.all(['owner.json', 'owner-2.json'].map(name => readFile(path.join(state, 'Chongchong', 'LocalChecks', name), 'utf8').then(JSON.parse)))
|
||||
assert.deepEqual(owners.map(owner => owner.slot).sort(), [1, 2])
|
||||
assert.equal(new Set(owners.map(owner => owner.directory)).size, 2)
|
||||
const timedOut = await start([process.execPath, '-e', 'console.log("SHOULD_NOT_RUN")'], { wait: 0, cwd: path.dirname(launcher) }).done
|
||||
assert.equal(timedOut.code, 75, timedOut.output)
|
||||
assert.doesNotMatch(timedOut.output, /SHOULD_NOT_RUN/)
|
||||
const second = start([process.execPath, '-e', 'console.log("SECOND_READY")'], { cwd: path.dirname(launcher) })
|
||||
await until(() => second.output().includes('WAITING'), second.output())
|
||||
assert.doesNotMatch(second.output(), /SECOND_READY/)
|
||||
const third = start([process.execPath, '-e', 'console.log("THIRD_READY")'], { cwd: state })
|
||||
await until(() => third.output().includes('WAITING'), third.output())
|
||||
assert.doesNotMatch(third.output(), /THIRD_READY/)
|
||||
await writeFile(releaseFirst, '')
|
||||
assert.equal((await first.done).code, 0)
|
||||
const result = await second.done
|
||||
const result = await third.done
|
||||
assert.equal(result.code, 0, result.output)
|
||||
assert.match(result.output, /SECOND_READY/)
|
||||
assert.match(result.output, /THIRD_READY/)
|
||||
assert.equal(second.child.exitCode, null)
|
||||
await writeFile(releaseSecond, '')
|
||||
assert.equal((await second.done).code, 0)
|
||||
})
|
||||
await t.test('execution timeout kills descendants and frees the slot', async () => {
|
||||
const pidFile = path.join(state, 'descendant.pid')
|
||||
|
||||
Reference in New Issue
Block a user