18 lines
618 B
TypeScript
18 lines
618 B
TypeScript
|
|
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);
|
|||
|
|
});
|
|||
|
|
});
|