Test memory flag computation across all platforms and system RAM values
This commit is contained in:
parent
ce84bed594
commit
18ae9813bf
6 changed files with 168 additions and 50 deletions
|
|
@ -19,28 +19,79 @@ test("getToolNames", (t) => {
|
|||
t.deepEqual(toolNames, ["CodeQL command-line toolchain", "ESLint"]);
|
||||
});
|
||||
|
||||
test("getMemoryFlag() should return the correct --ram flag", async (t) => {
|
||||
const totalMem = os.totalmem() / (1024 * 1024);
|
||||
const fixedAmount = process.platform === "win32" ? 1536 : 1024;
|
||||
const scaledAmount = 0.02 * totalMem;
|
||||
const expectedMemoryValue = Math.floor(totalMem - fixedAmount);
|
||||
const expectedMemoryValueWithScaling = Math.floor(
|
||||
totalMem - fixedAmount - scaledAmount
|
||||
const GET_MEMORY_FLAG_TESTS = [
|
||||
{
|
||||
input: undefined,
|
||||
totalMemoryMb: 8 * 1024,
|
||||
platform: "linux",
|
||||
expectedMemoryValue: 7 * 1024,
|
||||
expectedMemoryValueWithScaling: 7004, // Math.floor(1024 * (8*0.98 - 1))
|
||||
},
|
||||
{
|
||||
input: undefined,
|
||||
totalMemoryMb: 8 * 1024,
|
||||
platform: "win32",
|
||||
expectedMemoryValue: 6.5 * 1024,
|
||||
expectedMemoryValueWithScaling: 6492, // Math.floor(1024 * (8*0.98 - 1.5))
|
||||
},
|
||||
{
|
||||
input: "",
|
||||
totalMemoryMb: 8 * 1024,
|
||||
platform: "linux",
|
||||
expectedMemoryValue: 7 * 1024,
|
||||
expectedMemoryValueWithScaling: 7004, // Math.floor(1024 * (8*0.98 - 1))
|
||||
},
|
||||
{
|
||||
input: "512",
|
||||
totalMemoryMb: 8 * 1024,
|
||||
platform: "linux",
|
||||
expectedMemoryValue: 512,
|
||||
expectedMemoryValueWithScaling: 512,
|
||||
},
|
||||
{
|
||||
input: undefined,
|
||||
totalMemoryMb: 64 * 1024,
|
||||
platform: "linux",
|
||||
expectedMemoryValue: 63 * 1024,
|
||||
expectedMemoryValueWithScaling: 63201, // Math.floor(1024 * (64*0.98 - 1))
|
||||
},
|
||||
{
|
||||
input: undefined,
|
||||
totalMemoryMb: 64 * 1024,
|
||||
platform: "win32",
|
||||
expectedMemoryValue: 62.5 * 1024,
|
||||
expectedMemoryValueWithScaling: 62689, // Math.floor(1024 * (64*0.98 - 1.5))
|
||||
},
|
||||
];
|
||||
|
||||
for (const {
|
||||
input,
|
||||
totalMemoryMb,
|
||||
platform,
|
||||
expectedMemoryValue,
|
||||
expectedMemoryValueWithScaling,
|
||||
} of GET_MEMORY_FLAG_TESTS) {
|
||||
test(
|
||||
`Memory flag value is ${expectedMemoryValue} without scaling and ${expectedMemoryValueWithScaling} with scaling ` +
|
||||
`for ${
|
||||
input ?? "no user input"
|
||||
} on ${platform} with ${totalMemoryMb} MB total system RAM`,
|
||||
async (t) => {
|
||||
for (const withScaling of [true, false]) {
|
||||
const flag = util.getMemoryFlagValueForPlatform(
|
||||
input,
|
||||
totalMemoryMb * 1024 * 1024,
|
||||
platform,
|
||||
withScaling
|
||||
);
|
||||
t.deepEqual(
|
||||
flag,
|
||||
withScaling ? expectedMemoryValueWithScaling : expectedMemoryValue
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const tests: Array<[string | undefined, boolean, string]> = [
|
||||
[undefined, false, `--ram=${expectedMemoryValue}`],
|
||||
["", false, `--ram=${expectedMemoryValue}`],
|
||||
["512", false, "--ram=512"],
|
||||
[undefined, true, `--ram=${expectedMemoryValueWithScaling}`],
|
||||
["", true, `--ram=${expectedMemoryValueWithScaling}`],
|
||||
];
|
||||
|
||||
for (const [input, withScaling, expectedFlag] of tests) {
|
||||
const flag = util.getMemoryFlag(input, withScaling);
|
||||
t.deepEqual(flag, expectedFlag);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
test("getMemoryFlag() throws if the ram input is < 0 or NaN", async (t) => {
|
||||
for (const input of ["-1", "hello!"]) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue