Skip to content

Commit 4dab144

Browse files
Add remote functional test (microsoft#3741)
Add a functional test for remote connection functionality.
1 parent 4f237b4 commit 4dab144

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

news/3 Code Health/3714.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a functional test for interactive window remote connect scenario

src/test/datascience/notebook.functional.test.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CancellationToken, CancellationTokenSource } from 'vscode-jsonrpc';
1212
import { CancellationError } from '../../client/common/cancellation';
1313
import { EXTENSION_ROOT_DIR } from '../../client/common/constants';
1414
import { IFileSystem } from '../../client/common/platform/types';
15-
import { IProcessServiceFactory } from '../../client/common/process/types';
15+
import { IProcessServiceFactory, Output } from '../../client/common/process/types';
1616
import { createDeferred } from '../../client/common/utils/async';
1717
import { noop } from '../../client/common/utils/misc';
1818
import { concatMultilineString } from '../../client/datascience/common';
@@ -198,6 +198,43 @@ suite('Jupyter notebook tests', () => {
198198
}
199199
});
200200

201+
runTest('Remote', async () => {
202+
const python = await getNotebookCapableInterpreter();
203+
const procService = await processFactory.create();
204+
205+
if (procService && python) {
206+
const connectionFound = createDeferred();
207+
const exeResult = procService.execObservable(python.path, ['-m', 'jupyter', 'notebook', '--no-browser'], {env: process.env, throwOnStdErr: false});
208+
disposables.push(exeResult);
209+
210+
exeResult.out.subscribe((output: Output<string>) => {
211+
const connectionURL = getConnectionInfo(output.out);
212+
if (connectionURL) {
213+
connectionFound.resolve(connectionURL);
214+
}
215+
});
216+
217+
const connString = await connectionFound.promise;
218+
const uri = connString as string;
219+
220+
// We have a connection string here, so try to connect jupyterExecution to the notebook server
221+
const server = await jupyterExecution.connectToNotebookServer(uri!, true);
222+
if (!server) {
223+
assert.fail('Failed to connect to remote server');
224+
}
225+
}
226+
});
227+
228+
function getConnectionInfo(output: string) : string | undefined {
229+
const UrlPatternRegEx = /(https?:\/\/[^\s]+)/ ;
230+
231+
const urlMatch = UrlPatternRegEx.exec(output);
232+
if (urlMatch) {
233+
return urlMatch[0];
234+
}
235+
return undefined;
236+
}
237+
201238
runTest('Failure', async () => {
202239
// Make a dummy class that will fail during launch
203240
class FailedProcess extends JupyterExecution {
@@ -427,7 +464,7 @@ suite('Jupyter notebook tests', () => {
427464
}
428465

429466
// Try with something we can interrupt
430-
let interruptResult = await interruptExecute(server,
467+
let interruptResult = await interruptExecute(server!,
431468
`import signal
432469
import _thread
433470
import time
@@ -446,14 +483,14 @@ while keep_going:
446483

447484
// Try again with something that doesn't return. However it should finish before
448485
// we get to our own sleep. Note: We need the print so that the test knows something happened.
449-
interruptResult = await interruptExecute(server, `import time${os.EOL}time.sleep(4)${os.EOL}print("foo")`, 7000, 7000);
486+
interruptResult = await interruptExecute(server!, `import time${os.EOL}time.sleep(4)${os.EOL}print("foo")`, 7000, 7000);
450487

451488
// Try again with something that doesn't return. Make sure it times out
452-
interruptResult = await interruptExecute(server, `import time${os.EOL}time.sleep(4)${os.EOL}print("foo")`, 100, 7000);
489+
interruptResult = await interruptExecute(server!, `import time${os.EOL}time.sleep(4)${os.EOL}print("foo")`, 100, 7000);
453490
assert.equal(interruptResult, InterruptResult.TimedOut);
454491

455492
// The tough one, somethign that causes a kernel reset.
456-
interruptResult = await interruptExecute(server,
493+
interruptResult = await interruptExecute(server!,
457494
`import signal
458495
import time
459496
import os

0 commit comments

Comments
 (0)