Fix race condition in challenge test

This commit is contained in:
Fedor Indutny 2021-05-07 09:10:40 -07:00 committed by GitHub
parent a1e4820cb7
commit 470eab8352
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,8 @@ type CreateHandlerOptions = {
readonly onChallengeFailed?: (retryAfter?: number) => void; readonly onChallengeFailed?: (retryAfter?: number) => void;
}; };
const NEVER_RETRY = Date.now() + 365 * 24 * 3600 * 1000;
describe('ChallengeHandler', () => { describe('ChallengeHandler', () => {
const storage = new Map<string, any>(); const storage = new Map<string, any>();
const messageStorage = new Map<string, MinimalMessage>(); const messageStorage = new Map<string, MinimalMessage>();
@ -173,7 +175,7 @@ describe('ChallengeHandler', () => {
it('should send challenge response', async () => { it('should send challenge response', async () => {
const handler = await createHandler({ challenge: true }); const handler = await createHandler({ challenge: true });
const one = createMessage('1', { retryAfter: Date.now() + 100000 }); const one = createMessage('1', { retryAfter: NEVER_RETRY });
messageStorage.set('1', one); messageStorage.set('1', one);
await handler.register(one); await handler.register(one);
@ -348,7 +350,7 @@ describe('ChallengeHandler', () => {
}); });
const one = createMessage('1', { const one = createMessage('1', {
retryAfter: Date.now() + 1, retryAfter: NEVER_RETRY,
}); });
messageStorage.set('1', one); messageStorage.set('1', one);
await handler.register(one); await handler.register(one);
@ -369,7 +371,7 @@ describe('ChallengeHandler', () => {
}); });
const one = createMessage('1', { const one = createMessage('1', {
retryAfter: Date.now() + 1, retryAfter: NEVER_RETRY,
}); });
messageStorage.set('1', one); messageStorage.set('1', one);
await handler.register(one); await handler.register(one);