Remove scaling reserved RAM feature flag
This commit is contained in:
parent
574dbbc517
commit
10389f671b
15 changed files with 58 additions and 123 deletions
|
|
@ -26,49 +26,42 @@ const GET_MEMORY_FLAG_TESTS = [
|
|||
totalMemoryMb: 8 * 1024,
|
||||
platform: "linux",
|
||||
expectedMemoryValue: 7 * 1024,
|
||||
expectedMemoryValueWithScaling: 7 * 1024,
|
||||
},
|
||||
{
|
||||
input: undefined,
|
||||
totalMemoryMb: 8 * 1024,
|
||||
platform: "win32",
|
||||
expectedMemoryValue: 6.5 * 1024,
|
||||
expectedMemoryValueWithScaling: 6.5 * 1024,
|
||||
},
|
||||
{
|
||||
input: "",
|
||||
totalMemoryMb: 8 * 1024,
|
||||
platform: "linux",
|
||||
expectedMemoryValue: 7 * 1024,
|
||||
expectedMemoryValueWithScaling: 7 * 1024,
|
||||
},
|
||||
{
|
||||
input: "512",
|
||||
totalMemoryMb: 8 * 1024,
|
||||
platform: "linux",
|
||||
expectedMemoryValue: 512,
|
||||
expectedMemoryValueWithScaling: 512,
|
||||
},
|
||||
{
|
||||
input: undefined,
|
||||
totalMemoryMb: 64 * 1024,
|
||||
platform: "linux",
|
||||
expectedMemoryValue: 63 * 1024,
|
||||
expectedMemoryValueWithScaling: 61644, // Math.floor(1024 * (64 - 1 - 0.05 * (64 - 8)))
|
||||
expectedMemoryValue: 61644, // Math.floor(1024 * (64 - 1 - 0.05 * (64 - 8)))
|
||||
},
|
||||
{
|
||||
input: undefined,
|
||||
totalMemoryMb: 64 * 1024,
|
||||
platform: "win32",
|
||||
expectedMemoryValue: 62.5 * 1024,
|
||||
expectedMemoryValueWithScaling: 61132, // Math.floor(1024 * (64 - 1.5 - 0.05 * (64 - 8)))
|
||||
expectedMemoryValue: 61132, // Math.floor(1024 * (64 - 1.5 - 0.05 * (64 - 8)))
|
||||
},
|
||||
{
|
||||
input: undefined,
|
||||
totalMemoryMb: 64 * 1024,
|
||||
platform: "linux",
|
||||
expectedMemoryValue: 63 * 1024,
|
||||
expectedMemoryValueWithScaling: 58777, // Math.floor(1024 * (64 - 1 - 0.1 * (64 - 8)))
|
||||
expectedMemoryValue: 58777, // Math.floor(1024 * (64 - 1 - 0.1 * (64 - 8)))
|
||||
reservedPercentageValue: "10",
|
||||
},
|
||||
];
|
||||
|
|
@ -78,40 +71,29 @@ for (const {
|
|||
totalMemoryMb,
|
||||
platform,
|
||||
expectedMemoryValue,
|
||||
expectedMemoryValueWithScaling,
|
||||
reservedPercentageValue,
|
||||
} 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${
|
||||
reservedPercentageValue
|
||||
? ` and reserved percentage env var set to ${reservedPercentageValue}`
|
||||
: ""
|
||||
}`,
|
||||
async (t) => {
|
||||
process.env[EnvVar.SCALING_RESERVED_RAM_PERCENTAGE] =
|
||||
reservedPercentageValue || undefined;
|
||||
for (const withScaling of [true, false]) {
|
||||
const flag = util.getMemoryFlagValueForPlatform(
|
||||
input,
|
||||
totalMemoryMb * 1024 * 1024,
|
||||
platform,
|
||||
withScaling,
|
||||
);
|
||||
t.deepEqual(
|
||||
flag,
|
||||
withScaling ? expectedMemoryValueWithScaling : expectedMemoryValue,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
test(`Memory flag value is ${expectedMemoryValue} for ${
|
||||
input ?? "no user input"
|
||||
} on ${platform} with ${totalMemoryMb} MB total system RAM${
|
||||
reservedPercentageValue
|
||||
? ` and reserved percentage env var set to ${reservedPercentageValue}`
|
||||
: ""
|
||||
}`, async (t) => {
|
||||
process.env[EnvVar.SCALING_RESERVED_RAM_PERCENTAGE] =
|
||||
reservedPercentageValue || undefined;
|
||||
const flag = util.getMemoryFlagValueForPlatform(
|
||||
input,
|
||||
totalMemoryMb * 1024 * 1024,
|
||||
platform,
|
||||
);
|
||||
t.deepEqual(flag, expectedMemoryValue);
|
||||
});
|
||||
}
|
||||
|
||||
test("getMemoryFlag() throws if the ram input is < 0 or NaN", async (t) => {
|
||||
for (const input of ["-1", "hello!"]) {
|
||||
t.throws(() => util.getMemoryFlag(input, false));
|
||||
t.throws(() => util.getMemoryFlag(input));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue