Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

use non mocking redis #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ services:
redis:
image: redis:4.0
ports:
- 6379
- 26379:6379

jwt-service:
image: kinecosystem/jwt-service:1eaf6e5
Expand Down
20 changes: 19 additions & 1 deletion scripts/src/tests/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { localCache } from "../utils/cache";
import { AuthToken, WalletApplication } from "../models/users";
import mock = require("supertest");
import { withinMigrationRateLimit } from "../utils/migration";
import { getRedisClient } from "../redis";
import { getRedisClient, lock } from "../redis";

describe("util functions", () => {
test("cached decorator", async () => {
Expand Down Expand Up @@ -275,4 +275,22 @@ describe("util functions", () => {
.set("Authorization", `Bearer ${ token2.id }`)
.expect(res => res.status < 300);
});

test("lock function", async () => {
let num = 0;

async function f() {
num += 1;
if (num === 2) {
throw new Error("shouldn't reach 2");
}
await delay(500);
num -= 1;
}

const resource = `uniq:${ generateId() }`;
await Promise.all([
lock(resource, f),
lock(resource, f)]);
Copy link
Contributor

@liorama liorama Jul 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if the delay is 500ms and the RedLock config is set to 10 retries with 200ms wait between them that means that the resource will be unlocked before all retries have been exhausted and the second call to f will be done and num increased to 2. Right?

});
});
2 changes: 1 addition & 1 deletion tests/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"synchronize": true,
"logging": false
},
"redis": "mock",
"redis": "redis://localhost:26379/0",
"statsd": {
"host": "localhost",
"port": 8125
Expand Down