mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 21:47:57 +08:00
test: fix ECONNREFUSED
This commit is contained in:
@@ -18,37 +18,54 @@ afterAll(() => {
|
||||
delete process.env.CACHE_EXPIRE;
|
||||
});
|
||||
|
||||
async function check(type) {
|
||||
process.env.CACHE_TYPE = type;
|
||||
server = require('../../lib/index').server;
|
||||
const request = supertest(server);
|
||||
|
||||
const response1 = await request.get('/test/1');
|
||||
const parsed1 = await parser.parseString(response1.text);
|
||||
|
||||
const response2 = await request.get('/test/1');
|
||||
const parsed2 = await parser.parseString(response2.text);
|
||||
|
||||
delete parsed1.lastBuildDate;
|
||||
delete parsed2.lastBuildDate;
|
||||
expect(parsed2).toMatchObject(parsed1);
|
||||
|
||||
expect(response2.status).toBe(200);
|
||||
expect(response2.headers[`x-koa-${type}-cache`]).toBe('true');
|
||||
expect(response3.headers).not.toHaveProperty(`x-koa-${type === 'redis' ? 'memory' : 'redis'}-cache`);
|
||||
|
||||
await wait(1 * 1000 + 10);
|
||||
const response3 = await request.get('/test/1');
|
||||
expect(response3.headers).not.toHaveProperty('x-koa-redis-cache');
|
||||
expect(response3.headers).not.toHaveProperty('x-koa-memory-cache');
|
||||
}
|
||||
|
||||
describe('cache', () => {
|
||||
it('memory', async () => {
|
||||
check('memory');
|
||||
process.env.CACHE_TYPE = 'memory';
|
||||
server = require('../../lib/index').server;
|
||||
const request = supertest(server);
|
||||
|
||||
const response1 = await request.get('/test/1');
|
||||
const parsed1 = await parser.parseString(response1.text);
|
||||
|
||||
const response2 = await request.get('/test/1');
|
||||
const parsed2 = await parser.parseString(response2.text);
|
||||
|
||||
delete parsed1.lastBuildDate;
|
||||
delete parsed2.lastBuildDate;
|
||||
expect(parsed2).toMatchObject(parsed1);
|
||||
|
||||
expect(response2.status).toBe(200);
|
||||
expect(response2.headers['x-koa-memory-cache']).toBe('true');
|
||||
expect(response2.headers).not.toHaveProperty('x-koa-redis-cache');
|
||||
|
||||
await wait(1 * 1000 + 10);
|
||||
const response3 = await request.get('/test/1');
|
||||
expect(response3.headers).not.toHaveProperty('x-koa-redis-cache');
|
||||
expect(response3.headers).not.toHaveProperty('x-koa-memory-cache');
|
||||
});
|
||||
|
||||
it('redis', async () => {
|
||||
check('redis');
|
||||
process.env.CACHE_TYPE = 'redis';
|
||||
server = require('../../lib/index').server;
|
||||
const request = supertest(server);
|
||||
|
||||
const response1 = await request.get('/test/1');
|
||||
const parsed1 = await parser.parseString(response1.text);
|
||||
|
||||
const response2 = await request.get('/test/1');
|
||||
const parsed2 = await parser.parseString(response2.text);
|
||||
|
||||
delete parsed1.lastBuildDate;
|
||||
delete parsed2.lastBuildDate;
|
||||
expect(parsed2).toMatchObject(parsed1);
|
||||
|
||||
expect(response2.status).toBe(200);
|
||||
expect(response2.headers['x-koa-redis-cache']).toBe('true');
|
||||
expect(response2.headers).not.toHaveProperty('x-koa-memory-cache');
|
||||
|
||||
await wait(1 * 1000 + 10);
|
||||
const response3 = await request.get('/test/1');
|
||||
expect(response3.headers).not.toHaveProperty('x-koa-redis-cache');
|
||||
expect(response3.headers).not.toHaveProperty('x-koa-memory-cache');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user