mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
Merge pull request #15986 from mag123c/fix/shutdown-hooks-process-exit
feat(core): add option for async logger compatibility
This commit is contained in:
@@ -51,4 +51,21 @@ describe('enableShutdownHooks', () => {
|
||||
expect(result.stdout.toString().trim()).to.be.eq('');
|
||||
done();
|
||||
}).timeout(10000);
|
||||
|
||||
it('should call the correct hooks with useProcessExit option', done => {
|
||||
const result = spawnSync('ts-node', [
|
||||
join(__dirname, '../src/enable-shutdown-hooks-main.ts'),
|
||||
'SIGHUP',
|
||||
'SIGHUP',
|
||||
'graceful',
|
||||
]);
|
||||
const calls = result.stdout
|
||||
.toString()
|
||||
.split('\n')
|
||||
.map((call: string) => call.trim());
|
||||
expect(calls[0]).to.equal('beforeApplicationShutdown SIGHUP');
|
||||
expect(calls[1]).to.equal('onApplicationShutdown SIGHUP');
|
||||
expect(result.status).to.equal(0);
|
||||
done();
|
||||
}).timeout(10000);
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
const SIGNAL = process.argv[2];
|
||||
const SIGNAL_TO_LISTEN = process.argv[3];
|
||||
const USE_GRACEFUL_EXIT = process.argv[4] === 'graceful';
|
||||
|
||||
@Injectable()
|
||||
class TestInjectable
|
||||
@@ -29,10 +30,12 @@ class AppModule {}
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, { logger: false });
|
||||
|
||||
const shutdownOptions = USE_GRACEFUL_EXIT ? { useProcessExit: true } : {};
|
||||
|
||||
if (SIGNAL_TO_LISTEN && SIGNAL_TO_LISTEN !== 'NONE') {
|
||||
app.enableShutdownHooks([SIGNAL_TO_LISTEN]);
|
||||
app.enableShutdownHooks([SIGNAL_TO_LISTEN], shutdownOptions);
|
||||
} else if (SIGNAL_TO_LISTEN !== 'NONE') {
|
||||
app.enableShutdownHooks();
|
||||
app.enableShutdownHooks([], shutdownOptions);
|
||||
}
|
||||
|
||||
await app.listen(1800);
|
||||
|
||||
Reference in New Issue
Block a user