1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

chore: Move disconnecting cluster connections to own runnable

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-04-05 10:11:27 -04:00
parent 980b054fad
commit 1581da458d
5 changed files with 24 additions and 46 deletions

View File

@ -5,16 +5,13 @@
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } 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 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 stopServicesAndExitAppInjectable from "../../main/stop-services-and-exit-app.injectable";
import { testUsingFakeTime, advanceFakeTime } from "../../test-utils/use-fake-time"; import { testUsingFakeTime, advanceFakeTime } from "../../test-utils/use-fake-time";
describe("quitting the app using application menu", () => { describe("quitting the app using application menu", () => {
describe("given application has started", () => { describe("given application has started", () => {
let builder: ApplicationBuilder; let builder: ApplicationBuilder;
let clusterManagerStub: ClusterManager;
let forceAppExitMock: jest.Mock; let forceAppExitMock: jest.Mock;
beforeEach(async () => { beforeEach(async () => {
@ -25,9 +22,6 @@ describe("quitting the app using application menu", () => {
builder.beforeApplicationStart(({ mainDi }) => { builder.beforeApplicationStart(({ mainDi }) => {
mainDi.unoverride(stopServicesAndExitAppInjectable); mainDi.unoverride(stopServicesAndExitAppInjectable);
clusterManagerStub = { stop: jest.fn() } as unknown as ClusterManager;
mainDi.override(clusterManagerInjectable, () => clusterManagerStub);
forceAppExitMock = jest.fn(); forceAppExitMock = jest.fn();
mainDi.override(forceAppExitInjectable, () => forceAppExitMock); mainDi.override(forceAppExitInjectable, () => forceAppExitMock);
}); });
@ -52,10 +46,6 @@ describe("quitting the app using application menu", () => {
expect(windows).toEqual([]); expect(windows).toEqual([]);
}); });
it("disconnects all clusters", () => {
expect(clusterManagerStub.stop).toHaveBeenCalled();
});
it("after insufficient time passes, does not terminate application yet", () => { it("after insufficient time passes, does not terminate application yet", () => {
advanceFakeTime(999); advanceFakeTime(999);

View File

@ -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) { export function catalogEntityFromCluster(cluster: Cluster) {

View File

@ -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;

View File

@ -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;

View File

@ -4,7 +4,6 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import forceAppExitInjectable from "./electron-app/features/force-app-exit.injectable"; import forceAppExitInjectable from "./electron-app/features/force-app-exit.injectable";
import clusterManagerInjectable from "./cluster/manager.injectable";
import loggerInjectable from "../common/logger.injectable"; import loggerInjectable from "../common/logger.injectable";
import emitAppEventInjectable from "../common/app-event-bus/emit-event.injectable"; import emitAppEventInjectable from "../common/app-event-bus/emit-event.injectable";
@ -13,13 +12,11 @@ const stopServicesAndExitAppInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const forceAppExit = di.inject(forceAppExitInjectable); const forceAppExit = di.inject(forceAppExitInjectable);
const clusterManager = di.inject(clusterManagerInjectable);
const logger = di.inject(loggerInjectable); const logger = di.inject(loggerInjectable);
const emitAppEvent = di.inject(emitAppEventInjectable); const emitAppEvent = di.inject(emitAppEventInjectable);
return async () => { return async () => {
emitAppEvent({ name: "service", action: "close" }); emitAppEvent({ name: "service", action: "close" });
clusterManager.stop();
logger.info("SERVICE:QUIT"); logger.info("SERVICE:QUIT");
setTimeout(forceAppExit, 1000); setTimeout(forceAppExit, 1000);
}; };