From 29709398cecf06fd9d1bc3f7d11bd53279f18391 Mon Sep 17 00:00:00 2001 From: Ian Huff Date: Thu, 3 Oct 2019 10:48:24 -0700 Subject: [PATCH 1/3] initial changes --- src/client/datascience/jupyter/jupyterServer.ts | 4 ++++ .../datascience/jupyter/liveshare/hostJupyterServer.ts | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/client/datascience/jupyter/jupyterServer.ts b/src/client/datascience/jupyter/jupyterServer.ts index afef002f8bec..6830b2497e37 100644 --- a/src/client/datascience/jupyter/jupyterServer.ts +++ b/src/client/datascience/jupyter/jupyterServer.ts @@ -169,6 +169,10 @@ export class JupyterServerBase implements INotebookServer { return this.notebooks.get(resource.toString()); } + protected getNotebooks(): INotebook[] { + return [...this.notebooks.values()]; + } + protected setNotebook(resource: Uri, notebook: INotebook) { const oldDispose = notebook.dispose; notebook.dispose = () => { diff --git a/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts b/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts index 64ea465df7a1..58b52ee966e7 100644 --- a/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts +++ b/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts @@ -89,6 +89,14 @@ export class HostJupyterServer await notebook.onAttach(api); }); + // If we have any notebooks currently started up we need to attach them + this.getNotebooks().forEach(notebook => { + const hostNotebook = notebook as HostJupyterNotebook; + if (hostNotebook) { + hostNotebook.onAttach(api); + } + }); + // See if we need to forward the port await this.attemptToForwardPort(api, this.portToForward); } From 5743e27e8a618737db37e0903132874faf039fff Mon Sep 17 00:00:00 2001 From: Ian Huff Date: Thu, 3 Oct 2019 16:50:57 -0700 Subject: [PATCH 2/3] update notebooks on server session change and add test --- news/2 Fixes/7638.md | 1 + .../jupyter/liveshare/guestJupyterServer.ts | 11 +++++++++++ .../jupyter/liveshare/hostJupyterServer.ts | 19 +++++++++++-------- .../datascience/liveshare.functional.test.tsx | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 news/2 Fixes/7638.md diff --git a/news/2 Fixes/7638.md b/news/2 Fixes/7638.md new file mode 100644 index 000000000000..dea499b65438 --- /dev/null +++ b/news/2 Fixes/7638.md @@ -0,0 +1 @@ +Fix a hang in the Interactive window when connecting guest to host after the host has already started the interactive window. \ No newline at end of file diff --git a/src/client/datascience/jupyter/liveshare/guestJupyterServer.ts b/src/client/datascience/jupyter/liveshare/guestJupyterServer.ts index 4acea881452c..65f233fcc559 100644 --- a/src/client/datascience/jupyter/liveshare/guestJupyterServer.ts +++ b/src/client/datascience/jupyter/liveshare/guestJupyterServer.ts @@ -72,6 +72,17 @@ export class GuestJupyterServer return result; } + public async onSessionChange(api: vsls.LiveShare | null): Promise { + await super.onSessionChange(api); + + this.notebooks.forEach(notebook => { + const guestNotebook = notebook as GuestJupyterNotebook; + if (guestNotebook) { + guestNotebook.onSessionChange(api); + } + }); + } + public async getNotebook(resource: Uri): Promise { return this.notebooks.get(resource.toString()); } diff --git a/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts b/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts index 58b52ee966e7..4448a4307928 100644 --- a/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts +++ b/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts @@ -89,20 +89,23 @@ export class HostJupyterServer await notebook.onAttach(api); }); - // If we have any notebooks currently started up we need to attach them - this.getNotebooks().forEach(notebook => { - const hostNotebook = notebook as HostJupyterNotebook; - if (hostNotebook) { - hostNotebook.onAttach(api); - } - }); - // See if we need to forward the port await this.attemptToForwardPort(api, this.portToForward); } } } + public async onSessionChange(api: vsls.LiveShare | null): Promise { + await super.onSessionChange(api); + + this.getNotebooks().forEach(notebook => { + const hostNotebook = notebook as HostJupyterNotebook; + if (hostNotebook) { + hostNotebook.onSessionChange(api); + } + }); + } + public async onDetach(api: vsls.LiveShare | null): Promise { await super.onDetach(api); diff --git a/src/test/datascience/liveshare.functional.test.tsx b/src/test/datascience/liveshare.functional.test.tsx index 27ea390bac19..1ff19cafed39 100644 --- a/src/test/datascience/liveshare.functional.test.tsx +++ b/src/test/datascience/liveshare.functional.test.tsx @@ -202,6 +202,23 @@ suite('DataScience LiveShare tests', () => { verifyHtmlOnCell(guestContainer.wrapper!, 'InteractiveCell', '1', CellPosition.Last); }); + test('Host starts LiveShare after starting Jupyter', async() => { + addMockData(hostContainer!, 'a=1\na', 1); + addMockData(hostContainer!, 'b=2\nb', 2); + await getOrCreateInteractiveWindow(vsls.Role.Host); + let wrapper = await addCodeToRole(vsls.Role.Host, 'a=1\na'); + verifyHtmlOnCell(wrapper, 'InteractiveCell', '1', CellPosition.Last); + + await startSession(vsls.Role.Host); + await getOrCreateInteractiveWindow(vsls.Role.Guest); + await startSession(vsls.Role.Guest); + + wrapper = await addCodeToRole(vsls.Role.Host, 'b=2\nb'); + + assert.ok(guestContainer.wrapper, 'Guest wrapper not created'); + verifyHtmlOnCell(guestContainer.wrapper!, 'InteractiveCell', '2', CellPosition.Last); + }); + test('Host Shutdown and Run', async () => { // Should only need mock data in host addMockData(hostContainer!, 'a=1\na', 1); From 3e29d0f4802bbe10dd6bf3bd7a056eb72e46081e Mon Sep 17 00:00:00 2001 From: Ian Huff Date: Thu, 3 Oct 2019 17:07:21 -0700 Subject: [PATCH 3/3] await correctly --- .../datascience/jupyter/liveshare/guestJupyterServer.ts | 4 ++-- src/client/datascience/jupyter/liveshare/hostJupyterServer.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client/datascience/jupyter/liveshare/guestJupyterServer.ts b/src/client/datascience/jupyter/liveshare/guestJupyterServer.ts index 65f233fcc559..64924bce0a3b 100644 --- a/src/client/datascience/jupyter/liveshare/guestJupyterServer.ts +++ b/src/client/datascience/jupyter/liveshare/guestJupyterServer.ts @@ -75,10 +75,10 @@ export class GuestJupyterServer public async onSessionChange(api: vsls.LiveShare | null): Promise { await super.onSessionChange(api); - this.notebooks.forEach(notebook => { + this.notebooks.forEach(async notebook => { const guestNotebook = notebook as GuestJupyterNotebook; if (guestNotebook) { - guestNotebook.onSessionChange(api); + await guestNotebook.onSessionChange(api); } }); } diff --git a/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts b/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts index 4448a4307928..4f099e945a19 100644 --- a/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts +++ b/src/client/datascience/jupyter/liveshare/hostJupyterServer.ts @@ -98,10 +98,10 @@ export class HostJupyterServer public async onSessionChange(api: vsls.LiveShare | null): Promise { await super.onSessionChange(api); - this.getNotebooks().forEach(notebook => { + this.getNotebooks().forEach(async notebook => { const hostNotebook = notebook as HostJupyterNotebook; if (hostNotebook) { - hostNotebook.onSessionChange(api); + await hostNotebook.onSessionChange(api); } }); }