mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
code: nextjs,memory,max (1 files)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import type { SandboxedLuaEngineState } from './types'
|
||||
import { enforceMaxMemory } from './enforce-max-memory'
|
||||
|
||||
const createState = (usageBytes: number, maxMemory: number): SandboxedLuaEngineState =>
|
||||
({
|
||||
maxMemory,
|
||||
getLuaMemoryUsageBytes: () => usageBytes,
|
||||
}) as SandboxedLuaEngineState
|
||||
|
||||
describe('enforceMaxMemory', () => {
|
||||
it('does not throw when usage is under the limit', () => {
|
||||
const state = createState(512, 1024)
|
||||
expect(() => enforceMaxMemory.call(state)).not.toThrow()
|
||||
})
|
||||
|
||||
it('throws when usage exceeds the limit', () => {
|
||||
const state = createState(2048, 1024)
|
||||
expect(() => enforceMaxMemory.call(state)).toThrow(/Memory limit exceeded/)
|
||||
})
|
||||
|
||||
it('does not throw when maxMemory is disabled', () => {
|
||||
const state = createState(2048, 0)
|
||||
expect(() => enforceMaxMemory.call(state)).not.toThrow()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user