import { describe, it, beforeEach } from "mocha"; import { expect } from "chai"; import FeatureConfigFake from "../fake/FeatureConfigFake"; import { FeatureConfigService } from "../../../src/services/FeatureConfig.service"; import { RedisService, RedisClient } from "../../../src/services/redis.service"; describe("RedisService", function () { const featureConfigService = FeatureConfigService.getInstance(); const mockedFeatureConf: FeatureConfigFake = new FeatureConfigFake(); featureConfigService.setFeatureConfig(mockedFeatureConf); let redisClient: RedisClient; before(async () => { redisClient = RedisService.getClient("mockedClient", false) as any; }); after(async () => { redisClient.disconnect(); }); it("setting and getting a key should be consistent", async function () { await redisClient.setPX("myKey", "myValue", 3600000); const result = await redisClient.get("myKey"); expect(result).to.equal("myValue"); const ttl = await redisClient.client.pttl("myKey"); expect(ttl).to.be.lte(3600000); expect(ttl).to.be.gt(3599000); }); it("only one lock at the same time", async function () { const lock = await redisClient.getRedisLock("myLock", 5000); expect(lock).to.not.be.undefined; let lockbis = await redisClient.getRedisLock("myLock", 5000); expect(lockbis).to.be.undefined; const lock2 = await redisClient.getRedisLock("myLock2", 5000); expect(lock2).to.not.be.undefined; await lock!.unlock(); lockbis = await redisClient.getRedisLock("myLock", 5000); expect(lockbis).to.not.be.undefined; await lockbis!.unlock(); await lock2!.unlock(); }); });