mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Fixed Schema compare integration tests by adding retry (#13649)
This commit is contained in:
@@ -17,19 +17,21 @@ import { promisify } from 'util';
|
|||||||
|
|
||||||
const retryCount = 24; // 2 minutes
|
const retryCount = 24; // 2 minutes
|
||||||
const dacpac1: string = path.join(__dirname, '../../testData/Database1.dacpac');
|
const dacpac1: string = path.join(__dirname, '../../testData/Database1.dacpac');
|
||||||
suite('Dacpac integration test suite', () => {
|
|
||||||
|
|
||||||
|
suite('Dacpac integration test suite @DacFx@', () => {
|
||||||
suiteSetup(async function () {
|
suiteSetup(async function () {
|
||||||
await utils.sleep(5000); // To ensure the providers are registered.
|
await utils.sleep(5000); // To ensure the providers are registered.
|
||||||
console.log(`Start dacpac tests`);
|
console.log(`Start dacpac tests`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Deploy and extract dacpac @UNSTABLE@', async function () {
|
test('Deploy and extract dacpac @UNSTABLE@', async function () {
|
||||||
|
this.timeout(5 * 60 * 1000);
|
||||||
const server = await getStandaloneServer();
|
const server = await getStandaloneServer();
|
||||||
await utils.connectToServer(server);
|
const connectionId = await utils.connectToServer(server);
|
||||||
|
assert(connectionId, `Failed to connect to "${server.serverName}"`);
|
||||||
|
|
||||||
const nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
|
const ownerUri = await azdata.connection.getUriForConnection(connectionId);
|
||||||
const index = nodes.findIndex(node => node.nodePath.includes(server.serverName));
|
|
||||||
const ownerUri = await azdata.connection.getUriForConnection(nodes[index].connectionId);
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const databaseName = 'ADS_deployDacpac_' + now.getTime().toString();
|
const databaseName = 'ADS_deployDacpac_' + now.getTime().toString();
|
||||||
|
|
||||||
@@ -70,12 +72,13 @@ suite('Dacpac integration test suite', () => {
|
|||||||
|
|
||||||
const bacpac1: string = path.join(__dirname, '..', '..', 'testData', 'Database1.bacpac');
|
const bacpac1: string = path.join(__dirname, '..', '..', 'testData', 'Database1.bacpac');
|
||||||
test('Import and export bacpac @UNSTABLE@', async function () {
|
test('Import and export bacpac @UNSTABLE@', async function () {
|
||||||
|
this.timeout(5 * 60 * 1000);
|
||||||
const server = await getStandaloneServer();
|
const server = await getStandaloneServer();
|
||||||
await utils.connectToServer(server);
|
await utils.connectToServer(server);
|
||||||
|
|
||||||
const nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
|
const connectionId = await utils.connectToServer(server);
|
||||||
const index = nodes.findIndex(node => node.nodePath.includes(server.serverName));
|
assert(connectionId, `Failed to connect to "${server.serverName}"`);
|
||||||
const ownerUri = await azdata.connection.getUriForConnection(nodes[index].connectionId);
|
const ownerUri = await azdata.connection.getUriForConnection(connectionId);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const databaseName = 'ADS_importBacpac_' + now.getTime().toString();
|
const databaseName = 'ADS_importBacpac_' + now.getTime().toString();
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import * as os from 'os';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import { getStandaloneServer } from './testConfig';
|
import { getStandaloneServer, TestServerProfile } from './testConfig';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
|
||||||
let schemaCompareService: mssql.ISchemaCompareService;
|
let schemaCompareService: mssql.ISchemaCompareService;
|
||||||
@@ -25,7 +25,7 @@ const SERVER_CONNECTION_TIMEOUT: number = 3000;
|
|||||||
const retryCount = 24; // 2 minutes
|
const retryCount = 24; // 2 minutes
|
||||||
const folderPath = path.join(os.tmpdir(), 'SchemaCompareTest');
|
const folderPath = path.join(os.tmpdir(), 'SchemaCompareTest');
|
||||||
|
|
||||||
suite('Schema compare integration test suite', () => {
|
suite('Schema compare integration test suite @DacFx@', () => {
|
||||||
suiteSetup(async function () {
|
suiteSetup(async function () {
|
||||||
let attempts: number = 20;
|
let attempts: number = 20;
|
||||||
while (attempts > 0) {
|
while (attempts > 0) {
|
||||||
@@ -40,6 +40,7 @@ suite('Schema compare integration test suite', () => {
|
|||||||
console.log(`Start schema compare tests`);
|
console.log(`Start schema compare tests`);
|
||||||
});
|
});
|
||||||
test('Schema compare dacpac to dacpac comparison and scmp @UNSTABLE@', async function () {
|
test('Schema compare dacpac to dacpac comparison and scmp @UNSTABLE@', async function () {
|
||||||
|
this.timeout(5 * 60 * 1000);
|
||||||
assert(schemaCompareService, 'Schema Compare Service Provider is not available');
|
assert(schemaCompareService, 'Schema Compare Service Provider is not available');
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const operationId = 'testOperationId_' + now.getTime().toString();
|
const operationId = 'testOperationId_' + now.getTime().toString();
|
||||||
@@ -82,16 +83,9 @@ suite('Schema compare integration test suite', () => {
|
|||||||
assert(openScmpResult.targetEndpointInfo.packageFilePath === target.packageFilePath, `Expected: target packageFilePath to be ${target.packageFilePath}, Actual: ${openScmpResult.targetEndpointInfo.packageFilePath}`);
|
assert(openScmpResult.targetEndpointInfo.packageFilePath === target.packageFilePath, `Expected: target packageFilePath to be ${target.packageFilePath}, Actual: ${openScmpResult.targetEndpointInfo.packageFilePath}`);
|
||||||
});
|
});
|
||||||
test('Schema compare database to database comparison, script generation, and scmp @UNSTABLE@', async function () {
|
test('Schema compare database to database comparison, script generation, and scmp @UNSTABLE@', async function () {
|
||||||
|
this.timeout(5 * 60 * 1000);
|
||||||
let server = await getStandaloneServer();
|
let server = await getStandaloneServer();
|
||||||
await utils.connectToServer(server, SERVER_CONNECTION_TIMEOUT);
|
const ownerUri = await getConnectionUri(server);
|
||||||
|
|
||||||
let nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
|
|
||||||
assert(nodes.length > 0, `Expecting at least one active connection, actual: ${nodes.length}`);
|
|
||||||
|
|
||||||
let 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 now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
const operationId = 'testOperationId_' + now.getTime().toString();
|
const operationId = 'testOperationId_' + now.getTime().toString();
|
||||||
@@ -161,16 +155,9 @@ suite('Schema compare integration test suite', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
test('Schema compare dacpac to database comparison, script generation, and scmp @UNSTABLE@', async function () {
|
test('Schema compare dacpac to database comparison, script generation, and scmp @UNSTABLE@', async function () {
|
||||||
|
this.timeout(5 * 60 * 1000);
|
||||||
let server = await getStandaloneServer();
|
let server = await getStandaloneServer();
|
||||||
await utils.connectToServer(server, SERVER_CONNECTION_TIMEOUT);
|
const ownerUri = await getConnectionUri(server);
|
||||||
|
|
||||||
let nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
|
|
||||||
assert(nodes.length > 0, `Expecting at least one active connection, actual: ${nodes.length}`);
|
|
||||||
|
|
||||||
let 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 now = new Date();
|
const now = new Date();
|
||||||
const operationId = 'testOperationId_' + now.getTime().toString();
|
const operationId = 'testOperationId_' + now.getTime().toString();
|
||||||
const targetDB: string = 'ads_schemaCompare_targetDB_' + now.getTime().toString();
|
const targetDB: string = 'ads_schemaCompare_targetDB_' + now.getTime().toString();
|
||||||
@@ -228,6 +215,7 @@ suite('Schema compare integration test suite', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
test('Schema compare dacpac to dacpac comparison with include exclude @UNSTABLE@', async function () {
|
test('Schema compare dacpac to dacpac comparison with include exclude @UNSTABLE@', async function () {
|
||||||
|
this.timeout(5 * 60 * 1000);
|
||||||
assert(schemaCompareService, 'Schema Compare Service Provider is not available');
|
assert(schemaCompareService, 'Schema Compare Service Provider is not available');
|
||||||
const operationId = 'testOperationId_' + new Date().getTime().toString();
|
const operationId = 'testOperationId_' + new Date().getTime().toString();
|
||||||
|
|
||||||
@@ -284,6 +272,17 @@ suite('Schema compare integration test suite', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function getConnectionUri(server: TestServerProfile): Promise<string> {
|
||||||
|
|
||||||
|
// Connext to server
|
||||||
|
let connectionId = await utils.connectToServer(server, SERVER_CONNECTION_TIMEOUT);
|
||||||
|
assert(connectionId, `Failed to connect to "${server.serverName}"`);
|
||||||
|
|
||||||
|
// Get connection uri
|
||||||
|
const ownerUri = await azdata.connection.getUriForConnection(connectionId);
|
||||||
|
return ownerUri;
|
||||||
|
}
|
||||||
|
|
||||||
function assertIncludeExcludeResult(result: mssql.SchemaCompareIncludeExcludeResult, expectedSuccess: boolean, expectedBlockingDependenciesLength: number, expectedAffectedDependenciesLength: number): void {
|
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}`);
|
assert(result.success === expectedSuccess, `Operation success should have been ${expectedSuccess}. Actual: ${result.success}`);
|
||||||
if (result.blockingDependencies) {
|
if (result.blockingDependencies) {
|
||||||
|
|||||||
@@ -35,9 +35,15 @@ export async function connectToServer(connectionInfo: TestConnectionInfo, timeou
|
|||||||
options: {}
|
options: {}
|
||||||
};
|
};
|
||||||
await ensureConnectionViewOpened();
|
await ensureConnectionViewOpened();
|
||||||
let result = <azdata.ConnectionResult>await azdata.connection.connect(connectionProfile);
|
|
||||||
assert(result.connected, `Failed to connect to "${connectionProfile.serverName}", error code: ${result.errorCode}, error message: ${result.errorMessage}`);
|
|
||||||
|
|
||||||
|
// Try connecting 3 times
|
||||||
|
let result = await retryFunction(
|
||||||
|
async () => {
|
||||||
|
let connection = <azdata.ConnectionResult>await azdata.connection.connect(connectionProfile);
|
||||||
|
assert(connection?.connected, `Failed to connect to "${connectionProfile.serverName}", error code: ${connection.errorCode}, error message: ${connection.errorMessage}`);
|
||||||
|
return connection;
|
||||||
|
|
||||||
|
}, 3);
|
||||||
//workaround
|
//workaround
|
||||||
//wait for OE to load
|
//wait for OE to load
|
||||||
await pollTimeout(async () => {
|
await pollTimeout(async () => {
|
||||||
@@ -180,6 +186,26 @@ export async function runQuery(query: string, ownerUri: string): Promise<azdata.
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function retryFunction<T>(fn: () => Promise<T>, retryCount: number): Promise<T> {
|
||||||
|
let attempts: number = 1;
|
||||||
|
while (attempts <= retryCount) {
|
||||||
|
try {
|
||||||
|
return await fn();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error(`utils.retryFunction: Attempt #${attempts} from ${retryCount} failed. Error: ${e}`);
|
||||||
|
if (attempts === retryCount) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await sleep(10000);
|
||||||
|
attempts++;
|
||||||
|
}
|
||||||
|
throw new Error(`utils.retryFunction: Failed after ${attempts} attempts`);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function assertThrowsAsync(fn: () => Promise<any>, msg: string): Promise<void> {
|
export async function assertThrowsAsync(fn: () => Promise<any>, msg: string): Promise<void> {
|
||||||
let f = () => {
|
let f = () => {
|
||||||
// Empty
|
// Empty
|
||||||
|
|||||||
@@ -27,11 +27,7 @@ before(function (): void {
|
|||||||
testContext = createContext();
|
testContext = createContext();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function (): void {
|
describe('SchemaCompareMainWindow.start @DacFx@', function (): void {
|
||||||
sinon.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SchemaCompareMainWindow.start', function (): void {
|
|
||||||
before(() => {
|
before(() => {
|
||||||
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||||
mockExtensionContext.setup(x => x.extensionPath).returns(() => '');
|
mockExtensionContext.setup(x => x.extensionPath).returns(() => '');
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ before(function (): void {
|
|||||||
testContext = createContext();
|
testContext = createContext();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('SchemaCompareDialog.openDialog', function (): void {
|
describe('SchemaCompareDialog.openDialog @DacFx@', function (): void {
|
||||||
before(() => {
|
before(() => {
|
||||||
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||||
mockExtensionContext.setup(x => x.extensionPath).returns(() => '');
|
mockExtensionContext.setup(x => x.extensionPath).returns(() => '');
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import * as sinon from 'sinon';
|
|||||||
|
|
||||||
let testContext: TestContext;
|
let testContext: TestContext;
|
||||||
|
|
||||||
describe('utils: Tests to verify getEndpointName', function (): void {
|
describe('utils: Tests to verify getEndpointName @DacFx@', function (): void {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user