Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: shutdown hook configuration is using wrong config key #1621

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ export class ApiServer {
throw new Error(`ApiServer#ctor options.config was falsy`);
}

this.enableShutdownHook = Bools.isBooleanStrict(options.enableShutdownHook)
? (options.enableShutdownHook as boolean)
this.enableShutdownHook = Bools.isBooleanStrict(
options.config.enableShutdownHook,
)
? (options.config.enableShutdownHook as boolean)
: true;

if (this.enableShutdownHook) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import "jest-extended";
import {
ApiServer,
// AuthorizationProtocol,
ConfigService,
} from "../../../../main/typescript/public-api";

describe("api-server shutdown-hook configuration tests", () => {
// create a config service as base for the following UTs
const configService = new ConfigService();

it("enables the shutdown hook based on schema-default", async () => {
const expectedResult = true;
const apiServerOptions = await configService.newExampleConfig();
apiServerOptions.configFile = "";

const config = await configService.newExampleConfigConvict(
apiServerOptions,
);

const apiServer = new ApiServer({
config: config.getProperties(),
});

// check apiServerOptions
expect(apiServerOptions).not.toBeUndefined();
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult);

// check apiServer
expect(apiServer).toBeTruthy();
const result = apiServer["enableShutdownHook"];
expect(result).toBe(expectedResult);
});

it("disables the shutdown hook based on the config value set to false", async () => {
const expectedResult = false;
const apiServerOptions = await configService.newExampleConfig();

// disable shutdown hook
apiServerOptions.enableShutdownHook = false;
apiServerOptions.configFile = "";

const config = await configService.newExampleConfigConvict(
apiServerOptions,
true,
);

const apiServer = new ApiServer({
config: config.getProperties(),
});

// check apiServerOptions
expect(apiServerOptions).not.toBeUndefined();
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult);

// check apiServer
expect(apiServer).toBeTruthy();
const result = apiServer["enableShutdownHook"];
expect(result).toBe(expectedResult);
});

it("enables the shutdown hook based on the config value set to true", async () => {
const expectedResult = true;
const apiServerOptions = await configService.newExampleConfig();

// disable shutdown hook
apiServerOptions.enableShutdownHook = true;
apiServerOptions.configFile = "";

const config = await configService.newExampleConfigConvict(
apiServerOptions,
true,
);

const apiServer = new ApiServer({
config: config.getProperties(),
});

// check apiServerOptions
expect(apiServerOptions).not.toBeUndefined();
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult);

// check apiServer
expect(apiServer).toBeTruthy();
const result = apiServer["enableShutdownHook"];
expect(result).toBe(expectedResult);
});
});