Skip to content

Commit

Permalink
test(core): move error-releases-lock test
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Jan 12, 2024
1 parent ed67e6a commit 7a3ce7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
28 changes: 26 additions & 2 deletions core/api/test/integration/services/lock-service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { sleep } from "@/utils"
import { LockService } from "@/services/lock"
import { Redis } from "ioredis"

import { ResourceAttemptsRedlockServiceError } from "@/domain/lock"

import { LockService } from "@/services/lock"
import { redis } from "@/services/redis"

import { sleep } from "@/utils"

import { randomWalletId } from "test/helpers"

const lockService = LockService()
Expand Down Expand Up @@ -65,5 +70,24 @@ describe("LockService", () => {

expect(order).toStrictEqual([1, 2, 3, 4])
})

it("releases the lock when error is thrown", async () => {
const walletId = randomWalletId()

const checkLockExist = (client: Redis) =>
new Promise((resolve) =>
client.get(walletId, (err, res) => {
resolve(!!res)
}),
)

await lockService.lockWalletId(walletId, async () => {
expect(await checkLockExist(redis)).toBeTruthy()
await sleep(500)
throw Error("dummy error")
})

expect(await checkLockExist(redis)).toBeFalsy()
})
})
})
36 changes: 0 additions & 36 deletions core/api/test/legacy-integration/services/lock.spec.ts

This file was deleted.

0 comments on commit 7a3ce7b

Please sign in to comment.