From 827ca4b26f283b37db4eba6676bbc54c55727bf2 Mon Sep 17 00:00:00 2001 From: Doody Parizada Date: Tue, 23 Jul 2019 18:17:52 +0300 Subject: [PATCH] use non mocking redis --- docker-compose.deps.yaml | 2 +- scripts/src/tests/utils.spec.ts | 20 +++++++++++++++++++- tests/config.json | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docker-compose.deps.yaml b/docker-compose.deps.yaml index d8983c50..c36a8c8f 100644 --- a/docker-compose.deps.yaml +++ b/docker-compose.deps.yaml @@ -94,7 +94,7 @@ services: redis: image: redis:4.0 ports: - - 6379 + - 26379:6379 jwt-service: image: kinecosystem/jwt-service:1eaf6e5 diff --git a/scripts/src/tests/utils.spec.ts b/scripts/src/tests/utils.spec.ts index 1860d562..94fa1d8b 100644 --- a/scripts/src/tests/utils.spec.ts +++ b/scripts/src/tests/utils.spec.ts @@ -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 () => { @@ -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)]); + }); }); diff --git a/tests/config.json b/tests/config.json index 203e9604..7cd017c7 100644 --- a/tests/config.json +++ b/tests/config.json @@ -18,7 +18,7 @@ "synchronize": true, "logging": false }, - "redis": "mock", + "redis": "redis://localhost:26379/0", "statsd": { "host": "localhost", "port": 8125