test: fix memory test assertion
This commit is contained in:
parent
81498ecbea
commit
b7ba068853
1 changed files with 9 additions and 6 deletions
|
@ -44,14 +44,19 @@ export async function createSuite(testFile, maxMemoryUsage) {
|
||||||
const stats = await container.stats()
|
const stats = await container.stats()
|
||||||
|
|
||||||
let shouldAssertMemoryUsage = false
|
let shouldAssertMemoryUsage = false
|
||||||
|
let initialMemoryUsage
|
||||||
const initialMemoryUsage = await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
|
const initialDate = Date.now()
|
||||||
stats.on('data', (d) => {
|
stats.on('data', (d) => {
|
||||||
const { memory_stats } = JSON.parse(d.toString('utf8'))
|
const { memory_stats } = JSON.parse(d.toString('utf8'))
|
||||||
resolve(memory_stats.usage)
|
if (Date.now() - initialDate > 10000 && !shouldAssertMemoryUsage) {
|
||||||
|
resolve()
|
||||||
|
initialMemoryUsage = memory_stats.usage
|
||||||
|
shouldAssertMemoryUsage = true
|
||||||
|
}
|
||||||
if (shouldAssertMemoryUsage && memory_stats?.usage) {
|
if (shouldAssertMemoryUsage && memory_stats?.usage) {
|
||||||
const memoryGrowth = memory_stats.usage - initialMemoryUsage
|
const memoryGrowth = memory_stats.usage - initialMemoryUsage
|
||||||
if (memoryGrowth > maxMemoryUsage ?? initialMemoryUsage) {
|
if (memoryGrowth > (maxMemoryUsage ?? initialMemoryUsage)) {
|
||||||
console.info(
|
console.info(
|
||||||
chalk.redBright(
|
chalk.redBright(
|
||||||
`Potential memory leak, memory growth: ${prettyBytes(
|
`Potential memory leak, memory growth: ${prettyBytes(
|
||||||
|
@ -72,8 +77,6 @@ export async function createSuite(testFile, maxMemoryUsage) {
|
||||||
|
|
||||||
await sleep(60000)
|
await sleep(60000)
|
||||||
|
|
||||||
shouldAssertMemoryUsage = true
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await container.stop()
|
await container.stop()
|
||||||
await container.remove()
|
await container.remove()
|
||||||
|
|
Loading…
Reference in a new issue