Skip to content
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

Fix failing, re-enable skipped and move tests #16416

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 7 additions & 8 deletions src/kernels/raw/finder/contributedKerneFinder.node.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { assert } from 'chai';
import * as os from 'os';
import * as path from '../../../platform/vscode-path/path';
import * as uriPath from '../../../platform/vscode-path/resources';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -834,10 +833,10 @@ import { setPythonApi } from '../../../platform/interpreter/helpers';
condaEnv1
].forEach((activePythonEnv) => {
suite(activePythonEnv ? `With active Python (${activePythonEnv.id})` : 'without active Python', () => {
setup(function () {
// Flaky windows unit tests. https://github.com/microsoft/vscode-jupyter/issues/13462
return this.skip();
});
// setup(function () {
// // Flaky windows unit tests. https://github.com/microsoft/vscode-jupyter/issues/13462
// return this.skip();
// });
/**
* As we're using a push model, we need to wait for the events to get triggered.
* How many events do we need to wait for is not deterministic (well for tests it is, but its too complex).
Expand Down Expand Up @@ -915,9 +914,9 @@ import { setPythonApi } from '../../../platform/interpreter/helpers';
});
test('If two kernelspecs share the same interpreter, but have different env variables, then both should be listed', async function () {
// https://github.com/microsoft/vscode-jupyter/issues/13236
if (os.platform() === 'win32') {
return this.skip();
}
// if (os.platform() === 'win32') {
// return this.skip();
// }
const testData: TestData = {
interpreters: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce = 'IPYWidgetCDN
export const GlobalStateKeyToNeverWarnAboutScriptsNotFoundOnCDN = 'IPYWidgetNotFoundOnCDN';
export const GlobalStateKeyToNeverWarnAboutNoNetworkAccess = 'IPYWidgetNoNetWorkAccess';

function moduleNameToCDNUrl(cdn: string, moduleName: string, moduleVersion: string) {
export function moduleNameToCDNUrl(cdn: string, moduleName: string, moduleVersion: string) {
let packageName = moduleName;
let fileName = 'index'; // default filename
// if a '/' is present, like 'foo/bar', packageName is changed to 'foo', and path to 'bar'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import * as sinon from 'sinon';
import { assert } from 'chai';
import * as fs from 'fs-extra';
import nock from 'nock';
import * as path from '../../../../platform/vscode-path/path';
import { Readable } from 'stream';
import { anything, deepEqual, instance, mock, verify, when } from 'ts-mockito';
import { ConfigurationTarget, Disposable, Memento, Uri } from 'vscode';
import { ConfigurationTarget, Disposable, Memento, type WorkspaceConfiguration } from 'vscode';
import { JupyterSettings } from '../../../../platform/common/configSettings';
import { ConfigurationService } from '../../../../platform/common/configuration/service.node';
import { IConfigurationService, IDisposable, WidgetCDNs } from '../../../../platform/common/types';
import { noop } from '../../../../platform/common/utils/misc';
import { EXTENSION_ROOT_DIR } from '../../../../platform/constants.node';
import {
CDNWidgetScriptSourceProvider,
GlobalStateKeyToNeverWarnAboutNoNetworkAccess,
GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce
GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce,
moduleNameToCDNUrl
} from './cdnWidgetScriptSourceProvider';
import { IWidgetScriptSourceProvider } from '../types';
import { dispose } from '../../../../platform/common/utils/lifecycle';
import { Common, DataScience } from '../../../../platform/common/utils/localize';
import { computeHash } from '../../../../platform/common/crypto';
import { mockedVSCodeNamespaces, resetVSCodeMocks } from '../../../../test/vscode-mock';

/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, , @typescript-eslint/no-explicit-any, , no-console */
const sanitize = require('sanitize-filename');
import { HttpClient } from '../../../../platform/common/net/httpClient';

const unpgkUrl = 'https://unpkg.com/';
const jsdelivrUrl = 'https://cdn.jsdelivr.net/npm/';
Expand All @@ -50,18 +43,6 @@ suite('ipywidget - CDN', () => {

teardown(() => (disposables = dispose(disposables)));

function createStreamFromString(str: string) {
const readable = new Readable();
readable._read = noop;
readable.push(str);
readable.push(null);
return readable;
}

async function generateScriptName(moduleName: string, moduleVersion: string) {
const hash = sanitize(await computeHash(`${moduleName}${moduleVersion}`, 'SHA-256'));
return Uri.file(path.join(EXTENSION_ROOT_DIR, 'temp', 'scripts', hash, 'index.js')).toString();
}
test('Prompt to use CDN', async () => {
when(
mockedVSCodeNamespaces.window.showInformationMessage(
Expand Down Expand Up @@ -319,28 +300,30 @@ suite('ipywidget - CDN', () => {
// Nock seems to fail randomly on CI builds. See bug
// https://github.com/microsoft/vscode-python/issues/11442
// eslint-disable-next-line no-invalid-this
suite.skip(cdn, () => {
suite(cdn, () => {
const moduleName = 'HelloWorld';
const moduleVersion = '1';
let baseUrl = '';
let scriptUri = '';
const disposables: IDisposable[] = [];
setup(async () => {
baseUrl = cdn === 'unpkg.com' ? unpgkUrl : jsdelivrUrl;
scriptUri = await generateScriptName(moduleName, moduleVersion);
const baseUrl = cdn === 'unpkg.com' ? unpgkUrl : jsdelivrUrl;
scriptUri = moduleNameToCDNUrl(baseUrl, moduleName, moduleVersion);
const workspaceConfig = mock<WorkspaceConfiguration>();
when(workspaceConfig.get('proxy', anything())).thenReturn('');
when(mockedVSCodeNamespaces.workspace.getConfiguration('http')).thenReturn(
instance(workspaceConfig)
);
});
teardown(() => {
sinon.restore();
resetVSCodeMocks();
scriptSourceProvider.dispose();
nock.cleanAll();
dispose(disposables);
disposables.length = 0;
});
test('Ensure widget script is downloaded once and cached', async () => {
test('Verify script source', async () => {
updateCDNSettings(cdn);
let downloadCount = 0;
nock(baseUrl)
.get(/.*/)
.reply(200, () => {
downloadCount += 1;
return createStreamFromString('foo');
});
sinon.stub(HttpClient.prototype, 'exists').resolves(true);

const value = await scriptSourceProvider.getWidgetScriptSource(moduleName, moduleVersion);

Expand All @@ -349,20 +332,10 @@ suite('ipywidget - CDN', () => {
scriptUri,
source: 'cdn'
});

const value2 = await scriptSourceProvider.getWidgetScriptSource(moduleName, moduleVersion);

assert.deepEqual(value2, {
moduleName: 'HelloWorld',
scriptUri,
source: 'cdn'
});

assert.equal(downloadCount, 1, 'Downloaded more than once');
});
test('No script source if package does not exist on CDN', async () => {
updateCDNSettings(cdn);
nock(baseUrl).get(/.*/).replyWithError('404');
sinon.stub(HttpClient.prototype, 'exists').resolves(false);

const value = await scriptSourceProvider.getWidgetScriptSource(moduleName, moduleVersion);

Expand All @@ -377,61 +350,7 @@ suite('ipywidget - CDN', () => {
? ([cdn, 'jsdelivr.com'] as WidgetCDNs[])
: ([cdn, 'unpkg.com'] as WidgetCDNs[]);
updateCDNSettings(cdns[0], cdns[1]);
// Make only one cdn available
// when(httpClient.exists(anything())).thenCall((a) => {
// if (a.includes(cdn[0])) {
// return true;
// }
// return false;
// });
nock(baseUrl)
.get(/.*/)
.reply(200, () => {
return createStreamFromString('foo');
});
const value = await scriptSourceProvider.getWidgetScriptSource(moduleName, moduleVersion);

assert.deepEqual(value, {
moduleName: 'HelloWorld',
scriptUri,
source: 'cdn'
});
});

test('Retry if busy', async () => {
let retryCount = 0;
updateCDNSettings(cdn);
// when(httpClient.exists(anything())).thenResolve(true);
nock(baseUrl).get(/.*/).twice().replyWithError('Not found');
nock(baseUrl)
.get(/.*/)
.thrice()
.reply(200, () => {
retryCount = 3;
return createStreamFromString('foo');
});

// Then see if we can get it still.
const value = await scriptSourceProvider.getWidgetScriptSource(moduleName, moduleVersion);

assert.deepEqual(value, {
moduleName: 'HelloWorld',
scriptUri,
source: 'cdn'
});
assert.equal(retryCount, 3, 'Did not actually retry');
});
test('Script source already on disk', async () => {
updateCDNSettings(cdn);
// Make nobody available
// when(httpClient.exists(anything())).thenResolve(true);

// Write to where the file should eventually end up
const filePath = Uri.parse(scriptUri).fsPath;
await fs.createFile(filePath);
await fs.writeFile(filePath, 'foo');

// Then see if we can get it still.
sinon.stub(HttpClient.prototype, 'exists').resolves(true);
const value = await scriptSourceProvider.getWidgetScriptSource(moduleName, moduleVersion);

assert.deepEqual(value, {
Expand Down
27 changes: 0 additions & 27 deletions src/platform/common/experiments/service.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,6 @@ suite('Experimentation service', () => {
telemetryEvents = [];
});

test.skip('If the opt-in and opt-out arrays are empty, return the value from the experimentation framework for a given experiment', async () => {
configureSettings(true, [], []);

const experimentService = new ExperimentService(
instance(configurationService),
instance(appEnvironment),
globalMemento
);
const result = await experimentService.inExperiment(experiment);

assert.isTrue(result);
sinon.assert.notCalled(sendTelemetryEventStub);
});

test('If the experiment setting is disabled, inExperiment should return false', async () => {
configureSettings(false, [], []);

Expand Down Expand Up @@ -165,19 +151,6 @@ suite('Experimentation service', () => {
} as any);
});

test.skip('If the service is enabled and the opt-out array is empty,return the value from the experimentation framework for a given experiment', async () => {
configureSettings(true, [], []);

const experimentService = new ExperimentService(
instance(configurationService),
instance(appEnvironment),
globalMemento
);
const result = await experimentService.getExperimentValue(experiment);

assert.equal(result, 'value');
});

test('If the experiment setting is disabled, getExperimentValue should return undefined', async () => {
configureSettings(false, [], []);

Expand Down
58 changes: 0 additions & 58 deletions src/test/datascience/interactiveDebugging.vscode.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,64 +90,6 @@ export function sharedIWDebuggerTests(
await closeNotebooksAndCleanUpAfterTests(disposables);
});

// TODO: This should be a testMandatory
test.skip('Debug a cell from a python file @mandatory', async () => {
// #11917
// Run a cell to get IW open
const source = 'print(42)';
const { activeInteractiveWindow, untitledPythonFile } = await submitFromPythonFile(
interactiveWindowProvider,
source,
disposables
);
await waitForLastCellToComplete(activeInteractiveWindow);

// Add some more text
const editor = vscode.window.visibleTextEditors.find((e) => e.document.uri === untitledPythonFile.uri);
assert.ok(editor, `Couldn't find python file`);
await editor?.edit((b) => {
b.insert(new vscode.Position(1, 0), '\n# %%\n\n\nprint(43)');
});

let codeLenses = await waitForCodeLenses(untitledPythonFile.uri, Commands.DebugCell);
let stopped = false;
let stoppedOnLine5 = false;
debugAdapterTracker = {
onDidSendMessage: (message) => {
if (message.event == 'stopped') {
stopped = true;
}
if (message.command == 'stackTrace' && !stoppedOnLine5) {
stoppedOnLine5 = message.body.stackFrames[0].line == 5;
}
}
};

// Try debugging the cell
assert.ok(codeLenses, `No code lenses found`);
assert.equal(codeLenses.length, 3, `Wrong number of code lenses found`);
const args = codeLenses[2].command!.arguments || [];
vscode.commands.executeCommand(codeLenses[2].command!.command, ...args).then(noop, noop);

// Wait for breakpoint to be hit
await waitForCondition(
async () => {
return vscode.debug.activeDebugSession != undefined && stopped;
},
defaultNotebookTestTimeout,
`Never hit stop event when waiting for debug cell`
);

// Verify we are on the 'print(43)' line (might take a second for UI to update after stop event)
await waitForCondition(
async () => {
return stoppedOnLine5;
},
defaultNotebookTestTimeout,
`Cursor did not move to expected line when hitting breakpoint`
);
});

test('Run a cell and step into breakpoint', async function () {
// Define the function
const source = 'def foo():\n print("foo")';
Expand Down
Loading