Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
thehenrytsai committed Jul 6, 2024
1 parent a759239 commit 6470a54
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
11 changes: 7 additions & 4 deletions src/dwn-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down Expand Up @@ -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) {
Expand All @@ -148,7 +151,7 @@ export class DwnServer {
});
});

unsetProcessHandlers(this.processHandlers);
removeProcessHandlers(this.processHandlers);

this.serverState = DwnServerState.Stopped;
}
Expand Down
2 changes: 1 addition & 1 deletion src/http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export class HttpApi {
/**
* Stops the HTTP API endpoint.
*/
async stop(): Promise<void> {
async close(): Promise<void> {
// promisify http.Server.close() and await on it
await new Promise<void>((resolve, reject) => {
this.#server.close((err?: Error) => {
Expand Down
3 changes: 1 addition & 2 deletions src/process-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type ProcessHandlers = {
sigtermHandler: () => Promise<void>
};


export const setProcessHandlers = (dwnServer: DwnServer): ProcessHandlers => {
const unhandledRejectionHandler = (reason: any, promise: Promise<any>): void => {
console.error(
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions src/registration/registration-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ export class RegistrationStore {

return result[0];
}

public async close(): Promise<void> {
this.db.destroy();
}
}

interface RegisteredTenants {
Expand Down
2 changes: 1 addition & 1 deletion tests/connection/connection-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
8 changes: 4 additions & 4 deletions tests/http-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('http api', function () {
});

afterEach(async function () {
await httpApi.stop();
await httpApi.close();
});

after(function () {
Expand Down Expand Up @@ -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);
Expand All @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ws-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('websocket api', function () {

afterEach(async function () {
await wsApi.close();
await httpApi.stop();
await httpApi.close();
await dwn.close();
});

Expand Down

0 comments on commit 6470a54

Please sign in to comment.