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:
parent
980b054fad
commit
1581da458d
@ -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);
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user