mirror of
https://github.com/iflytek/skillhub.git
synced 2026-10-15 04:18:20 +00:00
test(cli): synchronize stale lock contenders
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
This commit is contained in:
parent
80c31a5bb7
commit
2c80b720b5
2 changed files with 18 additions and 4 deletions
|
|
@ -2,10 +2,20 @@ import { access, writeFile } from 'node:fs/promises'
|
|||
import { acquireSkillTargetLock } from '../../src/services/skill-target-lock'
|
||||
import { CliError } from '../../src/shared/errors'
|
||||
|
||||
const [rootDir, slug, acquiredPath, releasePath] = process.argv.slice(2)
|
||||
if (!rootDir || !slug || !acquiredPath || !releasePath) process.exit(5)
|
||||
const [rootDir, slug, readyPath, startPath, acquiredPath, releasePath] = process.argv.slice(2)
|
||||
if (!rootDir || !slug || !readyPath || !startPath || !acquiredPath || !releasePath) process.exit(5)
|
||||
|
||||
try {
|
||||
await writeFile(readyPath, 'ready')
|
||||
let startRequested = false
|
||||
while (!startRequested) {
|
||||
try {
|
||||
await access(startPath)
|
||||
startRequested = true
|
||||
} catch {
|
||||
await new Promise(resolve => setTimeout(resolve, 10))
|
||||
}
|
||||
}
|
||||
const release = await acquireSkillTargetLock(rootDir, slug)
|
||||
await writeFile(acquiredPath, 'acquired')
|
||||
process.stdout.write('acquired\n')
|
||||
|
|
|
|||
|
|
@ -69,13 +69,17 @@ describe('skill target lifecycle lock', () => {
|
|||
const bunPath = (await Bun.which('bun')) ?? process.execPath
|
||||
const acquiredPath = join(rootDir, 'acquired')
|
||||
const releasePath = join(rootDir, 'release')
|
||||
const startPath = join(rootDir, 'start')
|
||||
const readyPaths = [join(rootDir, 'ready-0'), join(rootDir, 'ready-1')]
|
||||
|
||||
const processes = [0, 1].map(() => Bun.spawn({
|
||||
cmd: [bunPath, worker, rootDir, 'demo', acquiredPath, releasePath],
|
||||
const processes = readyPaths.map(readyPath => Bun.spawn({
|
||||
cmd: [bunPath, worker, rootDir, 'demo', readyPath, startPath, acquiredPath, releasePath],
|
||||
stdout: 'pipe',
|
||||
stderr: 'pipe'
|
||||
}))
|
||||
try {
|
||||
await Promise.all(readyPaths.map(waitForFile))
|
||||
await writeFile(startPath, 'start')
|
||||
await waitForFile(acquiredPath)
|
||||
const loserExitCode = await Promise.race([
|
||||
...processes.map(process => process.exited),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue