mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-23 21:53:09 +02:00
ランダムにテストがコケるのを修正 (#7553)
* Test shutdown * Revert "Test shutdown" This reverts commit 85182e7dd196cdd9ecb46cfb50adaabd04c5ba60. * Skip beforeShutdown in test * Wait shutdown in test * Revert "Skip beforeShutdown in test" This reverts commit 79c33ab53615e8fa4820d2abfc2494cba55c441c. * Revert "Revert "Skip beforeShutdown in test"" This reverts commit 3423133a137c79b64f3ff6ef9dbe433a441a47b0.
This commit is contained in:
parent
a5cdc9a1f4
commit
5d66bb8794
7 changed files with 34 additions and 15 deletions
|
@ -56,6 +56,8 @@ const forceExitAfter = timeout => () => {
|
||||||
* @param {string} signalOrEvent The exit signal or event name received on the process.
|
* @param {string} signalOrEvent The exit signal or event name received on the process.
|
||||||
*/
|
*/
|
||||||
async function shutdownHandler(signalOrEvent) {
|
async function shutdownHandler(signalOrEvent) {
|
||||||
|
if (process.env.NODE_ENV === 'test') return process.exit(0);
|
||||||
|
|
||||||
console.warn(`Shutting down: received [${signalOrEvent}] signal`);
|
console.warn(`Shutting down: received [${signalOrEvent}] signal`);
|
||||||
|
|
||||||
for (const listener of shutdownListeners) {
|
for (const listener of shutdownListeners) {
|
||||||
|
|
|
@ -12,15 +12,15 @@ process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { async, signup, request, post, launchServer } from './utils';
|
import { async, signup, request, post, launchServer, shutdownServer } from './utils';
|
||||||
|
|
||||||
describe('API visibility', () => {
|
describe('API visibility', () => {
|
||||||
let p: childProcess.ChildProcess;
|
let p: childProcess.ChildProcess;
|
||||||
|
|
||||||
before(launchServer(g => p = g));
|
before(launchServer(g => p = g));
|
||||||
|
|
||||||
after(() => {
|
after(async () => {
|
||||||
p.kill();
|
await shutdownServer(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Note visibility', async () => {
|
describe('Note visibility', async () => {
|
||||||
|
|
|
@ -12,7 +12,7 @@ process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { async, launchServer, signup, post, request, simpleGet, port } from './utils';
|
import { async, launchServer, signup, post, request, simpleGet, port, shutdownServer } from './utils';
|
||||||
import * as openapi from '@redocly/openapi-core';
|
import * as openapi from '@redocly/openapi-core';
|
||||||
|
|
||||||
// Request Accept
|
// Request Accept
|
||||||
|
@ -39,8 +39,8 @@ describe('Fetch resource', () => {
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
after(() => {
|
after(async () => {
|
||||||
p.kill();
|
await shutdownServer(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Common', () => {
|
describe('Common', () => {
|
||||||
|
|
|
@ -12,7 +12,7 @@ process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { async, signup, request, post, react, connectStream, launchServer } from './utils';
|
import { async, signup, request, post, react, connectStream, launchServer, shutdownServer } from './utils';
|
||||||
|
|
||||||
describe('Mute', () => {
|
describe('Mute', () => {
|
||||||
let p: childProcess.ChildProcess;
|
let p: childProcess.ChildProcess;
|
||||||
|
@ -28,8 +28,8 @@ describe('Mute', () => {
|
||||||
carol = await signup({ username: 'carol' });
|
carol = await signup({ username: 'carol' });
|
||||||
}));
|
}));
|
||||||
|
|
||||||
after(() => {
|
after(async () => {
|
||||||
p.kill();
|
await shutdownServer(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ミュート作成', async(async () => {
|
it('ミュート作成', async(async () => {
|
||||||
|
|
|
@ -12,7 +12,7 @@ process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { async, signup, request, post, uploadFile, launchServer } from './utils';
|
import { async, signup, request, post, uploadFile, launchServer, shutdownServer } from './utils';
|
||||||
import { Note } from '../src/models/entities/note';
|
import { Note } from '../src/models/entities/note';
|
||||||
import { initDb } from '../src/db/postgre';
|
import { initDb } from '../src/db/postgre';
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ describe('Note', () => {
|
||||||
bob = await signup({ username: 'bob' });
|
bob = await signup({ username: 'bob' });
|
||||||
}));
|
}));
|
||||||
|
|
||||||
after(() => {
|
after(async () => {
|
||||||
p.kill();
|
await shutdownServer(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('投稿できる', async(async () => {
|
it('投稿できる', async(async () => {
|
||||||
|
|
|
@ -12,7 +12,7 @@ process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { async, signup, request, post, uploadFile, launchServer } from './utils';
|
import { async, signup, request, post, uploadFile, launchServer, shutdownServer } from './utils';
|
||||||
|
|
||||||
describe('users/notes', () => {
|
describe('users/notes', () => {
|
||||||
let p: childProcess.ChildProcess;
|
let p: childProcess.ChildProcess;
|
||||||
|
@ -37,8 +37,8 @@ describe('users/notes', () => {
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
after(() => {
|
after(async() => {
|
||||||
p.kill();
|
await shutdownServer(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ファイルタイプ指定 (jpg)', async(async () => {
|
it('ファイルタイプ指定 (jpg)', async(async () => {
|
||||||
|
|
|
@ -5,6 +5,7 @@ const FormData = require('form-data');
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import loadConfig from '../src/config/load';
|
import loadConfig from '../src/config/load';
|
||||||
|
import { SIGKILL } from 'constants';
|
||||||
|
|
||||||
export const port = loadConfig().port;
|
export const port = loadConfig().port;
|
||||||
|
|
||||||
|
@ -145,3 +146,19 @@ export function launchServer(callbackSpawnedProcess: (p: childProcess.ChildProce
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shutdownServer(p: childProcess.ChildProcess, timeout = 20 * 1000) {
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
const t = setTimeout(() => {
|
||||||
|
p.kill(SIGKILL);
|
||||||
|
res('force exit');
|
||||||
|
}, timeout);
|
||||||
|
|
||||||
|
p.once('exit', () => {
|
||||||
|
clearTimeout(t);
|
||||||
|
res('exited');
|
||||||
|
});
|
||||||
|
|
||||||
|
p.kill();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue