feat(expect): log-scale expect pollers (#8010)
This commit is contained in:
parent
7454647d8e
commit
0a97e87817
|
|
@ -48,7 +48,7 @@ export async function toBeTruthy<T>(
|
||||||
received = await query(remainingTime);
|
received = await query(remainingTime);
|
||||||
pass = !!received;
|
pass = !!received;
|
||||||
return pass === !matcherOptions.isNot;
|
return pass === !matcherOptions.isNot;
|
||||||
}, options.timeout, 100, testInfo._testFinished);
|
}, options.timeout, testInfo._testFinished);
|
||||||
|
|
||||||
const message = () => {
|
const message = () => {
|
||||||
return matcherHint(matcherName, undefined, '', matcherOptions);
|
return matcherHint(matcherName, undefined, '', matcherOptions);
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ export async function toEqual<T>(
|
||||||
received = await query(remainingTime);
|
received = await query(remainingTime);
|
||||||
pass = equals(received, expected, [iterableEquality]);
|
pass = equals(received, expected, [iterableEquality]);
|
||||||
return pass === !matcherOptions.isNot;
|
return pass === !matcherOptions.isNot;
|
||||||
}, options.timeout, 100, testInfo._testFinished);
|
}, options.timeout, testInfo._testFinished);
|
||||||
|
|
||||||
const message = pass
|
const message = pass
|
||||||
? () =>
|
? () =>
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ export async function toMatchText(
|
||||||
pass = expected.test(received);
|
pass = expected.test(received);
|
||||||
|
|
||||||
return pass === !matcherOptions.isNot;
|
return pass === !matcherOptions.isNot;
|
||||||
}, options.timeout, 100, testInfo._testFinished);
|
}, options.timeout, testInfo._testFinished);
|
||||||
|
|
||||||
const stringSubstring = options.matchSubstring ? 'substring' : 'string';
|
const stringSubstring = options.matchSubstring ? 'substring' : 'string';
|
||||||
const message = pass
|
const message = pass
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ export async function raceAgainstDeadline<T>(promise: Promise<T>, deadline: numb
|
||||||
return (new DeadlineRunner(promise, deadline)).result;
|
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;
|
const playwrightActionTimeout = (state as any).playwrightActionTimeout;
|
||||||
pollTime = pollTime === 0 ? 0 : pollTime || playwrightActionTimeout;
|
pollTime = pollTime === 0 ? 0 : pollTime || playwrightActionTimeout;
|
||||||
const deadline = pollTime ? monotonicTime() + pollTime : 0;
|
const deadline = pollTime ? monotonicTime() + pollTime : 0;
|
||||||
|
|
@ -82,6 +82,8 @@ export async function pollUntilDeadline(state: ReturnType<Expect['getState']>, f
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const pollIntervals = [100, 250, 500];
|
||||||
|
let attempts = 0;
|
||||||
while (!aborted) {
|
while (!aborted) {
|
||||||
const remainingTime = deadline ? deadline - monotonicTime() : 1000 * 3600 * 24;
|
const remainingTime = deadline ? deadline - monotonicTime() : 1000 * 3600 * 24;
|
||||||
if (remainingTime <= 0)
|
if (remainingTime <= 0)
|
||||||
|
|
@ -102,7 +104,7 @@ export async function pollUntilDeadline(state: ReturnType<Expect['getState']>, f
|
||||||
}
|
}
|
||||||
|
|
||||||
let timer: NodeJS.Timer;
|
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]);
|
await Promise.race([abortedPromise, timeoutPromise]);
|
||||||
clearTimeout(timer!);
|
clearTimeout(timer!);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue