Skip to content

Commit

Permalink
feat(models): adds a heap size check
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
  • Loading branch information
Stefan Blaginov authored and Stefan Blaginov committed Feb 1, 2024
1 parent 2dabc92 commit d01408f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/common/benchmarkModelGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

'use strict';

const v8 = require('v8');
const { Blob } = require('buffer');

const DEFAULT_CONCERTO_METAMODEL_VERSION = '1.0.0';
Expand Down Expand Up @@ -349,6 +350,10 @@ class BenchmarkModelGenerator {
nDeclarations = 1,
nProperties = 1,
}) {
if (generateUpToSize > v8.getHeapStatistics().total_heap_size) {
throw new Error('The requested model size is exceeding the total_heap_size and cannot be created.');
}

const model = {
$class: `concerto.metamodel@${concertoMetamodelVersion}.Model`,
decorators: [],
Expand Down
13 changes: 13 additions & 0 deletions test/common/benchmarkModelGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,18 @@ describe('benchmarkModelGenerator', function () {
});
}).should.throw('growBy can be either set to "declarations" or "properties".');
});

it('should throw an error if the requested model size exceeds the total_heap_size', function () {
const benchmarkModelGenerator = new BenchmarkModelGenerator();
benchmarkModelGenerator.should.not.be.null;

(() => {
benchmarkModelGenerator.generateConcertoModels({
generateUpToSize: 100000000000,
growBy: 'properties',
nDeclarations: 5,
});
}).should.throw('The requested model size is exceeding the total_heap_size and cannot be created.');
});
});
});

0 comments on commit d01408f

Please sign in to comment.