mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
* chore: Replace redlock with a single-node Redis lock * fix: Handle lost SET replies, late replies and stalled extensions in MutexLock
42 lines
918 B
TypeScript
42 lines
918 B
TypeScript
import { vi } from "vitest";
|
|
|
|
export class MutexLock {
|
|
// Default expiry time for acquiring lock in milliseconds
|
|
public static defaultLockTimeout = 4000;
|
|
|
|
/**
|
|
* Acquires a mock lock.
|
|
*/
|
|
public static acquire = vi.fn().mockResolvedValue({
|
|
release: vi.fn().mockResolvedValue(true),
|
|
expiration: Date.now() + 10000,
|
|
});
|
|
|
|
/**
|
|
* Runs the routine without a lock.
|
|
*/
|
|
public static using = vi.fn(
|
|
(
|
|
_resource: string,
|
|
_timeout: number,
|
|
routine: (signal: AbortSignal) => unknown
|
|
) => routine(new AbortController().signal)
|
|
);
|
|
|
|
/**
|
|
* Runs the routine without a lock.
|
|
*/
|
|
public static tryUsing = vi.fn(
|
|
(
|
|
_resource: string,
|
|
_timeout: number,
|
|
routine: (signal: AbortSignal) => unknown
|
|
) => routine(new AbortController().signal)
|
|
);
|
|
|
|
/**
|
|
* Releases a mock lock.
|
|
*/
|
|
public static release = vi.fn().mockResolvedValue(true);
|
|
}
|