Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Dec 20, 2023
1 parent 8ec786c commit b0c3920
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
11 changes: 2 additions & 9 deletions test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
populateNockCitiesList,
} from './utils/populate-static-files.js';
import chaiOas from './plugins/oas/index.js';
import { getRedisClient, initRedisClient } from '../src/lib/redis/client.js';
import { getPersistentRedisClient, initPersistentRedisClient } from '../src/lib/redis/persistent-client.js';
import { initRedisClient } from '../src/lib/redis/client.js';
import { initPersistentRedisClient } from '../src/lib/redis/persistent-client.js';
import { client as sql } from '../src/lib/sql/client.js';

const dbConfig = config.get<{ connection: { database: string, host: string } }>('db');
Expand Down Expand Up @@ -46,13 +46,6 @@ before(async () => {
await populateNockCitiesList();
});

after(async () => {
const redisClient = getRedisClient();
await redisClient.flushDb();
const persistentRedisClient = await getPersistentRedisClient();
await persistentRedisClient.flushDb();
});

const dropAllTables = async (sql: Knex) => {
const allTables = (await sql('information_schema.tables')
.whereRaw(`table_schema = database()`)
Expand Down
20 changes: 11 additions & 9 deletions test/tests/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import { EventEmitter } from 'node:events';
import { expect } from 'chai';
import * as td from 'testdouble';
import * as sinon from 'sinon';
import { getRedisClient } from '../../../src/lib/redis/client.js';
import { getPersistentRedisClient } from '../../../src/lib/redis/persistent-client.js';
import { getRedisClient, RedisClient } from '../../../src/lib/redis/client.js';
import { getPersistentRedisClient, PersistentRedisClient } from '../../../src/lib/redis/persistent-client.js';

describe('index file', () => {
const cluster: any = new EventEmitter();
cluster.isPrimary = true;
cluster.fork = sinon.stub();
let redis: RedisClient;
let persistentRedis: PersistentRedisClient;

before(async () => {
redis = getRedisClient();
persistentRedis = getPersistentRedisClient();
});

beforeEach(async () => {
sinon.resetHistory();
Expand All @@ -18,6 +25,8 @@ describe('index file', () => {

after(() => {
td.reset();
redis.del('testfield');
persistentRedis.del('testfield');
});

it('master should restart a worker if it dies', async () => {
Expand All @@ -36,16 +45,9 @@ describe('index file', () => {
});

it('master should flush non-persistent redis db on startup', async () => {
const redis = getRedisClient();
const persistentRedis = getPersistentRedisClient();
redis.set('testfield', 'testvalue');
persistentRedis.set('testfield', 'testvalue');

const value1 = await redis.get('testfield');
const persistentValue1 = await persistentRedis.get('testfield');

expect(value1).to.equal('testvalue');
expect(persistentValue1).to.equal('testvalue');
await import('../../../src/index.js');

const value2 = await redis.get('testfield');
Expand Down

0 comments on commit b0c3920

Please sign in to comment.