Skip to content

Commit

Permalink
Pass default values to start server
Browse files Browse the repository at this point in the history
Signed-off-by: Zabil Cheriya Maliackal <zabilcm@gmail.com>
  • Loading branch information
zabil committed Jun 5, 2024
1 parent 7a1d964 commit a107bc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/GaugeRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import RunnerServer from "./RunnerServer";
import { RunnerService } from "./gen/services_grpc_pb";
import StaticLoader from "./loaders/StaticLoader";

let server: Server | null = null;
let serverInstance: Server | null = null;

export const start = (host = "127.0.0.1:0", loader = new StaticLoader()) => {
if (server) {
console.log("Server is already running.");
throw new Error("Server is already running.");
}
server = new Server();
server.addService(RunnerService, new RunnerServer(loader));
export const start = (
host = "127.0.0.1:0",
server = new Server(),
runnerServer = new RunnerServer(new StaticLoader()),
) => {
serverInstance = server;
server.addService(RunnerService, runnerServer);
let port: number | null = null;
server.bindAsync(
host,
Expand All @@ -27,16 +27,16 @@ export const start = (host = "127.0.0.1:0", loader = new StaticLoader()) => {
);
};

export const stop = (): void => {
if (!server) {
export const stop = (server = serverInstance): void => {
if (!serverInstance) {
console.debug("Server is not running.");
return;
}
server.tryShutdown((err) => {
server?.tryShutdown((err) => {
if (err) {
console.error("Error shutting down the server:", err);
} else {
server = null;
serverInstance = null;
}
});
};
3 changes: 2 additions & 1 deletion tests/RunnerServerTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as grpc from "@grpc/grpc-js";
import type { ServerErrorResponse } from "@grpc/grpc-js/build/src/server-call";
import { mockProcessExit } from "jest-mock-process";
import { start, stop } from "../src/GaugeRuntime";
import RunnerServer from "../src/RunnerServer";
import {
CacheFileRequest as CFReq,
type ExecutionStatusResponse as ESR,
Expand Down Expand Up @@ -70,7 +71,7 @@ describe("RunnerServer", () => {
beforeAll(() => {
loader = new StaticLoader();
jest.spyOn(loader, "loadImplementations").mockImplementation();
start(host, loader);
start(host, new Server(), new RunnerServer(loader));
client = new RunnerClient(host, grpc.credentials.createInsecure());
});

Expand Down

0 comments on commit a107bc0

Please sign in to comment.