Skip to content

Fix waitForMessage timeouts on the functional tests #8278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3 Code Health/8255.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Timeout with new waitForMessage in native editor tests.
3 changes: 2 additions & 1 deletion src/test/datascience/nativeEditor.functional.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ for _ in range(50):
assert.ok(cell, 'Cannot find the first cell');
const imageButtons = cell!.find(ImageButton);
assert.equal(imageButtons.length, 7, 'Cell buttons not found');
const runButton = imageButtons.at(2);
const runButton = imageButtons.findWhere(w => w.props().tooltip === 'Run cell');
assert.equal(runButton.length, 1, 'No run button found');
const update = waitForMessage(ioc, InteractiveWindowMessages.RenderComplete);
runButton.simulate('click');
await update;
Expand Down
4 changes: 2 additions & 2 deletions src/test/datascience/testHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export enum CellPosition {
Last = 'last'
}

export function waitForMessage(ioc: DataScienceIocContainer, message: string): Promise<void> {
export function waitForMessage(ioc: DataScienceIocContainer, message: string, timeoutMs: number = 65000): Promise<void> {
// Wait for the mounted web panel to send a message back to the data explorer
const promise = createDeferred<void>();
let handler: (m: string, p: any) => void;
const timer = setTimeout(() => {
if (!promise.resolved) {
promise.reject(new Error(`Waiting for ${message} timed out`));
}
}, 3000); // Max 3 seconds for a message. Should be almost instant but this will make tests fail faster than the max timeout.
}, timeoutMs);
handler = (m: string, _p: any) => {
if (m === message) {
ioc.removeMessageListener(handler);
Expand Down
43 changes: 2 additions & 41 deletions src/test/datascience/variableexplorer.functional.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import { InteractivePanel } from '../../datascience-ui/history-react/interactive
import { VariableExplorer } from '../../datascience-ui/interactive-common/variableExplorer';
import { NativeEditor } from '../../datascience-ui/native-editor/nativeEditor';
import { DataScienceIocContainer } from './dataScienceIocContainer';
import { addCode, runMountedTest as interactiveRunMountedTest } from './interactiveWindowTestHelpers';
import { addCell, createNewEditor, runMountedTest as nativeRunMountedTest } from './nativeEditorTestHelpers';
import { waitForUpdate } from './reactHelpers';
import { addCode } from './interactiveWindowTestHelpers';
import { addCell, createNewEditor } from './nativeEditorTestHelpers';
import { runDoubleTest, waitForMessage } from './testHelpers';

// tslint:disable:max-func-body-length trailing-comma no-any no-multiline-string
Expand Down Expand Up @@ -65,34 +64,6 @@ suite('DataScience Interactive Window variable explorer tests', () => {
return waitForMessage(ioc, InteractiveWindowMessages.VariablesComplete);
}

async function checkVariableLoading(wrapper: ReactWrapper<any, Readonly<{}>, React.Component>, targetRenderCount: number) {
const basicCode: string = `value = 'hello world'`;

openVariableExplorer(wrapper);

await addCodeImpartial(wrapper, 'a=1\na');
await addCodeImpartial(wrapper, basicCode, false);

// Target a render count before loading is finished
await waitForUpdate(wrapper, VariableExplorer, targetRenderCount);

let targetVariables: IJupyterVariable[] = [
{name: 'a', value: '1', supportsDataExplorer: false, type: 'int', size: 54, shape: '', count: 0, truncated: false},
{name: 'value', value: 'Loading...', supportsDataExplorer: false, type: 'str', size: 54, shape: '', count: 0, truncated: false}
];
verifyVariables(wrapper, targetVariables);

// Now wait for one more update and then check the variables, we should have loaded the value var
await waitForUpdate(wrapper, VariableExplorer, 1);

targetVariables = [
{name: 'a', value: '1', supportsDataExplorer: false, type: 'int', size: 54, shape: '', count: 0, truncated: false},
// tslint:disable-next-line:quotemark
{name: 'value', value: "'hello world'", supportsDataExplorer: false, type: 'str', size: 54, shape: '', count: 0, truncated: false}
];
verifyVariables(wrapper, targetVariables);
}

async function addCodeImpartial(wrapper: ReactWrapper<any, Readonly<{}>, React.Component>, code: string, waitForVariables: boolean = true, expectedRenderCount: number = 4, expectError: boolean = false): Promise<ReactWrapper<any, Readonly<{}>, React.Component>> {
const variablesUpdated = waitForVariables ? waitForVariablesUpdated() : Promise.resolve();
const nodes = wrapper.find('InteractivePanel');
Expand Down Expand Up @@ -181,16 +152,6 @@ value = 'hello world'`;
verifyVariables(wrapper, targetVariables);
}, () => { return ioc; });

// For the loading tests we check before the explorer is fully loaded, so split tests here to check
// with different target render counts
nativeRunMountedTest('Variable Explorer - Native Loading', async (wrapper) => {
await checkVariableLoading(wrapper, 3);
}, () => { return ioc; });

interactiveRunMountedTest('Variable Explorer - Interactive Loading', async (wrapper) => {
await checkVariableLoading(wrapper, 2);
}, () => { return ioc; });

// Test our display of basic types. We render 8 rows by default so only 8 values per test
runDoubleTest('Variable explorer - Types A', async (wrapper) => {
const basicCode: string = `myList = [1, 2, 3]
Expand Down