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: consumed floating promises #836

Merged
merged 12 commits into from
Apr 14, 2022
15 changes: 13 additions & 2 deletions packages/core-common/src/utils/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { tmpdir } from 'os';
import { join, dirname } from 'path';

import { ensureDirSync } from 'fs-extra';
import { ensureDirSync, ensureDir } from 'fs-extra';

import { isWindows } from '../platform';
import { uuid } from '../uuid';

export function normalizedIpcHandlerPath(name: string, uuidSuffix = false, ipcPath = tmpdir()) {
let handler;
let handler: string;
if (!isWindows) {
handler = join(ipcPath, 'sumi-ipc', `sumi-ipc-${name}${uuidSuffix ? uuid() : ''}.sock`);
ensureDirSync(dirname(handler));
Expand All @@ -16,3 +16,14 @@ export function normalizedIpcHandlerPath(name: string, uuidSuffix = false, ipcPa
}
return handler;
}

export async function normalizedIpcHandlerPathAsync(name: string, uuidSuffix = false, ipcPath = tmpdir()) {
let handler: string;
if (!isWindows) {
handler = join(ipcPath, 'sumi-ipc', `sumi-ipc-${name}${uuidSuffix ? uuid() : ''}.sock`);
await ensureDir(dirname(handler));
} else {
handler = `\\\\.\\pipe\\sumi-ipc-${name}${uuidSuffix ? uuid() : ''}`;
}
return handler;
}
4 changes: 2 additions & 2 deletions packages/core-electron-main/src/bootstrap/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import treeKill from 'tree-kill';
import { Injectable, Autowired } from '@opensumi/di';
import { ExtensionCandidate } from '@opensumi/ide-core-common';
import { Disposable, getDebugLogger, isOSX, URI, FileUri, Deferred } from '@opensumi/ide-core-common';
import { normalizedIpcHandlerPath } from '@opensumi/ide-core-common/lib/utils/ipc';
import { normalizedIpcHandlerPathAsync } from '@opensumi/ide-core-common/lib/utils/ipc';

import { ElectronAppConfig, ICodeWindow, ICodeWindowOptions } from './types';

Expand Down Expand Up @@ -190,7 +190,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
this.windowClientId,
this.appConfig.extensionDir,
);
this.rpcListenPath = normalizedIpcHandlerPath('electron-window', true);
this.rpcListenPath = await normalizedIpcHandlerPathAsync('electron-window', true);
await this.node.start(this.rpcListenPath!, (this.workspace || '').toString());
this._nodeReady.resolve();
}
Expand Down
39 changes: 15 additions & 24 deletions packages/extension/__tests__/node/extension.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { ExtensionHostManager } from '../../src/node/extension.host.manager';
import { ExtensionNodeServiceImpl } from '../../src/node/extension.service';
import { ExtensionServiceClientImpl } from '../../src/node/extension.service.client';


describe('Extension Serivce', () => {
describe('Extension Service', () => {
let injector: Injector;
let extensionService: IExtensionNodeService;
const extensionDir = path.join(__dirname, '../../__mocks__/extensions');
Expand Down Expand Up @@ -46,9 +45,7 @@ describe('Extension Serivce', () => {
},
time() {
return {
timeEnd: () => {
//
},
timeEnd: () => 1,
};
},
},
Expand Down Expand Up @@ -116,62 +113,56 @@ describe('Extension Serivce', () => {
});

describe('extension host process', () => {
let mockExtClientId = 'mock_id123';
beforeEach(() => {
mockExtClientId = 'mock_id' + Math.random();
});

afterEach(async () => {
await extensionService.disposeClientExtProcess(mockExtClientId, true);
});

// jest.setTimeout(20 * 1000);

it('should create extension host process', async () => {
const mockExtClientId = 'mock_id' + Math.random();
await extensionService.createProcess(mockExtClientId);
const port = await extensionService.getProcessInspectPort(mockExtClientId);
expect(port).toBeUndefined();
await extensionService.disposeClientExtProcess(mockExtClientId, true);
});

it.skip('enable extProcess inspect port', async () => {
(global as any).isDev = undefined;
const mockExtClientId = 'mock_id' + Math.random();
await extensionService.createProcess(mockExtClientId);

const res = await extensionService.tryEnableInspectPort(mockExtClientId, 2000);
expect(res).toBeTruthy();

const port = await extensionService.getProcessInspectPort(mockExtClientId);
expect(typeof port).toBe('number');
await extensionService.disposeClientExtProcess(mockExtClientId, true);
});

it('create extension host process with develop mode', async () => {
(global as any).isDev = 1;
const mockExtClientId = 'mock_id' + Math.random();
await extensionService.createProcess(mockExtClientId);
const port = await extensionService.getProcessInspectPort(mockExtClientId);
expect(typeof port).toBe('number');
await extensionService.disposeClientExtProcess(mockExtClientId, false);
(global as any).isDev = undefined;
});

it('create extension host process with enable extension host options', async () => {
(global as any).isDev = undefined;
const mockExtClientId = 'mock_id' + Math.random();
await extensionService.createProcess(mockExtClientId, {
enableDebugExtensionHost: true,
});
const port = await extensionService.getProcessInspectPort(mockExtClientId);
expect(typeof port).toBe('number');
await extensionService.disposeClientExtProcess(mockExtClientId, false);
});
});

describe('getElectronMainThreadListenPath', () => {
it('should create connect listenPath', () => {
const mockExtClientId = 'mock_id' + Math.random();

const listenPath = extensionService.getElectronMainThreadListenPath2(mockExtClientId);
it('should create connect listenPath', async () => {
const listenPath = await extensionService.getElectronMainThreadListenPath2(mockExtClientId);
expect(path.dirname(listenPath)).toBe(path.join(os.tmpdir(), 'sumi-ipc'));
});
});

describe('getExtServerListenOption', () => {
it('should create ext server listen option', async () => {
const mockExtClientId = 'mock_id' + Math.random();

const { port, path: listenPath } = await extensionService.getExtServerListenOption(mockExtClientId);

if (port) {
Expand Down
4 changes: 2 additions & 2 deletions packages/extension/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export interface IExtensionNodeService {
): Promise<IExtensionMetaData[]>;
createProcess(clientId: string, options?: ICreateProcessOptions): Promise<void>;
ensureProcessReady(clientId: string): Promise<boolean>;
getElectronMainThreadListenPath(clientId: string);
getElectronMainThreadListenPath2(clientId: string);
getElectronMainThreadListenPath(clientId: string): Promise<string>;
getElectronMainThreadListenPath2(clientId: string): Promise<string>;
getExtServerListenOption(clientId: string);
getExtension(
extensionPath: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/node/extension.service.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class ExtensionServiceClientImpl
}

public async getElectronMainThreadListenPath(clientId: string) {
return this.extensionService.getElectronMainThreadListenPath(clientId);
return await this.extensionService.getElectronMainThreadListenPath(clientId);
}
/**
* 创建插件进程
Expand Down
Loading