Revert "Revert "OE clicking and awaiting the expansion calls"" (#6923)

* Revert "Revert "OE clicking and awaiting the expansion calls" (#6921)"

This reverts commit b9e3a468ae.

* Handle edge cases better

* Polling for OE load time
This commit is contained in:
Amir Omidi
2019-09-03 10:31:29 -07:00
committed by GitHub
parent a5c824a318
commit 33a7fe38e1
7 changed files with 82 additions and 36 deletions

View File

@@ -14,7 +14,7 @@ import { TestServerProfile } from './testConfig';
* @param timeout optional timeout parameter
* Returns connection id for a new connection
*/
export async function connectToServer(server: TestServerProfile, timeout: number = 3000): Promise<string> {
export async function connectToServer(server: TestServerProfile, timeout: number = 10000): Promise<string> {
let connectionProfile: azdata.IConnectionProfile = {
serverName: server.serverName,
databaseName: server.database,
@@ -36,10 +36,37 @@ export async function connectToServer(server: TestServerProfile, timeout: number
//workaround
//wait for OE to load
await new Promise(c => setTimeout(c, timeout));
await pollTimeout(async () => {
const nodes = await azdata.objectexplorer.getActiveConnectionNodes();
let found = nodes.some(node => {
return node.connectionId === result.connectionId;
});
if (found === undefined) {
found = false;
}
return found;
}, 1000, timeout);
return result.connectionId;
}
export async function pollTimeout(predicate: () => Thenable<boolean>, intervalDelay: number, timeoutTime: number): Promise<boolean> {
let interval: NodeJS.Timer;
return new Promise(pollOver => {
const complete = (success = false) => {
clearInterval(interval);
pollOver(success);
};
interval = setInterval(async () => {
const predResult = await predicate();
if (predResult) {
complete(true);
}
}, intervalDelay);
setTimeout(complete, timeoutTime);
});
}
export async function ensureConnectionViewOpened() {
await vscode.commands.executeCommand('dataExplorer.servers.focus');
}