feat(expect): log-scale expect pollers (#8010)

This commit is contained in:
Pavel Feldman 2021-08-05 10:55:37 -07:00 committed by GitHub
parent 7454647d8e
commit 0a97e87817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 5 deletions

View File

@ -48,7 +48,7 @@ export async function toBeTruthy<T>(
received = await query(remainingTime);
pass = !!received;
return pass === !matcherOptions.isNot;
}, options.timeout, 100, testInfo._testFinished);
}, options.timeout, testInfo._testFinished);
const message = () => {
return matcherHint(matcherName, undefined, '', matcherOptions);

View File

@ -64,7 +64,7 @@ export async function toEqual<T>(
received = await query(remainingTime);
pass = equals(received, expected, [iterableEquality]);
return pass === !matcherOptions.isNot;
}, options.timeout, 100, testInfo._testFinished);
}, options.timeout, testInfo._testFinished);
const message = pass
? () =>

View File

@ -80,7 +80,7 @@ export async function toMatchText(
pass = expected.test(received);
return pass === !matcherOptions.isNot;
}, options.timeout, 100, testInfo._testFinished);
}, options.timeout, testInfo._testFinished);
const stringSubstring = options.matchSubstring ? 'substring' : 'string';
const message = pass

View File

@ -71,7 +71,7 @@ export async function raceAgainstDeadline<T>(promise: Promise<T>, deadline: numb
return (new DeadlineRunner(promise, deadline)).result;
}
export async function pollUntilDeadline(state: ReturnType<Expect['getState']>, func: (remainingTime: number) => Promise<boolean>, pollTime: number | undefined, pollInterval: number, deadlinePromise: Promise<void>): Promise<void> {
export async function pollUntilDeadline(state: ReturnType<Expect['getState']>, func: (remainingTime: number) => Promise<boolean>, pollTime: number | undefined, deadlinePromise: Promise<void>): Promise<void> {
const playwrightActionTimeout = (state as any).playwrightActionTimeout;
pollTime = pollTime === 0 ? 0 : pollTime || playwrightActionTimeout;
const deadline = pollTime ? monotonicTime() + pollTime : 0;
@ -82,6 +82,8 @@ export async function pollUntilDeadline(state: ReturnType<Expect['getState']>, f
return true;
});
const pollIntervals = [100, 250, 500];
let attempts = 0;
while (!aborted) {
const remainingTime = deadline ? deadline - monotonicTime() : 1000 * 3600 * 24;
if (remainingTime <= 0)
@ -102,7 +104,7 @@ export async function pollUntilDeadline(state: ReturnType<Expect['getState']>, f
}
let timer: NodeJS.Timer;
const timeoutPromise = new Promise(f => timer = setTimeout(f, pollInterval));
const timeoutPromise = new Promise(f => timer = setTimeout(f, pollIntervals[attempts++] || 1000));
await Promise.race([abortedPromise, timeoutPromise]);
clearTimeout(timer!);
}