Skip to content

Commit

Permalink
Add remote functional test (#3741)
Browse files Browse the repository at this point in the history
Add a functional test for remote connection functionality.
  • Loading branch information
IanMatthewHuff authored Dec 18, 2018
1 parent 4f237b4 commit 4dab144
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/3 Code Health/3714.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a functional test for interactive window remote connect scenario
47 changes: 42 additions & 5 deletions src/test/datascience/notebook.functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CancellationToken, CancellationTokenSource } from 'vscode-jsonrpc';
import { CancellationError } from '../../client/common/cancellation';
import { EXTENSION_ROOT_DIR } from '../../client/common/constants';
import { IFileSystem } from '../../client/common/platform/types';
import { IProcessServiceFactory } from '../../client/common/process/types';
import { IProcessServiceFactory, Output } from '../../client/common/process/types';
import { createDeferred } from '../../client/common/utils/async';
import { noop } from '../../client/common/utils/misc';
import { concatMultilineString } from '../../client/datascience/common';
Expand Down Expand Up @@ -198,6 +198,43 @@ suite('Jupyter notebook tests', () => {
}
});

runTest('Remote', async () => {
const python = await getNotebookCapableInterpreter();
const procService = await processFactory.create();

if (procService && python) {
const connectionFound = createDeferred();
const exeResult = procService.execObservable(python.path, ['-m', 'jupyter', 'notebook', '--no-browser'], {env: process.env, throwOnStdErr: false});
disposables.push(exeResult);

exeResult.out.subscribe((output: Output<string>) => {
const connectionURL = getConnectionInfo(output.out);
if (connectionURL) {
connectionFound.resolve(connectionURL);
}
});

const connString = await connectionFound.promise;
const uri = connString as string;

// We have a connection string here, so try to connect jupyterExecution to the notebook server
const server = await jupyterExecution.connectToNotebookServer(uri!, true);
if (!server) {
assert.fail('Failed to connect to remote server');
}
}
});

function getConnectionInfo(output: string) : string | undefined {
const UrlPatternRegEx = /(https?:\/\/[^\s]+)/ ;

const urlMatch = UrlPatternRegEx.exec(output);
if (urlMatch) {
return urlMatch[0];
}
return undefined;
}

runTest('Failure', async () => {
// Make a dummy class that will fail during launch
class FailedProcess extends JupyterExecution {
Expand Down Expand Up @@ -427,7 +464,7 @@ suite('Jupyter notebook tests', () => {
}

// Try with something we can interrupt
let interruptResult = await interruptExecute(server,
let interruptResult = await interruptExecute(server!,
`import signal
import _thread
import time
Expand All @@ -446,14 +483,14 @@ while keep_going:

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

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

// The tough one, somethign that causes a kernel reset.
interruptResult = await interruptExecute(server,
interruptResult = await interruptExecute(server!,
`import signal
import time
import os
Expand Down

0 comments on commit 4dab144

Please sign in to comment.