Disable one test and add a new utility function (#7486)

Skip problematic tests
This commit is contained in:
Amir Omidi
2019-10-02 21:59:40 -07:00
committed by GitHub
parent 08b78c3ca5
commit 575d1c8543
2 changed files with 44 additions and 20 deletions

View File

@@ -54,6 +54,23 @@ export async function connectToServer(server: TestServerProfile, timeout: number
return result.connectionId;
}
export class PromiseCancelledError extends Error { }
/**
* Wait for a promise to resolve but timeout after a certain amount of time.
* It will throw CancelledError when it fails.
* @param p promise to wait on
* @param timeout time to wait
*/
export async function asyncTimeout<T>(p: Thenable<T>, timeout: number): Promise<(T | undefined)> {
const timeoutPromise = new Promise<T>((done, reject) => {
setTimeout(() => {
reject(new PromiseCancelledError('Promise did not resolve in time'));
}, timeout);
});
return Promise.race([p, timeoutPromise]);
}
export async function pollTimeout(predicate: () => Thenable<boolean>, intervalDelay: number, timeoutTime: number): Promise<boolean> {
let interval: NodeJS.Timer;
return new Promise(pollOver => {