-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make identity tests run 230x faster (#5482)
Improve the runtime of Identity unit tests by avoiding waiting real-world clock time when testing code that uses delays, such as polling for token updates.
- Loading branch information
Showing
5 changed files
with
163 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
let testFunction: ((t: number) => Promise<void>) | undefined; | ||
|
||
/** | ||
* A wrapper for setTimeout that resolves a promise after t milliseconds. | ||
* @internal | ||
* @param {number} t The number of milliseconds to be delayed. | ||
* @returns {Promise<void>} Resolved promise | ||
*/ | ||
export function delay(t: number): Promise<void> { | ||
if (testFunction) { | ||
return testFunction(t); | ||
} | ||
|
||
return new Promise((resolve) => setTimeout(() => resolve(), t)); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function _setDelayTestFunction(func?: (t: number) => Promise<void>): void { | ||
testFunction = func; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters