mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
parent
4eb1515a2d
commit
d323b88923
|
@ -11,7 +11,7 @@ import { Event } from 'vs/base/common/event';
|
|||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { mock } from 'vs/base/test/common/mock';
|
||||
import { assertThrowsAsync } from 'vs/base/test/common/utils';
|
||||
import { assertThrowsAsync, ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
|
||||
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';
|
||||
import { IMenu, IMenuService } from 'vs/platform/actions/common/actions';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
|
@ -40,6 +40,8 @@ suite('NotebookExecutionService', () => {
|
|||
disposables.dispose();
|
||||
});
|
||||
|
||||
ensureNoDisposablesAreLeakedInTestSuite();
|
||||
|
||||
setup(function () {
|
||||
|
||||
disposables = new DisposableStore();
|
||||
|
@ -80,8 +82,8 @@ suite('NotebookExecutionService', () => {
|
|||
contextKeyService = instantiationService.get(IContextKeyService);
|
||||
});
|
||||
|
||||
async function withTestNotebook(cells: [string, string, CellKind, IOutputDto[], NotebookCellMetadata][], callback: (viewModel: NotebookViewModel, textModel: NotebookTextModel) => void | Promise<void>) {
|
||||
return _withTestNotebook(cells, (editor, viewModel) => callback(viewModel, viewModel.notebookDocument));
|
||||
async function withTestNotebook(cells: [string, string, CellKind, IOutputDto[], NotebookCellMetadata][], callback: (viewModel: NotebookViewModel, textModel: NotebookTextModel, disposables: DisposableStore) => void | Promise<void>) {
|
||||
return _withTestNotebook(cells, (editor, viewModel, disposables) => callback(viewModel, viewModel.notebookDocument, disposables));
|
||||
}
|
||||
|
||||
// test('ctor', () => {
|
||||
|
@ -94,7 +96,7 @@ suite('NotebookExecutionService', () => {
|
|||
test('cell is not runnable when no kernel is selected', async () => {
|
||||
await withTestNotebook(
|
||||
[],
|
||||
async (viewModel, textModel) => {
|
||||
async (viewModel, textModel, disposables) => {
|
||||
const executionService = instantiationService.createInstance(NotebookExecutionService);
|
||||
|
||||
const cell = insertCellAtIndex(viewModel, 1, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
|
||||
|
@ -107,9 +109,9 @@ suite('NotebookExecutionService', () => {
|
|||
[],
|
||||
async (viewModel, textModel) => {
|
||||
|
||||
kernelService.registerKernel(new TestNotebookKernel({ languages: ['testlang'] }));
|
||||
const executionService = instantiationService.createInstance(NotebookExecutionService);
|
||||
const cell = insertCellAtIndex(viewModel, 1, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
|
||||
disposables.add(kernelService.registerKernel(new TestNotebookKernel({ languages: ['testlang'] })));
|
||||
const executionService = disposables.add(instantiationService.createInstance(NotebookExecutionService));
|
||||
const cell = disposables.add(insertCellAtIndex(viewModel, 1, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true));
|
||||
await assertThrowsAsync(async () => await executionService.executeNotebookCells(textModel, [cell.model], contextKeyService));
|
||||
|
||||
});
|
||||
|
@ -120,13 +122,13 @@ suite('NotebookExecutionService', () => {
|
|||
[],
|
||||
async (viewModel, textModel) => {
|
||||
const kernel = new TestNotebookKernel({ languages: ['javascript'] });
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, textModel);
|
||||
const executionService = instantiationService.createInstance(NotebookExecutionService);
|
||||
const executionService = disposables.add(instantiationService.createInstance(NotebookExecutionService));
|
||||
const executeSpy = sinon.spy();
|
||||
kernel.executeNotebookCellsRequest = executeSpy;
|
||||
|
||||
const cell = insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
|
||||
const cell = disposables.add(insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true));
|
||||
await executionService.executeNotebookCells(viewModel.notebookDocument, [cell.model], contextKeyService);
|
||||
assert.strictEqual(executeSpy.calledOnce, true);
|
||||
});
|
||||
|
@ -148,12 +150,12 @@ suite('NotebookExecutionService', () => {
|
|||
}
|
||||
};
|
||||
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, textModel);
|
||||
const executionService = instantiationService.createInstance(NotebookExecutionService);
|
||||
const executionService = disposables.add(instantiationService.createInstance(NotebookExecutionService));
|
||||
const exeStateService = instantiationService.get(INotebookExecutionStateService);
|
||||
|
||||
const cell = insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
|
||||
const cell = disposables.add(insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true));
|
||||
await executionService.executeNotebookCells(textModel, [cell.model], contextKeyService);
|
||||
|
||||
assert.strictEqual(didExecute, true);
|
||||
|
|
|
@ -10,6 +10,7 @@ import { Event } from 'vs/base/common/event';
|
|||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { mock } from 'vs/base/test/common/mock';
|
||||
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
|
||||
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';
|
||||
import { IMenu, IMenuService } from 'vs/platform/actions/common/actions';
|
||||
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
||||
|
@ -38,6 +39,8 @@ suite('NotebookExecutionStateService', () => {
|
|||
disposables.dispose();
|
||||
});
|
||||
|
||||
ensureNoDisposablesAreLeakedInTestSuite();
|
||||
|
||||
setup(function () {
|
||||
|
||||
disposables = new DisposableStore();
|
||||
|
@ -69,12 +72,12 @@ suite('NotebookExecutionStateService', () => {
|
|||
instantiationService.set(INotebookExecutionStateService, disposables.add(instantiationService.createInstance(NotebookExecutionStateService)));
|
||||
});
|
||||
|
||||
async function withTestNotebook(cells: [string, string, CellKind, IOutputDto[], NotebookCellMetadata][], callback: (viewModel: NotebookViewModel, textModel: NotebookTextModel) => void | Promise<void>) {
|
||||
return _withTestNotebook(cells, (editor, viewModel) => callback(viewModel, viewModel.notebookDocument));
|
||||
async function withTestNotebook(cells: [string, string, CellKind, IOutputDto[], NotebookCellMetadata][], callback: (viewModel: NotebookViewModel, textModel: NotebookTextModel, disposables: DisposableStore) => void | Promise<void>) {
|
||||
return _withTestNotebook(cells, (editor, viewModel) => callback(viewModel, viewModel.notebookDocument, disposables));
|
||||
}
|
||||
|
||||
function testCancelOnDelete(expectedCancels: number, implementsInterrupt: boolean) {
|
||||
return withTestNotebook([], async viewModel => {
|
||||
return withTestNotebook([], async (viewModel, _document, disposables) => {
|
||||
testNotebookModel = viewModel.notebookDocument;
|
||||
|
||||
let cancels = 0;
|
||||
|
@ -91,15 +94,15 @@ suite('NotebookExecutionStateService', () => {
|
|||
cancels += handles.length;
|
||||
}
|
||||
};
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, viewModel.notebookDocument);
|
||||
|
||||
const executionStateService: INotebookExecutionStateService = instantiationService.get(INotebookExecutionStateService);
|
||||
|
||||
// Should cancel executing and pending cells, when kernel does not implement interrupt
|
||||
const cell = insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
|
||||
const cell2 = insertCellAtIndex(viewModel, 1, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
|
||||
const cell3 = insertCellAtIndex(viewModel, 2, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
|
||||
const cell = disposables.add(insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true));
|
||||
const cell2 = disposables.add(insertCellAtIndex(viewModel, 1, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true));
|
||||
const cell3 = disposables.add(insertCellAtIndex(viewModel, 2, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true));
|
||||
insertCellAtIndex(viewModel, 3, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true); // Not deleted
|
||||
const exe = executionStateService.createCellExecution(viewModel.uri, cell.handle); // Executing
|
||||
exe.confirm();
|
||||
|
@ -126,11 +129,11 @@ suite('NotebookExecutionStateService', () => {
|
|||
});
|
||||
|
||||
test('fires onDidChangeCellExecution when cell is completed while deleted', async function () {
|
||||
return withTestNotebook([], async viewModel => {
|
||||
return withTestNotebook([], async (viewModel, _document, disposables) => {
|
||||
testNotebookModel = viewModel.notebookDocument;
|
||||
|
||||
const kernel = new TestNotebookKernel();
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, viewModel.notebookDocument);
|
||||
|
||||
const executionStateService: INotebookExecutionStateService = instantiationService.get(INotebookExecutionStateService);
|
||||
|
@ -153,15 +156,15 @@ suite('NotebookExecutionStateService', () => {
|
|||
});
|
||||
|
||||
test('does not fire onDidChangeCellExecution for output updates', async function () {
|
||||
return withTestNotebook([], async viewModel => {
|
||||
return withTestNotebook([], async (viewModel, _document, disposables) => {
|
||||
testNotebookModel = viewModel.notebookDocument;
|
||||
|
||||
const kernel = new TestNotebookKernel();
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, viewModel.notebookDocument);
|
||||
|
||||
const executionStateService: INotebookExecutionStateService = instantiationService.get(INotebookExecutionStateService);
|
||||
const cell = insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
|
||||
const cell = disposables.add(insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true));
|
||||
const exe = executionStateService.createCellExecution(viewModel.uri, cell.handle);
|
||||
|
||||
let didFire = false;
|
||||
|
@ -181,15 +184,15 @@ suite('NotebookExecutionStateService', () => {
|
|||
|
||||
// #142466
|
||||
test('getCellExecution and onDidChangeCellExecution', async function () {
|
||||
return withTestNotebook([], async viewModel => {
|
||||
return withTestNotebook([], async (viewModel, _document, disposables) => {
|
||||
testNotebookModel = viewModel.notebookDocument;
|
||||
|
||||
const kernel = new TestNotebookKernel();
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, viewModel.notebookDocument);
|
||||
|
||||
const executionStateService: INotebookExecutionStateService = instantiationService.get(INotebookExecutionStateService);
|
||||
const cell = insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
|
||||
const cell = disposables.add(insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true));
|
||||
|
||||
const deferred = new DeferredPromise<void>();
|
||||
disposables.add(executionStateService.onDidChangeExecution(e => {
|
||||
|
@ -213,11 +216,11 @@ suite('NotebookExecutionStateService', () => {
|
|||
});
|
||||
});
|
||||
test('getExecution and onDidChangeExecution', async function () {
|
||||
return withTestNotebook([], async viewModel => {
|
||||
return withTestNotebook([], async (viewModel, _document, disposables) => {
|
||||
testNotebookModel = viewModel.notebookDocument;
|
||||
|
||||
const kernel = new TestNotebookKernel();
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, viewModel.notebookDocument);
|
||||
|
||||
const eventRaisedWithExecution: boolean[] = [];
|
||||
|
@ -243,11 +246,11 @@ suite('NotebookExecutionStateService', () => {
|
|||
});
|
||||
|
||||
test('getExecution and onDidChangeExecution 2', async function () {
|
||||
return withTestNotebook([], async viewModel => {
|
||||
return withTestNotebook([], async (viewModel, _document, disposables) => {
|
||||
testNotebookModel = viewModel.notebookDocument;
|
||||
|
||||
const kernel = new TestNotebookKernel();
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, viewModel.notebookDocument);
|
||||
|
||||
const executionStateService: INotebookExecutionStateService = instantiationService.get(INotebookExecutionStateService);
|
||||
|
@ -283,15 +286,15 @@ suite('NotebookExecutionStateService', () => {
|
|||
});
|
||||
|
||||
test('force-cancel works for Cell Execution', async function () {
|
||||
return withTestNotebook([], async viewModel => {
|
||||
return withTestNotebook([], async (viewModel, _document, disposables) => {
|
||||
testNotebookModel = viewModel.notebookDocument;
|
||||
|
||||
const kernel = new TestNotebookKernel();
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, viewModel.notebookDocument);
|
||||
|
||||
const executionStateService: INotebookExecutionStateService = instantiationService.get(INotebookExecutionStateService);
|
||||
const cell = insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
|
||||
const cell = disposables.add(insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true));
|
||||
executionStateService.createCellExecution(viewModel.uri, cell.handle);
|
||||
const exe = executionStateService.getCellExecution(cell.uri);
|
||||
assert.ok(exe);
|
||||
|
@ -302,11 +305,11 @@ suite('NotebookExecutionStateService', () => {
|
|||
});
|
||||
});
|
||||
test('force-cancel works for Notebook Execution', async function () {
|
||||
return withTestNotebook([], async viewModel => {
|
||||
return withTestNotebook([], async (viewModel, _document, disposables) => {
|
||||
testNotebookModel = viewModel.notebookDocument;
|
||||
|
||||
const kernel = new TestNotebookKernel();
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, viewModel.notebookDocument);
|
||||
const eventRaisedWithExecution: boolean[] = [];
|
||||
|
||||
|
@ -324,11 +327,11 @@ suite('NotebookExecutionStateService', () => {
|
|||
});
|
||||
});
|
||||
test('force-cancel works for Cell and Notebook Execution', async function () {
|
||||
return withTestNotebook([], async viewModel => {
|
||||
return withTestNotebook([], async (viewModel, _document, disposables) => {
|
||||
testNotebookModel = viewModel.notebookDocument;
|
||||
|
||||
const kernel = new TestNotebookKernel();
|
||||
kernelService.registerKernel(kernel);
|
||||
disposables.add(kernelService.registerKernel(kernel));
|
||||
kernelService.selectKernelForNotebook(kernel, viewModel.notebookDocument);
|
||||
|
||||
const executionStateService: INotebookExecutionStateService = instantiationService.get(INotebookExecutionStateService);
|
||||
|
|
Loading…
Reference in a new issue