18 lines
618 B
TypeScript
Raw Normal View History

2026-05-20 21:39:12 +08:00
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { acquireRuntimeLock, readRuntimeLock, releaseRuntimeLock } from '../../src/comm/runtime-lock';
describe('runtime lock', () => {
it('写入当前 pid并在释放时删除锁文件', () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'neta-lock-'));
const lockPath = path.join(tempDir, 'neta.lock');
acquireRuntimeLock(lockPath);
expect(readRuntimeLock(lockPath).pid).toBe(process.pid);
releaseRuntimeLock(lockPath);
expect(fs.existsSync(lockPath)).toBe(false);
});
});