* Repeatedly triggers garbage collection until a specified condition is met or a maximum number of attempts is reached. * This utillity must be run in a Node.js instance that enables --expose-gc. * @param {string|Function} [name] - Optional name, used in the rejection message if the condition is n
(name, condition, maxCount = 10, gcOptions)
| 50 | * @returns {Promise} A promise that resolves when the condition is met, or rejects after 10 failed attempts. |
| 51 | */ |
| 52 | async function gcUntil(name, condition, maxCount = 10, gcOptions) { |
| 53 | for (let count = 0; count < maxCount; ++count) { |
| 54 | await setImmediatePromisified(); |
| 55 | if (gcOptions) { |
| 56 | await global.gc(gcOptions); |
| 57 | } else { |
| 58 | await global.gc(); // Passing in undefined is not the same as empty. |
| 59 | } |
| 60 | if (condition()) { |
| 61 | return; |
| 62 | } |
| 63 | } |
| 64 | throw new Error(`Test ${name} failed`); |
| 65 | } |
| 66 | |
| 67 | // This function can be used to check if an object factor leaks or not, |
| 68 | // but it needs to be used with care: |
no test coverage detected
searching dependent graphs…