Skip to content

Commit

Permalink
address @eli comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Jun 19, 2019
1 parent 79915e5 commit a62ed69
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/server/http/http_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class HttpServer {
await this.server.start();
const serverPath = this.config!.rewriteBasePath || this.config!.basePath || '';
this.log.info('http server running');
this.log.debug(`http server listens at ${this.server.info.uri}${serverPath}`);
this.log.debug(`http server listening on ${this.server.info.uri}${serverPath}`);
}

public async stop() {
Expand Down
24 changes: 24 additions & 0 deletions src/core/server/http/http_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,30 @@ test('stops http server', async () => {
expect(httpServer.stop).toHaveBeenCalledTimes(1);
});

test('stops not ready server if it is running', async () => {
const configService = createConfigService();
const mockHapiServer = {
start: jest.fn(),
stop: jest.fn(),
route: jest.fn(),
};
const httpServer = {
isListening: () => false,
setup: jest.fn().mockReturnValue({ server: mockHapiServer }),
start: noop,
stop: jest.fn(),
};
mockHttpServer.mockImplementation(() => httpServer);

const service = new HttpService({ configService, env, logger });

await service.setup();

await service.stop();

expect(mockHapiServer.stop).toHaveBeenCalledTimes(1);
});

test('register route handler', async () => {
const configService = createConfigService();

Expand Down
6 changes: 6 additions & 0 deletions src/core/server/http/http_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export class HttpService implements CoreService<HttpServiceSetup, HttpServiceSta
const config = await this.config$.pipe(first()).toPromise();
if (this.shouldListen(config)) {
if (this.notReadyServer) {
this.log.debug('stopping NotReady server');
await this.notReadyServer.stop();
this.notReadyServer = undefined;
}
// If a redirect port is specified, we start an HTTP server at this port and
// redirect all requests to the SSL port.
Expand Down Expand Up @@ -162,13 +164,17 @@ export class HttpService implements CoreService<HttpServiceSetup, HttpServiceSta
this.configSubscription.unsubscribe();
this.configSubscription = undefined;

if (this.notReadyServer) {
await this.notReadyServer.stop();
}
await this.httpServer.stop();
await this.httpsRedirectServer.stop();
await Promise.all([...this.secondaryServers.values()].map(s => s.stop()));
this.secondaryServers.clear();
}

private async runNotReadyServer(config: HttpConfig) {
this.log.debug('starting NotReady server');
const httpServer = new HttpServer(this.log);
const { server } = await httpServer.setup(config);
this.notReadyServer = server;
Expand Down

0 comments on commit a62ed69

Please sign in to comment.