Created
February 25, 2023 12:43
-
-
Save iNewLegend/f7c41f035cbad93479e5a8f8ade5cc6b to your computer and use it in GitHub Desktop.
Find memory leak in node example.
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
/** | |
* @author: Leonid Vinikov <[email protected]> | |
*/ | |
import { Component } from "@internal/core/component"; | |
import * as assert from "assert"; | |
describe( 'Core', () => { | |
describe( 'Component', () => { | |
test( 'render() :: should have no memory leaks', async function () { | |
// Arrange. | |
class TestComponent extends Component { | |
static getName() { | |
return "TestComponent"; | |
} | |
template() { | |
return <div>Test Component</div>; | |
} | |
} | |
const component = new TestComponent( document.createElement( 'div' ) ); | |
for ( let i = 0; i < 200; i++ ) { | |
component.render(); | |
} | |
const initialMemory = process.memoryUsage(); | |
for ( let i = 0; i < 100; i++ ) { | |
component.render(); | |
} | |
// Act - Promise with a timeout to allow the garbage collector to run. | |
await new Promise( resolve => setTimeout( resolve, 0 ) ); | |
const currentMemory = process.memoryUsage(); | |
// Assert. | |
assert.ok( | |
initialMemory.heapUsed >= currentMemory.heapUsed | |
); | |
} ); | |
} ) | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment