diff --git a/src/commands/actor/calculate-memory.ts b/src/commands/actor/calculate-memory.ts index 48fcabc22..8b2392512 100644 --- a/src/commands/actor/calculate-memory.ts +++ b/src/commands/actor/calculate-memory.ts @@ -12,6 +12,12 @@ import { getJsonFileContent, getLocalKeyValueStorePath } from '../../lib/utils.j const DEFAULT_INPUT_PATH = join(getLocalKeyValueStorePath('default'), 'INPUT.json'); +interface ActorMemoryConfig { + defaultMemoryMbytes?: string; + minMemoryMbytes?: number; + maxMemoryMbytes?: number; +} + /** * This command can be used to test dynamic memory calculation expressions * defined in actor.json or provided via command-line flag. @@ -60,14 +66,7 @@ export class ActorCalculateMemoryCommand extends ApifyCommand { + private async getExpressionFromConfig(): Promise { const cwd = process.cwd(); const localConfigResult = await useActorConfig({ cwd }); @@ -103,10 +134,14 @@ export class ActorCalculateMemoryCommand extends ApifyCommand { expect(lastErrorMessage()).toMatch(/Memory calculation failed: /); }); + + describe('clamping to minMemoryMbytes/maxMemoryMbytes', () => { + it('should clamp memory to minMemoryMbytes from actor.json', async () => { + await createActorJson({ + defaultMemoryMbytes: START_URLS_LENGTH_BASED_MEMORY_EXPRESSION, + minMemoryMbytes: 8192, + }); + + await testRunCommand(ActorCalculateMemoryCommand, { + flags_input: inputPath, + }); + expect(lastLogMessage()).toMatch(/8192 MB/); + }); + + it('should clamp memory to maxMemoryMbytes from actor.json', async () => { + await createActorJson({ + defaultMemoryMbytes: START_URLS_LENGTH_BASED_MEMORY_EXPRESSION, + maxMemoryMbytes: 2048, + }); + + await testRunCommand(ActorCalculateMemoryCommand, { + flags_input: inputPath, + }); + expect(lastLogMessage()).toMatch(/2048 MB/); + }); + }); });