test(memory-testing): adjust buffer tests

This commit is contained in:
LongYinan 2022-10-02 12:23:35 +08:00
parent c76be2f1e0
commit 6ff69a1dab
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
2 changed files with 8 additions and 8 deletions

View file

@ -10,18 +10,18 @@ const require = createRequire(import.meta.url)
const api = require(`./index.node`) const api = require(`./index.node`)
let i = 1 let i = 1
const FIXTURE = Buffer.allocUnsafe(1000 * 1000 * 20)
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
while (true) { while (true) {
api.bufferLen() api.bufferLen()
api.arrayBufferLen() api.arrayBufferLen()
api.bufferConvert(Buffer.from(Array.from({ length: 1024 * 10240 }).fill(1))) api.bufferConvert(Buffer.from(FIXTURE))
api.arrayBufferConvert( api.arrayBufferConvert(Uint8Array.from(FIXTURE))
Uint8Array.from(Array.from({ length: 1024 * 10240 }).fill(1)), api.bufferPassThrough(Buffer.from(FIXTURE))
) api.arrayBufferPassThrough(Uint8Array.from(FIXTURE))
api.bufferPassThrough(Buffer.from('hello world'.repeat(1024 * 1024)))
api.arrayBufferPassThrough(Uint8Array.from('hello world'.repeat(1024 * 1024)))
if (i % 10 === 0) { if (i % 10 === 0) {
await setTimeout(100) await setTimeout(1000)
global?.gc?.()
displayMemoryUsageFromNode(initialMemoryUsage) displayMemoryUsageFromNode(initialMemoryUsage)
} }
i++ i++

View file

@ -10,7 +10,7 @@ const sleep = promisify(setTimeout)
const client = new Dockerode() const client = new Dockerode()
export async function createSuite(testFile, maxMemoryUsage) { export async function createSuite(testFile, maxMemoryUsage) {
console.info(chalk.cyanBright('Create container')) console.info(chalk.cyanBright(`Create container to test ${testFile}`))
const container = await client.createContainer({ const container = await client.createContainer({
Image: 'node:lts-slim', Image: 'node:lts-slim',