Skip to content

Commit baca18b

Browse files
committed
Fix intermittent test failures
1 parent 325e1f0 commit baca18b

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

news/3 Code Health/4936.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Intermittent test failures with invalid objects.

news/3 Code Health/4951.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test intermittent failures with jupyter kernel shutdown.

src/client/datascience/jupyter/jupyterServer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ export class JupyterServerBase implements INotebookServer {
574574
if (this.launchInfo && this.launchInfo.connectionInfo) {
575575
// If the server crashes, cancel the current observable
576576
exitHandlerDisposable = this.launchInfo.connectionInfo.disconnected((c) => {
577-
subscriber.error(this.sessionStartTime, new Error(localize.DataScience.jupyterServerCrashed().format(c.toString())));
577+
const str = c ? c.toString() : '';
578+
subscriber.error(this.sessionStartTime, new Error(localize.DataScience.jupyterServerCrashed().format(str)));
578579
subscriber.complete(this.sessionStartTime);
579580
});
580581
}

src/client/datascience/jupyter/jupyterSession.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { callWithTimeout, sleep } from '../../common/utils/async';
2020
import * as localize from '../../common/utils/localize';
2121
import { noop } from '../../common/utils/misc';
2222
import { IConnection, IJupyterKernelSpec, IJupyterSession } from '../types';
23+
import { isTestExecution } from '../../common/constants';
2324

2425
export class JupyterSession implements IJupyterSession {
2526
private connInfo: IConnection | undefined;
@@ -182,17 +183,17 @@ export class JupyterSession implements IJupyterSession {
182183
if (this.session) {
183184
try {
184185
// Shutdown may fail if the process has been killed
185-
await Promise.race([this.session.shutdown(), sleep(100)]);
186+
await Promise.race([this.session.shutdown(), sleep(1000)]);
186187
} catch {
187188
noop();
188189
}
189190
// Dispose may not return. Wrap in a promise instead. Kernel futures can die if
190191
// process is already dead.
191-
if (this.session) {
192+
if (this.session && !isTestExecution()) {
192193
await callWithTimeout(this.session.dispose.bind(this.session), 100);
193194
}
194195
}
195-
if (this.sessionManager) {
196+
if (this.sessionManager && !isTestExecution()) {
196197
await callWithTimeout(this.sessionManager.dispose.bind(this.sessionManager), 100);
197198
}
198199
} catch {

src/test/datascience/mockLiveShare.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ class Emitter<T> {
126126
if (typeof item.listener === 'function') {
127127
result = item.listener.call(undefined, item.event);
128128
} else {
129-
result = item.listener[0].call(item.listener[1], item.event);
129+
const func = item.listener[0];
130+
if (func) {
131+
result = item.listener[0].call(item.listener[1], item.event);
132+
}
130133
}
131134
}
132135
} catch (e) {

0 commit comments

Comments
 (0)