From 1581da458d449b10495625bd250ce148cc98eef9 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 5 Apr 2023 10:11:27 -0400 Subject: [PATCH] chore: Move disconnecting cluster connections to own runnable Signed-off-by: Sebastian Malton --- ...ing-the-app-using-application-menu.test.ts | 10 -------- packages/core/src/main/cluster/manager.ts | 8 ------ ...-cluster-connections-on-quit.injectable.ts | 24 ++++++++++++++++++ .../stop-cluster-manager.injectable.ts | 25 ------------------- .../stop-services-and-exit-app.injectable.ts | 3 --- 5 files changed, 24 insertions(+), 46 deletions(-) create mode 100644 packages/core/src/main/cluster/stop-cluster-connections-on-quit.injectable.ts delete mode 100644 packages/core/src/main/start-main-application/runnables/stop-cluster-manager.injectable.ts diff --git a/packages/core/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts b/packages/core/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts index 5b78d9cceb..3827226bb9 100644 --- a/packages/core/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts +++ b/packages/core/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts @@ -5,16 +5,13 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; -import type { ClusterManager } from "../../main/cluster/manager"; import forceAppExitInjectable from "../../main/electron-app/features/force-app-exit.injectable"; -import clusterManagerInjectable from "../../main/cluster/manager.injectable"; import stopServicesAndExitAppInjectable from "../../main/stop-services-and-exit-app.injectable"; import { testUsingFakeTime, advanceFakeTime } from "../../test-utils/use-fake-time"; describe("quitting the app using application menu", () => { describe("given application has started", () => { let builder: ApplicationBuilder; - let clusterManagerStub: ClusterManager; let forceAppExitMock: jest.Mock; beforeEach(async () => { @@ -25,9 +22,6 @@ describe("quitting the app using application menu", () => { builder.beforeApplicationStart(({ mainDi }) => { mainDi.unoverride(stopServicesAndExitAppInjectable); - clusterManagerStub = { stop: jest.fn() } as unknown as ClusterManager; - mainDi.override(clusterManagerInjectable, () => clusterManagerStub); - forceAppExitMock = jest.fn(); mainDi.override(forceAppExitInjectable, () => forceAppExitMock); }); @@ -52,10 +46,6 @@ describe("quitting the app using application menu", () => { expect(windows).toEqual([]); }); - it("disconnects all clusters", () => { - expect(clusterManagerStub.stop).toHaveBeenCalled(); - }); - it("after insufficient time passes, does not terminate application yet", () => { advanceFakeTime(999); diff --git a/packages/core/src/main/cluster/manager.ts b/packages/core/src/main/cluster/manager.ts index 800f981372..f52050ffa4 100644 --- a/packages/core/src/main/cluster/manager.ts +++ b/packages/core/src/main/cluster/manager.ts @@ -226,14 +226,6 @@ export class ClusterManager { )), ); }; - - stop() { - for (const cluster of this.dependencies.clusters.get()) { - this.dependencies - .getClusterConnection(cluster) - .disconnect(); - } - } } export function catalogEntityFromCluster(cluster: Cluster) { diff --git a/packages/core/src/main/cluster/stop-cluster-connections-on-quit.injectable.ts b/packages/core/src/main/cluster/stop-cluster-connections-on-quit.injectable.ts new file mode 100644 index 0000000000..651e38e8ff --- /dev/null +++ b/packages/core/src/main/cluster/stop-cluster-connections-on-quit.injectable.ts @@ -0,0 +1,24 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getInjectable } from "@ogre-tools/injectable"; +import clustersInjectable from "../../features/cluster/storage/common/clusters.injectable"; +import { onQuitOfBackEndInjectionToken } from "../start-main-application/runnable-tokens/phases"; +import clusterConnectionInjectable from "./cluster-connection.injectable"; + +const stopAllClusterConnectionsOnQuitInjectable = getInjectable({ + id: "stop-all-cluster-connections-on-quit", + instantiate: (di) => ({ + run: () => { + const clusters = di.inject(clustersInjectable).get(); + + for (const cluster of clusters) { + di.inject(clusterConnectionInjectable, cluster).disconnect(); + } + }, + }), + injectionToken: onQuitOfBackEndInjectionToken, +}); + +export default stopAllClusterConnectionsOnQuitInjectable; diff --git a/packages/core/src/main/start-main-application/runnables/stop-cluster-manager.injectable.ts b/packages/core/src/main/start-main-application/runnables/stop-cluster-manager.injectable.ts deleted file mode 100644 index 5d322836f3..0000000000 --- a/packages/core/src/main/start-main-application/runnables/stop-cluster-manager.injectable.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ -import { getInjectable } from "@ogre-tools/injectable"; -import clusterManagerInjectable from "../../cluster/manager.injectable"; -import { afterQuitOfFrontEndInjectionToken } from "../runnable-tokens/phases"; - -const stopClusterManagerInjectable = getInjectable({ - id: "stop-cluster-manager", - - instantiate: (di) => ({ - run: () => { - const clusterManager = di.inject(clusterManagerInjectable); - - clusterManager.stop(); - - return undefined; - }, - }), - - injectionToken: afterQuitOfFrontEndInjectionToken, -}); - -export default stopClusterManagerInjectable; diff --git a/packages/core/src/main/stop-services-and-exit-app.injectable.ts b/packages/core/src/main/stop-services-and-exit-app.injectable.ts index 0546fcaf0e..56f4544113 100644 --- a/packages/core/src/main/stop-services-and-exit-app.injectable.ts +++ b/packages/core/src/main/stop-services-and-exit-app.injectable.ts @@ -4,7 +4,6 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import forceAppExitInjectable from "./electron-app/features/force-app-exit.injectable"; -import clusterManagerInjectable from "./cluster/manager.injectable"; import loggerInjectable from "../common/logger.injectable"; import emitAppEventInjectable from "../common/app-event-bus/emit-event.injectable"; @@ -13,13 +12,11 @@ const stopServicesAndExitAppInjectable = getInjectable({ instantiate: (di) => { const forceAppExit = di.inject(forceAppExitInjectable); - const clusterManager = di.inject(clusterManagerInjectable); const logger = di.inject(loggerInjectable); const emitAppEvent = di.inject(emitAppEventInjectable); return async () => { emitAppEvent({ name: "service", action: "close" }); - clusterManager.stop(); logger.info("SERVICE:QUIT"); setTimeout(forceAppExit, 1000); };