-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the
hasRunningNotebookSession
context out of the notebook sess…
…ion service (#5688) Another step toward removing the notebook session service entirely (#2671). ### QA Notes This shouldn't change any behavior, although I did fix some edge cases where the context was not set correctly. Opening a notebook, restarting it, closing and reopening it should all work. The restart button should be deactivated when the session is exited.
- Loading branch information
Showing
11 changed files
with
396 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
extensions/positron-notebook-controllers/src/test/commands.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as assert from 'assert'; | ||
import * as positron from 'positron'; | ||
import * as sinon from 'sinon'; | ||
import * as vscode from 'vscode'; | ||
import { closeAllEditors, openTestJupyterNotebookDocument } from './utils'; | ||
import { TestLanguageRuntimeSession } from './testLanguageRuntimeSession'; | ||
import { onDidSetHasRunningNotebookSessionContext } from '../extension'; | ||
|
||
suite('commands', () => { | ||
let disposables: vscode.Disposable[]; | ||
let session: TestLanguageRuntimeSession; | ||
|
||
setup(() => { | ||
disposables = []; | ||
session = new TestLanguageRuntimeSession(); | ||
disposables.push(session); | ||
}); | ||
|
||
teardown(async () => { | ||
await closeAllEditors(); | ||
vscode.Disposable.from(...disposables).dispose(); | ||
sinon.restore(); | ||
}); | ||
|
||
// TODO: This test is currently flaky. It should become more stable once the restartKernel | ||
// calls directly to Positron and not via the notebook session service. | ||
test.skip('restart disables then enables hasRunningNotebookSession context', async () => { | ||
// Simulate a running session for the notebook. | ||
sinon.stub(positron.runtime, 'getNotebookSession').resolves(session as any); | ||
|
||
// Simulate a successful restart. | ||
sinon.stub(positron.runtime, 'restartSession').callsFake(async () => { | ||
session.setRuntimeState(positron.RuntimeState.Ready); | ||
}); | ||
|
||
// Open a test Jupyter notebook. | ||
await openTestJupyterNotebookDocument(); | ||
|
||
// Capture the first two hasRunningNotebookSession context values. | ||
const promise = new Promise<boolean[]>(resolve => { | ||
const values: boolean[] = []; | ||
disposables.push(onDidSetHasRunningNotebookSessionContext(value => { | ||
values.push(value); | ||
if (values.length === 2) { | ||
resolve(values); | ||
} | ||
})); | ||
}); | ||
|
||
// Restart. | ||
await vscode.commands.executeCommand('positron.restartKernel'); | ||
|
||
// Assert that the context is first set to false, then true. | ||
assert.deepStrictEqual(await promise, [false, true]); | ||
}); | ||
}); |
Oops, something went wrong.