Skip to content

Commit e185904

Browse files
committed
Fix connect authenticator test
1 parent ddc7125 commit e185904

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/tests-e2e/src/connect/utils/AuthenticatorApp.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ export class AuthenticatorApp {
3030
const wrapped = this.#existing.get(secret);
3131
if (!wrapped) return null;
3232

33-
const now = Date.now();
34-
if (now < wrapped.nextBoundary) {
35-
await new Promise(resolve => setTimeout(resolve, wrapped.nextBoundary - now));
33+
const safetyMargin = 2_000;
34+
let now = Date.now();
35+
36+
// If the stored boundary is already in the past, recalculate from now
37+
if (now >= wrapped.nextBoundary) {
38+
wrapped.nextBoundary = this.#calculateNextBoundary(now, 30_000);
3639
}
3740

41+
await new Promise(resolve => setTimeout(resolve, wrapped.nextBoundary - now + safetyMargin));
42+
3843
const then = Date.now();
3944
const result = generateToken(secret);
4045
if (!result) return null;

0 commit comments

Comments
 (0)