diff --git a/src/dwn-server.ts b/src/dwn-server.ts index 642dfb2..c4ad608 100644 --- a/src/dwn-server.ts +++ b/src/dwn-server.ts @@ -14,7 +14,7 @@ import { HttpApi } from './http-api.js'; import { RegistrationManager } from './registration/registration-manager.js'; import { WsApi } from './ws-api.js'; import { Dwn, EventEmitterStream } from '@tbd54566975/dwn-sdk-js'; -import { setProcessHandlers, unsetProcessHandlers } from './process-handlers.js'; +import { removeProcessHandlers, setProcessHandlers } from './process-handlers.js'; /** * Options for the DwnServer constructor. @@ -31,7 +31,10 @@ export type DwnServerOptions = { config?: DwnServerConfig; }; -export enum DwnServerState { +/** + * State of the DwnServer, either Stopped or Started, to help short-circuit start and stop logic. + */ +enum DwnServerState { Stopped, Started } @@ -135,7 +138,7 @@ export class DwnServer { } await this.dwn.close(); - await this.#httpApi.stop(); + await this.#httpApi.close(); // close WebSocket server if it was initialized if (this.#wsApi !== undefined) { @@ -148,7 +151,7 @@ export class DwnServer { }); }); - unsetProcessHandlers(this.processHandlers); + removeProcessHandlers(this.processHandlers); this.serverState = DwnServerState.Stopped; } diff --git a/src/http-api.ts b/src/http-api.ts index 5b7d829..f5c682d 100644 --- a/src/http-api.ts +++ b/src/http-api.ts @@ -470,7 +470,7 @@ export class HttpApi { /** * Stops the HTTP API endpoint. */ - async stop(): Promise { + async close(): Promise { // promisify http.Server.close() and await on it await new Promise((resolve, reject) => { this.#server.close((err?: Error) => { diff --git a/src/process-handlers.ts b/src/process-handlers.ts index b9de6e6..554fcaf 100644 --- a/src/process-handlers.ts +++ b/src/process-handlers.ts @@ -13,7 +13,6 @@ export type ProcessHandlers = { sigtermHandler: () => Promise }; - export const setProcessHandlers = (dwnServer: DwnServer): ProcessHandlers => { const unhandledRejectionHandler = (reason: any, promise: Promise): void => { console.error( @@ -51,7 +50,7 @@ export const setProcessHandlers = (dwnServer: DwnServer): ProcessHandlers => { }; }; -export const unsetProcessHandlers = (handlers: ProcessHandlers): void => { +export const removeProcessHandlers = (handlers: ProcessHandlers): void => { const { unhandledRejectionHandler, uncaughtExceptionHandler, diff --git a/src/registration/registration-store.ts b/src/registration/registration-store.ts index 197c38b..f4d8159 100644 --- a/src/registration/registration-store.ts +++ b/src/registration/registration-store.ts @@ -67,10 +67,6 @@ export class RegistrationStore { return result[0]; } - - public async close(): Promise { - this.db.destroy(); - } } interface RegisteredTenants { diff --git a/tests/connection/connection-manager.spec.ts b/tests/connection/connection-manager.spec.ts index 9e62932..616f7ee 100644 --- a/tests/connection/connection-manager.spec.ts +++ b/tests/connection/connection-manager.spec.ts @@ -31,7 +31,7 @@ describe('InMemoryConnectionManager', () => { afterEach(async () => { await connectionManager.closeAll(); await dwn.close(); - await httpApi.stop(); + await httpApi.close(); await wsApi.close(); sinon.restore(); }); diff --git a/tests/http-api.spec.ts b/tests/http-api.spec.ts index ced0e1e..2d938f4 100644 --- a/tests/http-api.spec.ts +++ b/tests/http-api.spec.ts @@ -81,7 +81,7 @@ describe('http api', function () { }); afterEach(async function () { - await httpApi.stop(); + await httpApi.close(); }); after(function () { @@ -1057,7 +1057,7 @@ describe('http api', function () { // start server without websocket support enabled - await httpApi.stop(); + await httpApi.close(); config.webSocketSupport = false; httpApi = await HttpApi.create(config, dwn, registrationManager); @@ -1075,7 +1075,7 @@ describe('http api', function () { }); it('verify /info still returns when package.json file does not exist', async function () { - await httpApi.stop(); + await httpApi.close(); // set up spy to check for an error log by the server const logSpy = sinon.spy(log, 'error'); @@ -1106,7 +1106,7 @@ describe('http api', function () { }); it('verify /info returns server name from config', async function () { - await httpApi.stop(); + await httpApi.close(); // set a custom name for the `serverName` const serverName = config.serverName; diff --git a/tests/ws-api.spec.ts b/tests/ws-api.spec.ts index 5ea4b8f..19251b0 100644 --- a/tests/ws-api.spec.ts +++ b/tests/ws-api.spec.ts @@ -45,7 +45,7 @@ describe('websocket api', function () { afterEach(async function () { await wsApi.close(); - await httpApi.stop(); + await httpApi.close(); await dwn.close(); });