mutex-lock-redis/test/mutex.test.ts

26 lines
547 B
TypeScript
Raw Permalink Normal View History

2025-01-10 00:17:29 +00:00
import { test } from "bun:test";
import { MutexLock } from "../src/MutexLock";
test(
"redis mutex",
async () => {
2025-01-10 00:20:21 +00:00
const mutexLock = await MutexLock.create();
2025-01-10 00:17:29 +00:00
const testLock = async () => {
const release = await mutexLock.obtainLock("test");
console.log("got lock");
try {
await new Promise((res) => setTimeout(res, 3000));
} finally {
await release();
console.log("released lock");
}
};
await Promise.all([testLock(), testLock(), testLock(), testLock()]);
},
{
timeout: Number.POSITIVE_INFINITY,
},
);