Remove adstest package (#9956)

This commit is contained in:
Charles Gagnon
2020-04-15 10:38:20 -07:00
committed by GitHub
parent 251fa220d5
commit 916ac7c7d1
6 changed files with 390 additions and 655 deletions

View File

@@ -4,10 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import * as testRunner from 'vscode/lib/testrunner';
import { SuiteType, getSuiteType } from 'adstest';
import * as path from 'path';
const suite = getSuiteType();
const suite = 'Extension Integration Tests';
const options: any = {
ui: 'tdd',
@@ -15,17 +14,6 @@ const options: any = {
timeout: 600000
};
if (suite === SuiteType.Stress) {
options.timeout = 7200000; // 2 hours
// StressRuntime sets the default run time in stress/perf mode for those suites. By default ensure that there is sufficient timeout available.
// if ADS_TEST_TIMEOUT is also defined then that value overrides this calculated timeout value. User needs to ensure that ADS_TEST_GREP > StressRuntime if
// both are set.
if (process.env.StressRuntime) {
options.timeout = (120 + 1.2 * parseInt(process.env.StressRuntime)) * 1000; // allow sufficient timeout based on StressRuntime setting
console.log(`setting options.timeout to: ${options.timeout} based on process.env.StressRuntime value of ${process.env.StressRuntime} seconds`);
}
}
// set relevant mocha options from the environment
if (process.env.ADS_TEST_GREP) {
options.grep = process.env.ADS_TEST_GREP;

View File

@@ -11,7 +11,6 @@ import { sqlNotebookContent, writeNotebookToFile, sqlKernelMetadata, getFileName
import { getConfigValue, EnvironmentVariable_PYTHON_PATH, TestServerProfile, getStandaloneServer } from './testConfig';
import { connectToServer, sleep, testServerProfileToIConnectionProfile } from './utils';
import * as fs from 'fs';
import { stressify } from 'adstest';
import { isNullOrUndefined, promisify } from 'util';
suite('Notebook integration test suite', function () {
@@ -23,136 +22,42 @@ suite('Notebook integration test suite', function () {
});
teardown(async function () {
await (new NotebookTester()).cleanup(this.currentTest.title);
try {
let fileName = getFileName(this.test.title + this.invocationCount++);
if (await promisify(fs.exists)(fileName)) {
await fs.promises.unlink(fileName);
console.log(`"${fileName}" is deleted.`);
}
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
}
catch (err) {
console.log(err);
}
finally {
console.log(`"${this.test.title}" is done`);
}
});
test('Sql NB test @UNSTABLE@', async function () {
await (new NotebookTester()).sqlNbTest(this.test.title);
});
test('Sql NB multiple cells test @UNSTABLE@', async function () {
await (new NotebookTester()).sqlNbMultipleCellsTest(this.test.title);
});
test('Sql NB run cells above and below test', async function () {
await (new NotebookTester()).sqlNbRunCellsAboveBelowTest(this.test.title);
});
test('Clear cell output - SQL notebook', async function () {
await (new NotebookTester()).sqlNbClearOutputs(this.test.title);
});
test('Clear all outputs - SQL notebook ', async function () {
await (new NotebookTester()).sqlNbClearAllOutputs(this.test.title);
});
test('sql language test', async function () {
await (new NotebookTester()).sqlLanguageTest(this.test.title);
});
// TODO: Need to make this test more reliable.
test('should not be dirty after saving notebook test @UNSTABLE@', async function () {
await (new NotebookTester().shouldNotBeDirtyAfterSavingNotebookTest(this.test.title));
});
if (process.env['RUN_PYTHON3_TEST'] === '1') {
test('Python3 notebook test', async function () {
await (new NotebookTester()).python3NbTest(this.test.title);
});
test('Clear all outputs - Python3 notebook ', async function () {
await (new NotebookTester()).python3ClearAllOutputs(this.test.title);
});
test('python language test', async function () {
await (new NotebookTester()).pythonLanguageTest(this.test.title);
});
test('Change kernel different provider SQL to Python to SQL', async function () {
await (new NotebookTester()).sqlNbChangeKernelDifferentProviderTest(this.test.title);
});
test('Change kernel different provider Python to SQL to Python', async function () {
await (new NotebookTester()).pythonChangeKernelDifferentProviderTest(this.test.title);
});
test('Change kernel same provider Python to PySpark to Python', async function () {
await (new NotebookTester()).pythonChangeKernelSameProviderTest(this.test.title);
});
}
if (process.env['RUN_PYSPARK_TEST'] === '1') {
test('PySpark notebook test', async function () {
await (new NotebookTester()).pySparkNbTest(this.test.title);
});
}
/* After https://github.com/microsoft/azuredatastudio/issues/5598 is fixed, enable these tests.
test('scala language test', async function () {
await (new NotebookTester()).scalaLanguageTest(this.test.title);
});
test('empty language test', async function () {
await (new NotebookTester()).emptyLanguageTest(this.test.title);
});
test('cplusplus language test', async function () {
await (new NotebookTester()).cplusplusLanguageTest(this.test.title);
});
*/
});
class NotebookTester {
private static ParallelCount = 1;
invocationCount: number = 0;
@stressify({ dop: NotebookTester.ParallelCount })
async pySparkNbTest(title: string): Promise<void> {
let notebook = await this.openNotebook(pySparkNotebookContent, pySparkKernelMetadata, title + this.invocationCount++);
await this.runCell(notebook);
let cellOutputs = notebook.document.cells[0].contents.outputs;
let sparkResult = (<azdata.nb.IStreamResult>cellOutputs[3]).text;
assert(sparkResult === '2', `Expected spark result: 2, Actual: ${sparkResult}`);
}
@stressify({ dop: NotebookTester.ParallelCount })
async python3ClearAllOutputs(title: string): Promise<void> {
let notebook = await this.openNotebook(pySparkNotebookContent, pythonKernelMetadata, title + this.invocationCount++);
await this.runCell(notebook);
await this.verifyClearAllOutputs(notebook);
}
@stressify({ dop: NotebookTester.ParallelCount })
async python3NbTest(title: string): Promise<void> {
let notebook = await this.openNotebook(pySparkNotebookContent, pythonKernelMetadata, title + this.invocationCount++);
await this.runCell(notebook);
let notebook = await openNotebook(sqlNotebookContent, sqlKernelMetadata, this.test.title + this.invocationCount++, true);
await runCell(notebook);
const expectedOutput0 = '(1 row affected)';
let cellOutputs = notebook.document.cells[0].contents.outputs;
console.log('Got cell outputs ---');
if (cellOutputs) {
cellOutputs.forEach(o => console.log(JSON.stringify(o, undefined, '\t')));
cellOutputs.forEach(o => console.log(o));
}
let result = (<azdata.nb.IExecuteResult>cellOutputs[0]).data['text/plain'];
assert(result === '2', `Expected python result: 2, Actual: ${result}`);
}
assert(cellOutputs.length === 3, `Expected length: 3, Actual: ${cellOutputs.length}`);
let actualOutput0 = (<azdata.nb.IDisplayData>cellOutputs[0]).data['text/html'];
console.log('Got first output');
assert(actualOutput0 === expectedOutput0, `Expected row count: ${expectedOutput0}, Actual: ${actualOutput0}`);
let actualOutput2 = (<azdata.nb.IExecuteResult>cellOutputs[2]).data['application/vnd.dataresource+json'].data[0];
assert(actualOutput2[0] === '1', `Expected result: 1, Actual: '${actualOutput2[0]}'`);
});
@stressify({ dop: NotebookTester.ParallelCount })
async sqlNbClearAllOutputs(title: string): Promise<void> {
let notebook = await this.openNotebook(sqlNotebookContent, sqlKernelMetadata, title + this.invocationCount++);
await this.runCell(notebook);
await this.verifyClearAllOutputs(notebook);
}
async sqlNbClearOutputs(title: string): Promise<void> {
let notebook = await this.openNotebook(sqlNotebookContent, sqlKernelMetadata, title + this.invocationCount++);
await this.runCell(notebook);
await this.verifyClearOutputs(notebook);
}
@stressify({ dop: NotebookTester.ParallelCount })
async sqlNbMultipleCellsTest(title: string): Promise<void> {
let notebook = await this.openNotebook(sqlNotebookMultipleCellsContent, sqlKernelMetadata, title + this.invocationCount++);
await this.runCells(notebook);
test('Sql NB multiple cells test @UNSTABLE@', async function () {
let notebook = await openNotebook(sqlNotebookMultipleCellsContent, sqlKernelMetadata, this.test.title + this.invocationCount++);
await runCells(notebook);
const expectedOutput0 = '(1 row affected)';
for (let i = 0; i < 3; i++) {
let cellOutputs = notebook.document.cells[i].contents.outputs;
@@ -177,12 +82,12 @@ class NotebookTester {
assert(actualOutput2[0] === i.toString(), `Expected result: ${i.toString()}, Actual: '${actualOutput2[0]}'`);
console.log('Sql multiple cells NB done');
}
}
});
async sqlNbRunCellsAboveBelowTest(title: string): Promise<void> {
let notebook = await this.openNotebook(sqlNotebookMultipleCellsContent, sqlKernelMetadata, title + this.invocationCount++);
test('Sql NB run cells above and below test', async function () {
let notebook = await openNotebook(sqlNotebookMultipleCellsContent, sqlKernelMetadata, this.test.title + this.invocationCount++);
// When running all cells above a cell, ensure that only cells preceding current cell have output
await this.runCells(notebook, true, undefined, notebook.document.cells[1]);
await runCells(notebook, true, undefined, notebook.document.cells[1]);
assert(notebook.document.cells[0].contents.outputs.length === 3, `Expected length: '3', Actual: '${notebook.document.cells[0].contents.outputs.length}'`);
assert(notebook.document.cells[1].contents.outputs.length === 0, `Expected length: '0', Actual: '${notebook.document.cells[1].contents.outputs.length}'`);
assert(notebook.document.cells[2].contents.outputs.length === 0, `Expected length: '0', Actual: '${notebook.document.cells[2].contents.outputs.length}'`);
@@ -190,49 +95,44 @@ class NotebookTester {
await notebook.clearAllOutputs();
// When running all cells below a cell, ensure that current cell and cells after have output
await this.runCells(notebook, undefined, true, notebook.document.cells[1]);
await runCells(notebook, undefined, true, notebook.document.cells[1]);
assert(notebook.document.cells[0].contents.outputs.length === 0, `Expected length: '0', Actual: '${notebook.document.cells[0].contents.outputs.length}'`);
assert(notebook.document.cells[1].contents.outputs.length === 3, `Expected length: '3', Actual: '${notebook.document.cells[1].contents.outputs.length}'`);
assert(notebook.document.cells[2].contents.outputs.length === 3, `Expected length: '3', Actual: '${notebook.document.cells[2].contents.outputs.length}'`);
}
});
@stressify({ dop: NotebookTester.ParallelCount })
async sqlNbTest(title: string): Promise<void> {
let notebook = await this.openNotebook(sqlNotebookContent, sqlKernelMetadata, title + this.invocationCount++, true);
await this.runCell(notebook);
const expectedOutput0 = '(1 row affected)';
let cellOutputs = notebook.document.cells[0].contents.outputs;
console.log('Got cell outputs ---');
if (cellOutputs) {
cellOutputs.forEach(o => console.log(o));
}
assert(cellOutputs.length === 3, `Expected length: 3, Actual: ${cellOutputs.length}`);
let actualOutput0 = (<azdata.nb.IDisplayData>cellOutputs[0]).data['text/html'];
console.log('Got first output');
assert(actualOutput0 === expectedOutput0, `Expected row count: ${expectedOutput0}, Actual: ${actualOutput0}`);
let actualOutput2 = (<azdata.nb.IExecuteResult>cellOutputs[2]).data['application/vnd.dataresource+json'].data[0];
assert(actualOutput2[0] === '1', `Expected result: 1, Actual: '${actualOutput2[0]}'`);
}
test('Clear cell output - SQL notebook', async function () {
let notebook = await openNotebook(sqlNotebookContent, sqlKernelMetadata, this.test.title + this.invocationCount++);
await runCell(notebook);
await verifyClearOutputs(notebook);
});
async sqlNbChangeKernelDifferentProviderTest(title: string): Promise<void> {
let notebook = await this.openNotebook(sqlNotebookContent, sqlKernelMetadata, title);
await this.runCell(notebook);
assert(notebook.document.providerId === 'sql', `Expected providerId to be sql, Actual: ${notebook.document.providerId}`);
assert(notebook.document.kernelSpec.name === 'SQL', `Expected first kernel name: SQL, Actual: ${notebook.document.kernelSpec.name}`);
test('Clear all outputs - SQL notebook ', async function () {
let notebook = await openNotebook(sqlNotebookContent, sqlKernelMetadata, this.test.title + this.invocationCount++);
await runCell(notebook);
await verifyClearAllOutputs(notebook);
});
let kernelChanged = await notebook.changeKernel(pythonKernelSpec);
assert(notebook.document.providerId === 'jupyter', `Expected providerId to be jupyter, Actual: ${notebook.document.providerId}`);
assert(kernelChanged && notebook.document.kernelSpec.name === 'python3', `Expected second kernel name: python3, Actual: ${notebook.document.kernelSpec.name}`);
test('sql language test', async function () {
let language = 'sql';
await cellLanguageTest(notebookContentForCellLanguageTest, this.test.title + this.invocationCount++, language, {
'kernelspec': {
'name': language,
'display_name': language.toUpperCase()
},
'language_info': {
'name': language,
'version': '',
'mimetype': ''
}
});
});
kernelChanged = await notebook.changeKernel(sqlKernelSpec);
assert(notebook.document.providerId === 'sql', `Expected providerId to be sql, Actual: ${notebook.document.providerId}`);
assert(kernelChanged && notebook.document.kernelSpec.name === 'SQL', `Expected third kernel name: SQL, Actual: ${notebook.document.kernelSpec.name}`);
}
async shouldNotBeDirtyAfterSavingNotebookTest(title: string): Promise<void> {
// TODO: Need to make this test more reliable.
test('should not be dirty after saving notebook test @UNSTABLE@', async function () {
// Given a notebook that's been edited (in this case, open notebook runs the 1st cell and adds an output)
let notebook = await this.openNotebook(sqlNotebookContent, sqlKernelMetadata, title);
await this.runCell(notebook);
let notebook = await openNotebook(sqlNotebookContent, sqlKernelMetadata, this.test.title);
await runCell(notebook);
assert(notebook.document.providerId === 'sql', `Expected providerId to be sql, Actual: ${notebook.document.providerId}`);
assert(notebook.document.kernelSpec.name === 'SQL', `Expected first kernel name: SQL, Actual: ${notebook.document.kernelSpec.name}`);
assert(notebook.document.isDirty === true, 'Notebook should be dirty after edit');
@@ -262,27 +162,75 @@ class NotebookTester {
await sleep(100);
assert(saved === true, 'Expect save after edit to succeed');
assert(notebook.document.isDirty === false, 'Notebook should not be dirty after 2nd save');
});
}
if (process.env['RUN_PYTHON3_TEST'] === '1') {
test('Python3 notebook test', async function () {
let notebook = await openNotebook(pySparkNotebookContent, pythonKernelMetadata, this.test.title + this.invocationCount++);
await runCell(notebook);
let cellOutputs = notebook.document.cells[0].contents.outputs;
console.log('Got cell outputs ---');
if (cellOutputs) {
cellOutputs.forEach(o => console.log(JSON.stringify(o, undefined, '\t')));
}
let result = (<azdata.nb.IExecuteResult>cellOutputs[0]).data['text/plain'];
assert(result === '2', `Expected python result: 2, Actual: ${result}`);
});
async pythonChangeKernelDifferentProviderTest(title: string): Promise<void> {
let notebook = await this.openNotebook(pySparkNotebookContent, pythonKernelMetadata, title);
await this.runCell(notebook);
assert(notebook.document.providerId === 'jupyter', `Expected providerId to be jupyter, Actual: ${notebook.document.providerId}`);
assert(notebook.document.kernelSpec.name === 'python3', `Expected first kernel name: python3, Actual: ${notebook.document.kernelSpec.name}`);
test('Clear all outputs - Python3 notebook ', async function () {
let notebook = await openNotebook(pySparkNotebookContent, pythonKernelMetadata, this.test.title + this.invocationCount++);
await runCell(notebook);
await verifyClearAllOutputs(notebook);
});
let kernelChanged = await notebook.changeKernel(sqlKernelSpec);
assert(notebook.document.providerId === 'sql', `Expected providerId to be sql, Actual: ${notebook.document.providerId}`);
assert(kernelChanged && notebook.document.kernelSpec.name === 'SQL', `Expected second kernel name: SQL, Actual: ${notebook.document.kernelSpec.name}`);
test('python language test', async function () {
let language = 'python';
await cellLanguageTest(notebookContentForCellLanguageTest, this.test.title + this.invocationCount++, language, {
'kernelspec': {
'name': 'python3',
'display_name': 'Python 3'
},
'language_info': {
'name': language,
'version': '',
'mimetype': ''
}
});
});
kernelChanged = await notebook.changeKernel(pythonKernelSpec);
assert(notebook.document.providerId === 'jupyter', `Expected providerId to be jupyter, Actual: ${notebook.document.providerId}`);
assert(kernelChanged && notebook.document.kernelSpec.name === 'python3', `Expected third kernel name: python3, Actual: ${notebook.document.kernelSpec.name}`);
}
test('Change kernel different provider SQL to Python to SQL', async function () {
let notebook = await openNotebook(sqlNotebookContent, sqlKernelMetadata, this.test.title);
await runCell(notebook);
assert(notebook.document.providerId === 'sql', `Expected providerId to be sql, Actual: ${notebook.document.providerId}`);
assert(notebook.document.kernelSpec.name === 'SQL', `Expected first kernel name: SQL, Actual: ${notebook.document.kernelSpec.name}`);
async pythonChangeKernelSameProviderTest(title: string): Promise<void> {
let notebook = await this.openNotebook(pySparkNotebookContent, pythonKernelMetadata, title);
await this.runCell(notebook);
let kernelChanged = await notebook.changeKernel(pythonKernelSpec);
assert(notebook.document.providerId === 'jupyter', `Expected providerId to be jupyter, Actual: ${notebook.document.providerId}`);
assert(kernelChanged && notebook.document.kernelSpec.name === 'python3', `Expected second kernel name: python3, Actual: ${notebook.document.kernelSpec.name}`);
kernelChanged = await notebook.changeKernel(sqlKernelSpec);
assert(notebook.document.providerId === 'sql', `Expected providerId to be sql, Actual: ${notebook.document.providerId}`);
assert(kernelChanged && notebook.document.kernelSpec.name === 'SQL', `Expected third kernel name: SQL, Actual: ${notebook.document.kernelSpec.name}`);
});
test('Change kernel different provider Python to SQL to Python', async function () {
let notebook = await openNotebook(pySparkNotebookContent, pythonKernelMetadata, this.test.title);
await runCell(notebook);
assert(notebook.document.providerId === 'jupyter', `Expected providerId to be jupyter, Actual: ${notebook.document.providerId}`);
assert(notebook.document.kernelSpec.name === 'python3', `Expected first kernel name: python3, Actual: ${notebook.document.kernelSpec.name}`);
let kernelChanged = await notebook.changeKernel(sqlKernelSpec);
assert(notebook.document.providerId === 'sql', `Expected providerId to be sql, Actual: ${notebook.document.providerId}`);
assert(kernelChanged && notebook.document.kernelSpec.name === 'SQL', `Expected second kernel name: SQL, Actual: ${notebook.document.kernelSpec.name}`);
kernelChanged = await notebook.changeKernel(pythonKernelSpec);
assert(notebook.document.providerId === 'jupyter', `Expected providerId to be jupyter, Actual: ${notebook.document.providerId}`);
assert(kernelChanged && notebook.document.kernelSpec.name === 'python3', `Expected third kernel name: python3, Actual: ${notebook.document.kernelSpec.name}`);
});
test('Change kernel same provider Python to PySpark to Python', async function () {
let notebook = await openNotebook(pySparkNotebookContent, pythonKernelMetadata, this.test.title);
await runCell(notebook);
assert(notebook.document.providerId === 'jupyter', `Expected providerId to be jupyter, Actual: ${notebook.document.providerId}`);
assert(notebook.document.kernelSpec.name === 'python3', `Expected first kernel name: python3, Actual: ${notebook.document.kernelSpec.name}`);
@@ -293,11 +241,23 @@ class NotebookTester {
kernelChanged = await notebook.changeKernel(pythonKernelSpec);
assert(notebook.document.providerId === 'jupyter', `Expected providerId to be jupyter, Actual: ${notebook.document.providerId}`);
assert(kernelChanged && notebook.document.kernelSpec.name === 'python3', `Expected third kernel name: python3, Actual: ${notebook.document.kernelSpec.name}`);
});
}
async scalaLanguageTest(title: string): Promise<void> {
if (process.env['RUN_PYSPARK_TEST'] === '1') {
test('PySpark notebook test', async function () {
let notebook = await openNotebook(pySparkNotebookContent, pySparkKernelMetadata, this.test.title + this.invocationCount++);
await runCell(notebook);
let cellOutputs = notebook.document.cells[0].contents.outputs;
let sparkResult = (<azdata.nb.IStreamResult>cellOutputs[3]).text;
assert(sparkResult === '2', `Expected spark result: 2, Actual: ${sparkResult}`);
});
}
/* After https://github.com/microsoft/azuredatastudio/issues/5598 is fixed, enable these tests.
test('scala language test', async function () {
let language = 'scala';
await this.cellLanguageTest(notebookContentForCellLanguageTest, title + this.invocationCount++, language, {
await cellLanguageTest(notebookContentForCellLanguageTest, this.test.title + this.invocationCount++, language, {
'kernelspec': {
'name': '',
'display_name': ''
@@ -308,26 +268,11 @@ class NotebookTester {
mimetype: ''
}
});
}
});
async cplusplusLanguageTest(title: string): Promise<void> {
let language = 'cplusplus';
await this.cellLanguageTest(notebookContentForCellLanguageTest, title + this.invocationCount++, language, {
'kernelspec': {
'name': '',
'display_name': ''
},
'language_info': {
name: language,
version: '',
mimetype: ''
}
});
}
async emptyLanguageTest(title: string): Promise<void> {
test('empty language test', async function () {
let language = '';
await this.cellLanguageTest(notebookContentForCellLanguageTest, title + this.invocationCount++, language, {
await cellLanguageTest(notebookContentForCellLanguageTest, this.test.title + this.invocationCount++, language, {
'kernelspec': {
'name': language,
'display_name': ''
@@ -338,124 +283,93 @@ class NotebookTester {
mimetype: 'x-scala'
}
});
}
});
async sqlLanguageTest(title: string): Promise<void> {
let language = 'sql';
await this.cellLanguageTest(notebookContentForCellLanguageTest, title + this.invocationCount++, language, {
test('cplusplus language test', async function () {
let language = 'cplusplus';
await cellLanguageTest(notebookContentForCellLanguageTest, this.test.title + this.invocationCount++, language, {
'kernelspec': {
'name': language,
'display_name': language.toUpperCase()
'name': '',
'display_name': ''
},
'language_info': {
'name': language,
'version': '',
'mimetype': ''
name: language,
version: '',
mimetype: ''
}
});
}
});
*/
});
async pythonLanguageTest(title: string): Promise<void> {
let language = 'python';
await this.cellLanguageTest(notebookContentForCellLanguageTest, title + this.invocationCount++, language, {
'kernelspec': {
'name': 'python3',
'display_name': 'Python 3'
},
'language_info': {
'name': language,
'version': '',
'mimetype': ''
}
});
async function openNotebook(content: azdata.nb.INotebookContents, kernelMetadata: any, testName: string, connectToDifferentServer?: boolean): Promise<azdata.nb.NotebookEditor> {
let notebookConfig = vscode.workspace.getConfiguration('notebook');
notebookConfig.update('pythonPath', getConfigValue(EnvironmentVariable_PYTHON_PATH), 1);
let server: TestServerProfile;
if (!connectToDifferentServer) {
server = await getStandaloneServer();
assert(server && server.serverName, 'No server could be found in openNotebook');
await connectToServer(server, 6000);
}
async cleanup(testName: string): Promise<void> {
try {
let fileName = getFileName(testName + this.invocationCount++);
if (await promisify(fs.exists)(fileName)) {
await fs.promises.unlink(fileName);
console.log(`"${fileName}" is deleted.`);
}
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
}
catch (err) {
console.log(err);
}
finally {
console.log(`"${testName}" is done`);
}
}
async openNotebook(content: azdata.nb.INotebookContents, kernelMetadata: any, testName: string, connectToDifferentServer?: boolean): Promise<azdata.nb.NotebookEditor> {
let notebookConfig = vscode.workspace.getConfiguration('notebook');
notebookConfig.update('pythonPath', getConfigValue(EnvironmentVariable_PYTHON_PATH), 1);
let server: TestServerProfile;
if (!connectToDifferentServer) {
server = await getStandaloneServer();
assert(server && server.serverName, 'No server could be found in openNotebook');
await connectToServer(server, 6000);
}
let notebookJson = Object.assign({}, content, { metadata: kernelMetadata });
let uri = writeNotebookToFile(notebookJson, testName);
console.log('Notebook uri ' + uri);
let nbShowOptions: azdata.nb.NotebookShowOptions;
if (server) {
nbShowOptions = { connectionProfile: testServerProfileToIConnectionProfile(server) };
}
let notebook = await azdata.nb.showNotebookDocument(uri, nbShowOptions);
return notebook;
}
async runCells(notebook: azdata.nb.NotebookEditor, runCellsAbove?: boolean, runCellsBelow?: boolean, currentCell?: azdata.nb.NotebookCell) {
assert(notebook !== undefined && notebook !== null, 'Expected notebook object is defined');
let ran;
if (runCellsAbove) {
ran = await notebook.runAllCells(undefined, currentCell);
} else if (runCellsBelow) {
ran = await notebook.runAllCells(currentCell, undefined);
} else {
ran = await notebook.runAllCells();
}
assert(ran, 'Notebook runCell should succeed');
}
async runCell(notebook: azdata.nb.NotebookEditor, cell?: azdata.nb.NotebookCell) {
if (isNullOrUndefined(cell)) {
cell = notebook.document.cells[0];
}
let ran = await notebook.runCell(cell);
assert(ran, 'Notebook runCell should succeed');
}
async verifyClearAllOutputs(notebook: azdata.nb.NotebookEditor): Promise<void> {
let cellWithOutputs = notebook.document.cells.find(cell => cell.contents && cell.contents.outputs && cell.contents.outputs.length > 0);
assert(cellWithOutputs !== undefined, 'Could not find notebook cells with outputs');
console.log('Before clearing cell outputs');
let clearedOutputs = await notebook.clearAllOutputs();
let cells = notebook.document.cells;
cells.forEach(cell => {
assert(cell.contents && cell.contents.outputs && cell.contents.outputs.length === 0, `Expected Output: 0, Actual: '${cell.contents.outputs.length}'`);
});
assert(clearedOutputs, 'Outputs of all the code cells from Python notebook should be cleared');
console.log('After clearing cell outputs');
}
async verifyClearOutputs(notebook: azdata.nb.NotebookEditor): Promise<void> {
let cellWithOutputs = notebook.document.cells[0].contents && notebook.document.cells[0].contents.outputs && notebook.document.cells[0].contents.outputs.length > 0;
assert(cellWithOutputs === true, 'Expected first cell to have outputs');
let clearedOutputs = await notebook.clearOutput(notebook.document.cells[0]);
let firstCell = notebook.document.cells[0];
assert(firstCell.contents && firstCell.contents.outputs && firstCell.contents.outputs.length === 0, `Expected Output: 0, Actual: '${firstCell.contents.outputs.length}'`);
assert(clearedOutputs, 'Outputs of requested code cell should be cleared');
}
async cellLanguageTest(content: azdata.nb.INotebookContents, testName: string, languageConfigured: string, metadataInfo: any) {
let notebookJson = Object.assign({}, content, { metadata: metadataInfo });
let uri = writeNotebookToFile(notebookJson, testName);
let notebook = await azdata.nb.showNotebookDocument(uri);
await notebook.document.save();
let languageInNotebook = notebook.document.cells[0].contents.metadata.language;
assert(languageInNotebook === languageConfigured, `Expected cell language is: ${languageConfigured}, Actual: ${languageInNotebook}`);
let notebookJson = Object.assign({}, content, { metadata: kernelMetadata });
let uri = writeNotebookToFile(notebookJson, testName);
console.log('Notebook uri ' + uri);
let nbShowOptions: azdata.nb.NotebookShowOptions;
if (server) {
nbShowOptions = { connectionProfile: testServerProfileToIConnectionProfile(server) };
}
let notebook = await azdata.nb.showNotebookDocument(uri, nbShowOptions);
return notebook;
}
async function runCells(notebook: azdata.nb.NotebookEditor, runCellsAbove?: boolean, runCellsBelow?: boolean, currentCell?: azdata.nb.NotebookCell) {
assert(notebook !== undefined && notebook !== null, 'Expected notebook object is defined');
let ran;
if (runCellsAbove) {
ran = await notebook.runAllCells(undefined, currentCell);
} else if (runCellsBelow) {
ran = await notebook.runAllCells(currentCell, undefined);
} else {
ran = await notebook.runAllCells();
}
assert(ran, 'Notebook runCell should succeed');
}
async function runCell(notebook: azdata.nb.NotebookEditor, cell?: azdata.nb.NotebookCell) {
if (isNullOrUndefined(cell)) {
cell = notebook.document.cells[0];
}
let ran = await notebook.runCell(cell);
assert(ran, 'Notebook runCell should succeed');
}
async function verifyClearAllOutputs(notebook: azdata.nb.NotebookEditor): Promise<void> {
let cellWithOutputs = notebook.document.cells.find(cell => cell.contents && cell.contents.outputs && cell.contents.outputs.length > 0);
assert(cellWithOutputs !== undefined, 'Could not find notebook cells with outputs');
console.log('Before clearing cell outputs');
let clearedOutputs = await notebook.clearAllOutputs();
let cells = notebook.document.cells;
cells.forEach(cell => {
assert(cell.contents && cell.contents.outputs && cell.contents.outputs.length === 0, `Expected Output: 0, Actual: '${cell.contents.outputs.length}'`);
});
assert(clearedOutputs, 'Outputs of all the code cells from Python notebook should be cleared');
console.log('After clearing cell outputs');
}
async function verifyClearOutputs(notebook: azdata.nb.NotebookEditor): Promise<void> {
let cellWithOutputs = notebook.document.cells[0].contents && notebook.document.cells[0].contents.outputs && notebook.document.cells[0].contents.outputs.length > 0;
assert(cellWithOutputs === true, 'Expected first cell to have outputs');
let clearedOutputs = await notebook.clearOutput(notebook.document.cells[0]);
let firstCell = notebook.document.cells[0];
assert(firstCell.contents && firstCell.contents.outputs && firstCell.contents.outputs.length === 0, `Expected Output: 0, Actual: '${firstCell.contents.outputs.length}'`);
assert(clearedOutputs, 'Outputs of requested code cell should be cleared');
}
async function cellLanguageTest(content: azdata.nb.INotebookContents, testName: string, languageConfigured: string, metadataInfo: any) {
let notebookJson = Object.assign({}, content, { metadata: metadataInfo });
let uri = writeNotebookToFile(notebookJson, testName);
let notebook = await azdata.nb.showNotebookDocument(uri);
await notebook.document.save();
let languageInNotebook = notebook.document.cells[0].contents.metadata.language;
assert(languageInNotebook === languageConfigured, `Expected cell language is: ${languageConfigured}, Actual: ${languageInNotebook}`);
}

View File

@@ -8,78 +8,26 @@ import * as azdata from 'azdata';
import { getBdcServer, TestServerProfile, getAzureServer, getStandaloneServer } from './testConfig';
import { connectToServer, createDB, deleteDB, DefaultConnectTimeoutInMs, asyncTimeout } from './utils';
import * as assert from 'assert';
import { stressify } from 'adstest';
suite('Object Explorer integration suite', () => {
test.skip('BDC instance node label test', async function () {
return await (new ObjectExplorerTester()).bdcNodeLabelTest();
});
test('Standalone instance node label test', async function () {
return await (new ObjectExplorerTester()).standaloneNodeLabelTest();
});
test('Azure SQL DB instance node label test @UNSTABLE@', async function () {
return await (new ObjectExplorerTester()).sqlDbNodeLabelTest();
});
test.skip('BDC instance context menu test', async function () {
return await (new ObjectExplorerTester()).bdcContextMenuTest();
});
test('Azure SQL DB context menu test @UNSTABLE@', async function () {
return await (new ObjectExplorerTester()).sqlDbContextMenuTest();
});
test('Standalone database context menu test', async function () {
return await (new ObjectExplorerTester()).standaloneContextMenuTest();
});
});
class ObjectExplorerTester {
private static ParallelCount = 1;
@stressify({ dop: ObjectExplorerTester.ParallelCount })
async bdcNodeLabelTest(): Promise<void> {
const expectedNodeLabel = ['Databases', 'Security', 'Server Objects'];
const server = await getBdcServer();
return await this.verifyOeNode(server, DefaultConnectTimeoutInMs, expectedNodeLabel);
}
@stressify({ dop: ObjectExplorerTester.ParallelCount })
async standaloneNodeLabelTest(): Promise<void> {
await verifyOeNode(server, DefaultConnectTimeoutInMs, expectedNodeLabel);
});
test('Standalone instance node label test', async function () {
if (process.platform === 'win32') {
const expectedNodeLabel = ['Databases', 'Security', 'Server Objects'];
const server = await getStandaloneServer();
return await this.verifyOeNode(server, DefaultConnectTimeoutInMs, expectedNodeLabel);
await verifyOeNode(server, DefaultConnectTimeoutInMs, expectedNodeLabel);
}
}
@stressify({ dop: ObjectExplorerTester.ParallelCount })
async sqlDbNodeLabelTest(): Promise<void> {
});
test('Azure SQL DB instance node label test @UNSTABLE@', async function () {
const expectedNodeLabel = ['Databases', 'Security'];
const server = await getAzureServer();
return await this.verifyOeNode(server, DefaultConnectTimeoutInMs, expectedNodeLabel);
}
@stressify({ dop: ObjectExplorerTester.ParallelCount })
async sqlDbContextMenuTest(): Promise<void> {
const server = await getAzureServer();
const expectedActions = ['Manage', 'New Query', 'New Notebook', 'Disconnect', 'Delete Connection', 'Refresh', 'Data-tier Application wizard', 'Launch Profiler'];
return await this.verifyContextMenu(server, expectedActions);
}
@stressify({ dop: ObjectExplorerTester.ParallelCount })
async standaloneContextMenuTest(): Promise<void> {
const server = await getStandaloneServer();
let expectedActions: string[] = [];
// Generate Scripts and Properties come from the admin-tool-ext-win extension which is for Windows only, so the item won't show up on non-Win32 platforms
if (process.platform === 'win32') {
expectedActions = ['Manage', 'New Query', 'New Notebook', 'Refresh', 'Backup', 'Restore', 'Data-tier Application wizard', 'Schema Compare', 'Import wizard', 'Generate Scripts...', 'Properties'];
}
else {
expectedActions = ['Manage', 'New Query', 'New Notebook', 'Refresh', 'Backup', 'Restore', 'Data-tier Application wizard', 'Schema Compare', 'Import wizard'];
}
return await this.verifyDBContextMenu(server, DefaultConnectTimeoutInMs, expectedActions);
}
@stressify({ dop: ObjectExplorerTester.ParallelCount })
async bdcContextMenuTest(): Promise<void> {
await verifyOeNode(server, DefaultConnectTimeoutInMs, expectedNodeLabel);
});
test.skip('BDC instance context menu test', async function () {
const server = await getBdcServer();
let expectedActions: string[];
// Properties comes from the admin-tool-ext-win extension which is for Windows only, so the item won't show up on non-Win32 platforms
@@ -89,80 +37,99 @@ class ObjectExplorerTester {
else {
expectedActions = ['Manage', 'New Query', 'New Notebook', 'Disconnect', 'Delete Connection', 'Refresh', 'Data-tier Application wizard', 'Launch Profiler'];
}
return await this.verifyContextMenu(server, expectedActions);
return await verifyContextMenu(server, expectedActions);
});
test('Azure SQL DB context menu test @UNSTABLE@', async function () {
const server = await getAzureServer();
const expectedActions = ['Manage', 'New Query', 'New Notebook', 'Disconnect', 'Delete Connection', 'Refresh', 'Data-tier Application wizard', 'Launch Profiler'];
await verifyContextMenu(server, expectedActions);
});
test('Standalone database context menu test', async function () {
const server = await getStandaloneServer();
let expectedActions: string[] = [];
// Generate Scripts and Properties come from the admin-tool-ext-win extension which is for Windows only, so the item won't show up on non-Win32 platforms
if (process.platform === 'win32') {
expectedActions = ['Manage', 'New Query', 'New Notebook', 'Refresh', 'Backup', 'Restore', 'Data-tier Application wizard', 'Schema Compare', 'Import wizard', 'Generate Scripts...', 'Properties'];
}
else {
expectedActions = ['Manage', 'New Query', 'New Notebook', 'Refresh', 'Backup', 'Restore', 'Data-tier Application wizard', 'Schema Compare', 'Import wizard'];
}
await verifyDBContextMenu(server, DefaultConnectTimeoutInMs, expectedActions);
});
});
async function verifyContextMenu(server: TestServerProfile, expectedActions: string[]): Promise<void> {
await connectToServer(server, DefaultConnectTimeoutInMs);
const nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
assert(nodes.length > 0, `Expecting at least one active connection, actual: ${nodes.length}`);
const index = nodes.findIndex(node => node.nodePath.includes(server.serverName));
assert(index !== -1, `Failed to find server: "${server.serverName}" in OE tree`);
const node = nodes[index];
const actions = await azdata.objectexplorer.getNodeActions(node.connectionId, node.nodePath);
const expectedString = expectedActions.join(',');
const actualString = actions.join(',');
return assert(expectedActions.length === actions.length && expectedString === actualString, `Expected actions: "${expectedString}", Actual actions: "${actualString}"`);
}
async function verifyOeNode(server: TestServerProfile, timeout: number, expectedNodeLabel: string[]): Promise<void> {
await connectToServer(server, timeout);
const nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
assert(nodes.length > 0, `Expecting at least one active connection, actual: ${nodes.length}`);
const index = nodes.findIndex(node => node.nodePath.includes(server.serverName));
assert(index !== -1, `Failed to find server: "${server.serverName}" in OE tree`);
// TODO: #7146 HDFS isn't always filled in by the call to getChildren since it's loaded asynchronously. To avoid this test being flaky just removing
// the node for now if it exists until a proper fix can be made.
let children: azdata.objectexplorer.ObjectExplorerNode[];
try {
children = await asyncTimeout(nodes[index].getChildren(), timeout);
} catch (e) {
return assert.fail('getChildren() timed out...', e);
}
async verifyContextMenu(server: TestServerProfile, expectedActions: string[]): Promise<void> {
await connectToServer(server, DefaultConnectTimeoutInMs);
const nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
assert(nodes.length > 0, `Expecting at least one active connection, actual: ${nodes.length}`);
const nonHDFSChildren = children.filter(c => c.label !== 'HDFS');
const actualLabelsString = nonHDFSChildren.map(c => c.label).join(',');
const expectedLabelString = expectedNodeLabel.join(',');
return assert(expectedNodeLabel.length === nonHDFSChildren.length && expectedLabelString === actualLabelsString, `Expected node label: "${expectedLabelString}", Actual: "${actualLabelsString}"`);
}
const index = nodes.findIndex(node => node.nodePath.includes(server.serverName));
assert(index !== -1, `Failed to find server: "${server.serverName}" in OE tree`);
async function verifyDBContextMenu(server: TestServerProfile, timeoutinMS: number, expectedActions: string[]): Promise<void> {
const node = nodes[index];
const actions = await azdata.objectexplorer.getNodeActions(node.connectionId, node.nodePath);
await connectToServer(server, timeoutinMS);
const nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
assert(nodes.length > 0, `Expecting at least one active connection, actual: ${nodes.length}`);
const index = nodes.findIndex(node => node.nodePath.includes(server.serverName));
assert(index !== -1, `Failed to find server: "${server.serverName}" in OE tree`);
const ownerUri = await azdata.connection.getUriForConnection(nodes[index].connectionId);
const dbName: string = 'ads_test_VerifyDBContextMenu_' + new Date().getTime().toString();
try {
await createDB(dbName, ownerUri);
const serverNode = nodes[index];
const children = await serverNode.getChildren();
assert(children[0].label === 'Databases', `Expected Databases node. Actual ${children[0].label}`);
const databasesFolder = children[0];
const databases = await databasesFolder.getChildren();
assert(databases.length > 2, `No database present, can not test further`); // System Databses folder and at least one database
const actions = await azdata.objectexplorer.getNodeActions(databases[1].connectionId, databases[1].nodePath);
const expectedString = expectedActions.join(',');
const actualString = actions.join(',');
return assert(expectedActions.length === actions.length && expectedString === actualString, `Expected actions: "${expectedString}", Actual actions: "${actualString}"`);
}
async verifyOeNode(server: TestServerProfile, timeout: number, expectedNodeLabel: string[]): Promise<void> {
await connectToServer(server, timeout);
const nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
assert(nodes.length > 0, `Expecting at least one active connection, actual: ${nodes.length}`);
const index = nodes.findIndex(node => node.nodePath.includes(server.serverName));
assert(index !== -1, `Failed to find server: "${server.serverName}" in OE tree`);
// TODO: #7146 HDFS isn't always filled in by the call to getChildren since it's loaded asynchronously. To avoid this test being flaky just removing
// the node for now if it exists until a proper fix can be made.
let children: azdata.objectexplorer.ObjectExplorerNode[];
try {
children = await asyncTimeout(nodes[index].getChildren(), timeout);
} catch (e) {
return assert.fail('getChildren() timed out...', e);
}
const nonHDFSChildren = children.filter(c => c.label !== 'HDFS');
const actualLabelsString = nonHDFSChildren.map(c => c.label).join(',');
const expectedLabelString = expectedNodeLabel.join(',');
return assert(expectedNodeLabel.length === nonHDFSChildren.length && expectedLabelString === actualLabelsString, `Expected node label: "${expectedLabelString}", Actual: "${actualLabelsString}"`);
}
async verifyDBContextMenu(server: TestServerProfile, timeoutinMS: number, expectedActions: string[]): Promise<void> {
await connectToServer(server, timeoutinMS);
const nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
assert(nodes.length > 0, `Expecting at least one active connection, actual: ${nodes.length}`);
const index = nodes.findIndex(node => node.nodePath.includes(server.serverName));
assert(index !== -1, `Failed to find server: "${server.serverName}" in OE tree`);
const ownerUri = await azdata.connection.getUriForConnection(nodes[index].connectionId);
const dbName: string = 'ads_test_VerifyDBContextMenu_' + new Date().getTime().toString();
try {
await createDB(dbName, ownerUri);
const serverNode = nodes[index];
const children = await serverNode.getChildren();
assert(children[0].label === 'Databases', `Expected Databases node. Actual ${children[0].label}`);
const databasesFolder = children[0];
const databases = await databasesFolder.getChildren();
assert(databases.length > 2, `No database present, can not test further`); // System Databses folder and at least one database
const actions = await azdata.objectexplorer.getNodeActions(databases[1].connectionId, databases[1].nodePath);
const expectedString = expectedActions.join(',');
const actualString = actions.join(',');
return assert(expectedActions.length === actions.length && expectedString === actualString, `Expected actions: "${expectedString}", Actual actions: "${actualString}"`);
}
finally {
await deleteDB(server, dbName, ownerUri);
}
finally {
await deleteDB(server, dbName, ownerUri);
}
}

View File

@@ -10,15 +10,13 @@ import * as utils from './utils';
import * as mssql from '../../../mssql';
import * as os from 'os';
import * as fs from 'fs';
const path = require('path');
import * as path from 'path';
import * as assert from 'assert';
import { getStandaloneServer } from './testConfig';
import { stressify } from 'adstest';
import { promisify } from 'util';
let schemaCompareService: mssql.ISchemaCompareService;
let dacfxService: mssql.IDacFxService;
let schemaCompareTester: SchemaCompareTester;
const dacpac1: string = path.join(__dirname, '..', '..', 'testData', 'Database1.dacpac');
const dacpac2: string = path.join(__dirname, '..', '..', 'testData', 'Database2.dacpac');
const includeExcludeSourceDacpac: string = path.join(__dirname, '..', '..', 'testData', 'SchemaCompareIncludeExcludeSource.dacpac');
@@ -39,28 +37,9 @@ suite('Schema compare integration test suite', () => {
await utils.sleep(1000); // To ensure the providers are registered.
}
dacfxService = ((await vscode.extensions.getExtension(mssql.extension.name).activate() as mssql.IExtension)).dacFx;
schemaCompareTester = new SchemaCompareTester();
console.log(`Start schema compare tests`);
});
test('Schema compare dacpac to dacpac comparison and scmp', async function () {
await schemaCompareTester.SchemaCompareDacpacToDacpac();
});
test('Schema compare database to database comparison, script generation, and scmp', async function () {
await schemaCompareTester.SchemaCompareDatabaseToDatabase();
});
test('Schema compare dacpac to database comparison, script generation, and scmp', async function () {
await schemaCompareTester.SchemaCompareDacpacToDatabase();
});
test('Schema compare dacpac to dacpac comparison with include exclude', async function () {
await schemaCompareTester.SchemaCompareIncludeExcludeDacpacToDacpac();
});
});
class SchemaCompareTester {
private static ParallelCount = 1;
@stressify({ dop: SchemaCompareTester.ParallelCount })
async SchemaCompareDacpacToDacpac(): Promise<void> {
assert(schemaCompareService, 'Schema Compare Service Provider is not available');
const now = new Date();
const operationId = 'testOperationId_' + now.getTime().toString();
@@ -85,7 +64,7 @@ class SchemaCompareTester {
};
let schemaCompareResult = await schemaCompareService.schemaCompare(operationId, source, target, azdata.TaskExecutionMode.execute, null);
this.assertSchemaCompareResult(schemaCompareResult, operationId, 4);
assertSchemaCompareResult(schemaCompareResult, operationId, 4);
// save to scmp
const filepath = path.join(folderPath, `ads_schemaCompare_${now.getTime().toString()}.scmp`);
@@ -101,10 +80,8 @@ class SchemaCompareTester {
assert(openScmpResult.success && !openScmpResult.errorMessage, `Open scmp should succeed. Expected: there should be no error. Actual Error message: "${openScmpResult.errorMessage}`);
assert(openScmpResult.sourceEndpointInfo.packageFilePath === source.packageFilePath, `Expected: source packageFilePath to be ${source.packageFilePath}, Actual: ${openScmpResult.sourceEndpointInfo.packageFilePath}`);
assert(openScmpResult.targetEndpointInfo.packageFilePath === target.packageFilePath, `Expected: target packageFilePath to be ${target.packageFilePath}, Actual: ${openScmpResult.targetEndpointInfo.packageFilePath}`);
}
@stressify({ dop: SchemaCompareTester.ParallelCount })
async SchemaCompareDatabaseToDatabase(): Promise<void> {
});
test('Schema compare database to database comparison, script generation, and scmp', async function () {
let server = await getStandaloneServer();
await utils.connectToServer(server, SERVER_CONNECTION_TIMEOUT);
@@ -153,13 +130,13 @@ class SchemaCompareTester {
};
let schemaCompareResult = await schemaCompareService.schemaCompare(operationId, source, target, azdata.TaskExecutionMode.execute, null);
this.assertSchemaCompareResult(schemaCompareResult, operationId, 4);
assertSchemaCompareResult(schemaCompareResult, operationId, 4);
let status = await schemaCompareService.schemaCompareGenerateScript(schemaCompareResult.operationId, server.serverName, targetDB, azdata.TaskExecutionMode.script);
// TODO : add wait for tasks to complete
// script generation might take too long and the 'success' status does not mean that script is created.
await this.assertScriptGenerationResult(status, target.serverName, target.databaseName);
await assertScriptGenerationResult(status, target.serverName, target.databaseName);
// save to scmp
const filepath = path.join(folderPath, `ads_schemaCompare_${now.getTime().toString()}.scmp`);
@@ -182,10 +159,8 @@ class SchemaCompareTester {
await utils.deleteDB(server, sourceDB, ownerUri);
await utils.deleteDB(server, targetDB, ownerUri);
}
}
@stressify({ dop: SchemaCompareTester.ParallelCount })
async SchemaCompareDacpacToDatabase(): Promise<void> {
});
test('Schema compare dacpac to database comparison, script generation, and scmp', async function () {
let server = await getStandaloneServer();
await utils.connectToServer(server, SERVER_CONNECTION_TIMEOUT);
@@ -228,10 +203,10 @@ class SchemaCompareTester {
assert(schemaCompareService, 'Schema Compare Service Provider is not available');
let schemaCompareResult = await schemaCompareService.schemaCompare(operationId, source, target, azdata.TaskExecutionMode.execute, null);
this.assertSchemaCompareResult(schemaCompareResult, operationId, 4);
assertSchemaCompareResult(schemaCompareResult, operationId, 4);
let status = await schemaCompareService.schemaCompareGenerateScript(schemaCompareResult.operationId, server.serverName, targetDB, azdata.TaskExecutionMode.script);
await this.assertScriptGenerationResult(status, target.serverName, target.databaseName);
await assertScriptGenerationResult(status, target.serverName, target.databaseName);
// save to scmp
const filepath = path.join(folderPath, `ads_schemaCompare_${now.getTime().toString()}.scmp`);
@@ -251,10 +226,8 @@ class SchemaCompareTester {
finally {
await utils.deleteDB(server, targetDB, ownerUri);
}
}
@stressify({ dop: SchemaCompareTester.ParallelCount })
async SchemaCompareIncludeExcludeDacpacToDacpac(): Promise<void> {
});
test('Schema compare dacpac to dacpac comparison with include exclude', async function () {
assert(schemaCompareService, 'Schema Compare Service Provider is not available');
const operationId = 'testOperationId_' + new Date().getTime().toString();
@@ -280,26 +253,26 @@ class SchemaCompareTester {
const deploymentOptionsResult = await schemaCompareService.schemaCompareGetDefaultOptions();
let deploymentOptions = deploymentOptionsResult.defaultDeploymentOptions;
const schemaCompareResult = await schemaCompareService.schemaCompare(operationId, source, target, azdata.TaskExecutionMode.execute, deploymentOptions);
this.assertSchemaCompareResult(schemaCompareResult, operationId, 5);
assertSchemaCompareResult(schemaCompareResult, operationId, 5);
// try to exclude table t2 and it should fail because a dependency is still included
const t2Difference = schemaCompareResult.differences.find(e => e.sourceValue && e.sourceValue[1] === 't2' && e.name === 'SqlTable');
assert(t2Difference !== undefined, 'The difference Table t2 should be found. Should not be undefined');
const excludeResult = await schemaCompareService.schemaCompareIncludeExcludeNode(operationId, t2Difference, false, azdata.TaskExecutionMode.execute);
this.assertIncludeExcludeResult(excludeResult, false, 1, 0);
assertIncludeExcludeResult(excludeResult, false, 1, 0);
assert(excludeResult.blockingDependencies[0].sourceValue[1] === 'v1', `Blocking dependency should be view v1. Actual: ${excludeResult.blockingDependencies[0].sourceValue[1]}`);
// Exclude the view v1 that t2 was a dependency for and it should succeed and t2 should also be excluded
const v1Difference = schemaCompareResult.differences.find(e => e.sourceValue && e.sourceValue[1] === 'v1' && e.name === 'SqlView');
assert(v1Difference !== undefined, 'The difference View v1 should be found. Should not be undefined');
const excludeResult2 = await schemaCompareService.schemaCompareIncludeExcludeNode(operationId, v1Difference, false, azdata.TaskExecutionMode.execute);
this.assertIncludeExcludeResult(excludeResult2, true, 0, 1);
assertIncludeExcludeResult(excludeResult2, true, 0, 1);
assert(excludeResult2.affectedDependencies[0].sourceValue[1] === 't2', `Table t2 should be the affected dependency. Actual: ${excludeResult2.affectedDependencies[0].sourceValue[1]}`);
assert(excludeResult2.affectedDependencies[0].included === false, 'Table t2 should be excluded as a result of excluding v1. Actual: true');
// including the view v1 should also include the table t2
const includeResult = await schemaCompareService.schemaCompareIncludeExcludeNode(operationId, v1Difference, true, azdata.TaskExecutionMode.execute);
this.assertIncludeExcludeResult(includeResult, true, 0, 1);
assertIncludeExcludeResult(includeResult, true, 0, 1);
assert(includeResult.affectedDependencies[0].sourceValue[1] === 't2', `Table t2 should be the affected dependency. Actual: ${includeResult.affectedDependencies[0].sourceValue[1]}`);
assert(includeResult.affectedDependencies[0].included === true, 'Table t2 should be included as a result of including v1. Actual: false');
@@ -307,62 +280,62 @@ class SchemaCompareTester {
deploymentOptions.excludeObjectTypes.push(mssql.SchemaObjectType.Views);
await schemaCompareService.schemaCompare(operationId, source, target, azdata.TaskExecutionMode.execute, deploymentOptions);
const excludeResult3 = await schemaCompareService.schemaCompareIncludeExcludeNode(operationId, t2Difference, false, azdata.TaskExecutionMode.execute);
this.assertIncludeExcludeResult(excludeResult3, true, 0, 0);
assertIncludeExcludeResult(excludeResult3, true, 0, 0);
});
});
function assertIncludeExcludeResult(result: mssql.SchemaCompareIncludeExcludeResult, expectedSuccess: boolean, expectedBlockingDependenciesLength: number, expectedAffectedDependenciesLength: number): void {
assert(result.success === expectedSuccess, `Operation success should have been ${expectedSuccess}. Actual: ${result.success}`);
if (result.blockingDependencies) {
assert(result.blockingDependencies.length === expectedBlockingDependenciesLength, `Expected ${expectedBlockingDependenciesLength} blocking dependencies. Actual: ${result.blockingDependencies}`);
} else if (expectedBlockingDependenciesLength !== 0) {
throw new Error(`ExpectedBlockingDependencies length was ${expectedBlockingDependenciesLength} but blockingDependencies was undefined`);
}
private assertIncludeExcludeResult(result: mssql.SchemaCompareIncludeExcludeResult, expectedSuccess: boolean, expectedBlockingDependenciesLength: number, expectedAffectedDependenciesLength: number): void {
assert(result.success === expectedSuccess, `Operation success should have been ${expectedSuccess}. Actual: ${result.success}`);
if (result.blockingDependencies) {
assert(result.blockingDependencies.length === expectedBlockingDependenciesLength, `Expected ${expectedBlockingDependenciesLength} blocking dependencies. Actual: ${result.blockingDependencies}`);
} else if (expectedBlockingDependenciesLength !== 0) {
throw new Error(`ExpectedBlockingDependencies length was ${expectedBlockingDependenciesLength} but blockingDependencies was undefined`);
}
if (result.affectedDependencies) {
assert(result.affectedDependencies.length === expectedAffectedDependenciesLength, `Expected ${expectedAffectedDependenciesLength} affected dependencies. Actual: ${result.affectedDependencies}`);
} else if (expectedAffectedDependenciesLength !== 0) {
throw new Error(`ExpectedAffectedDependencies length was ${expectedAffectedDependenciesLength} but affectedDependencies was undefined`);
}
}
private assertSchemaCompareResult(schemaCompareResult: mssql.SchemaCompareResult, operationId: string, expectedDifferenceCount: number): void {
assert(schemaCompareResult.areEqual === false, `Expected: the schemas are not to be equal Actual: Equal`);
assert(schemaCompareResult.errorMessage === null, `Expected: there should be no error. Actual Error message: "${schemaCompareResult.errorMessage}"`);
assert(schemaCompareResult.success === true, `Expected: success in schema compare, Actual: Failure`);
assert(schemaCompareResult.differences.length === expectedDifferenceCount, `Expected: ${expectedDifferenceCount} differences. Actual differences: "${schemaCompareResult.differences.length}"`);
assert(schemaCompareResult.operationId === operationId, `Operation Id Expected to be same as passed. Expected : ${operationId}, Actual ${schemaCompareResult.operationId}`);
}
private async assertScriptGenerationResult(resultstatus: azdata.ResultStatus, server: string, database: string): Promise<void> {
// TODO add more validation
assert(resultstatus.success === true, `Expected: success true Actual: "${resultstatus.success}" Error Message: "${resultstatus.errorMessage}`);
const taskService = azdata.dataprotocol.getProvider<azdata.TaskServicesProvider>('MSSQL', azdata.DataProviderType.TaskServicesProvider);
const tasks = await taskService.getAllTasks({ listActiveTasksOnly: true });
let foundTask: azdata.TaskInfo;
tasks.tasks.forEach(t => {
if (t.serverName === server && t.databaseName === database && t.taskExecutionMode === azdata.TaskExecutionMode.script) {
foundTask = t;
}
});
assert(foundTask, 'Could not find Script task');
assert(foundTask.isCancelable, 'The task should be cancellable');
if (foundTask.status !== azdata.TaskStatus.Succeeded) {
// wait for all tasks completion before exiting test and cleaning up db otherwise tasks fail
let retry = 10;
let allCompleted = false;
while (retry > 0 && !allCompleted) {
retry--;
await utils.sleep(1000);
allCompleted = true;
let tasks = await taskService.getAllTasks({ listActiveTasksOnly: true });
tasks.tasks.forEach(t => {
if (t.status !== azdata.TaskStatus.Succeeded) {
allCompleted = false;
}
});
}
// TODO: add proper validation for task completion to ensure all tasks successfully complete before exiting test
assert(tasks !== null && tasks.tasks.length > 0, 'Tasks should still show in list. This is to ensure that the tasks actually complete.');
}
if (result.affectedDependencies) {
assert(result.affectedDependencies.length === expectedAffectedDependenciesLength, `Expected ${expectedAffectedDependenciesLength} affected dependencies. Actual: ${result.affectedDependencies}`);
} else if (expectedAffectedDependenciesLength !== 0) {
throw new Error(`ExpectedAffectedDependencies length was ${expectedAffectedDependenciesLength} but affectedDependencies was undefined`);
}
}
function assertSchemaCompareResult(schemaCompareResult: mssql.SchemaCompareResult, operationId: string, expectedDifferenceCount: number): void {
assert(schemaCompareResult.areEqual === false, `Expected: the schemas are not to be equal Actual: Equal`);
assert(schemaCompareResult.errorMessage === null, `Expected: there should be no error. Actual Error message: "${schemaCompareResult.errorMessage}"`);
assert(schemaCompareResult.success === true, `Expected: success in schema compare, Actual: Failure`);
assert(schemaCompareResult.differences.length === expectedDifferenceCount, `Expected: ${expectedDifferenceCount} differences. Actual differences: "${schemaCompareResult.differences.length}"`);
assert(schemaCompareResult.operationId === operationId, `Operation Id Expected to be same as passed. Expected : ${operationId}, Actual ${schemaCompareResult.operationId}`);
}
async function assertScriptGenerationResult(resultstatus: azdata.ResultStatus, server: string, database: string): Promise<void> {
// TODO add more validation
assert(resultstatus.success === true, `Expected: success true Actual: "${resultstatus.success}" Error Message: "${resultstatus.errorMessage}`);
const taskService = azdata.dataprotocol.getProvider<azdata.TaskServicesProvider>('MSSQL', azdata.DataProviderType.TaskServicesProvider);
const tasks = await taskService.getAllTasks({ listActiveTasksOnly: true });
let foundTask: azdata.TaskInfo;
tasks.tasks.forEach(t => {
if (t.serverName === server && t.databaseName === database && t.taskExecutionMode === azdata.TaskExecutionMode.script) {
foundTask = t;
}
});
assert(foundTask, 'Could not find Script task');
assert(foundTask.isCancelable, 'The task should be cancellable');
if (foundTask.status !== azdata.TaskStatus.Succeeded) {
// wait for all tasks completion before exiting test and cleaning up db otherwise tasks fail
let retry = 10;
let allCompleted = false;
while (retry > 0 && !allCompleted) {
retry--;
await utils.sleep(1000);
allCompleted = true;
let tasks = await taskService.getAllTasks({ listActiveTasksOnly: true });
tasks.tasks.forEach(t => {
if (t.status !== azdata.TaskStatus.Succeeded) {
allCompleted = false;
}
});
}
// TODO: add proper validation for task completion to ensure all tasks successfully complete before exiting test
assert(tasks !== null && tasks.tasks.length > 0, 'Tasks should still show in list. This is to ensure that the tasks actually complete.');
}
}