mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -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 dacpac1: string = path.join(__dirname, '../../testData/Database1.dacpac');
|
||||
suite('Dacpac integration test suite', () => {
|
||||
|
||||
|
||||
suite('Dacpac integration test suite @DacFx@', () => {
|
||||
suiteSetup(async function () {
|
||||
await utils.sleep(5000); // To ensure the providers are registered.
|
||||
console.log(`Start dacpac tests`);
|
||||
});
|
||||
|
||||
test('Deploy and extract dacpac @UNSTABLE@', async function () {
|
||||
this.timeout(5 * 60 * 1000);
|
||||
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 index = nodes.findIndex(node => node.nodePath.includes(server.serverName));
|
||||
const ownerUri = await azdata.connection.getUriForConnection(nodes[index].connectionId);
|
||||
const ownerUri = await azdata.connection.getUriForConnection(connectionId);
|
||||
const now = new Date();
|
||||
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');
|
||||
test('Import and export bacpac @UNSTABLE@', async function () {
|
||||
this.timeout(5 * 60 * 1000);
|
||||
const server = await getStandaloneServer();
|
||||
await utils.connectToServer(server);
|
||||
|
||||
const nodes = <azdata.objectexplorer.ObjectExplorerNode[]>await azdata.objectexplorer.getActiveConnectionNodes();
|
||||
const index = nodes.findIndex(node => node.nodePath.includes(server.serverName));
|
||||
const ownerUri = await azdata.connection.getUriForConnection(nodes[index].connectionId);
|
||||
const connectionId = await utils.connectToServer(server);
|
||||
assert(connectionId, `Failed to connect to "${server.serverName}"`);
|
||||
const ownerUri = await azdata.connection.getUriForConnection(connectionId);
|
||||
const now = new Date();
|
||||
const databaseName = 'ADS_importBacpac_' + now.getTime().toString();
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import * as os from 'os';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as assert from 'assert';
|
||||
import { getStandaloneServer } from './testConfig';
|
||||
import { getStandaloneServer, TestServerProfile } from './testConfig';
|
||||
import { promisify } from 'util';
|
||||
|
||||
let schemaCompareService: mssql.ISchemaCompareService;
|
||||
@@ -25,7 +25,7 @@ const SERVER_CONNECTION_TIMEOUT: number = 3000;
|
||||
const retryCount = 24; // 2 minutes
|
||||
const folderPath = path.join(os.tmpdir(), 'SchemaCompareTest');
|
||||
|
||||
suite('Schema compare integration test suite', () => {
|
||||
suite('Schema compare integration test suite @DacFx@', () => {
|
||||
suiteSetup(async function () {
|
||||
let attempts: number = 20;
|
||||
while (attempts > 0) {
|
||||
@@ -40,6 +40,7 @@ suite('Schema compare integration test suite', () => {
|
||||
console.log(`Start schema compare tests`);
|
||||
});
|
||||
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');
|
||||
const now = new Date();
|
||||
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}`);
|
||||
});
|
||||
test('Schema compare database to database comparison, script generation, and scmp @UNSTABLE@', async function () {
|
||||
this.timeout(5 * 60 * 1000);
|
||||
let server = await getStandaloneServer();
|
||||
await utils.connectToServer(server, SERVER_CONNECTION_TIMEOUT);
|
||||
|
||||
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 ownerUri = await getConnectionUri(server);
|
||||
const now = new Date();
|
||||
|
||||
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 () {
|
||||
this.timeout(5 * 60 * 1000);
|
||||
let server = await getStandaloneServer();
|
||||
await utils.connectToServer(server, SERVER_CONNECTION_TIMEOUT);
|
||||
|
||||
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 ownerUri = await getConnectionUri(server);
|
||||
const now = new Date();
|
||||
const operationId = 'testOperationId_' + 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 () {
|
||||
this.timeout(5 * 60 * 1000);
|
||||
assert(schemaCompareService, 'Schema Compare Service Provider is not available');
|
||||
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 {
|
||||
assert(result.success === expectedSuccess, `Operation success should have been ${expectedSuccess}. Actual: ${result.success}`);
|
||||
if (result.blockingDependencies) {
|
||||
|
||||
@@ -35,9 +35,15 @@ export async function connectToServer(connectionInfo: TestConnectionInfo, timeou
|
||||
options: {}
|
||||
};
|
||||
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
|
||||
//wait for OE to load
|
||||
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> {
|
||||
let f = () => {
|
||||
// Empty
|
||||
|
||||
Reference in New Issue
Block a user