2023-11-09 19:11:11 -05:00
|
|
|
import {
|
|
|
|
calculatePercentageUsed,
|
|
|
|
checkDiskUtilization,
|
|
|
|
} from "../dist/util/storage.js";
|
2023-07-06 00:58:28 -04:00
|
|
|
|
|
|
|
test("ensure calculatePercentageUsed returns expected values", () => {
|
|
|
|
expect(calculatePercentageUsed(30, 100)).toEqual(30);
|
|
|
|
|
|
|
|
expect(calculatePercentageUsed(1507, 35750)).toEqual(4);
|
|
|
|
|
|
|
|
expect(calculatePercentageUsed(33819, 35750)).toEqual(95);
|
|
|
|
|
|
|
|
expect(calculatePercentageUsed(140, 70)).toEqual(200);
|
|
|
|
|
|
|
|
expect(calculatePercentageUsed(0, 5)).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("verify end-to-end disk utilization not exceeded threshold", async () => {
|
|
|
|
const params = {
|
|
|
|
diskUtilization: 90,
|
|
|
|
combineWARC: true,
|
2023-11-09 19:11:11 -05:00
|
|
|
generateWACZ: true,
|
2023-07-06 00:58:28 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const mockDfOutput = `\
|
|
|
|
Filesystem 1K-blocks Used Available Use% Mounted on
|
|
|
|
grpcfuse 1000000 285000 715000 28% /crawls`;
|
|
|
|
|
|
|
|
// with combineWARC + generateWACZ, projected is 285k + 4 * 5k = 310k = 31%
|
|
|
|
// does not exceed 90% threshold
|
2023-11-09 19:11:11 -05:00
|
|
|
const returnValue = await checkDiskUtilization(
|
2024-06-07 19:13:15 +02:00
|
|
|
'/crawls',
|
2023-11-09 19:11:11 -05:00
|
|
|
params,
|
|
|
|
5000 * 1024,
|
|
|
|
mockDfOutput,
|
2024-06-26 13:05:13 -07:00
|
|
|
false
|
2023-11-09 19:11:11 -05:00
|
|
|
);
|
2023-07-06 00:58:28 -04:00
|
|
|
expect(returnValue).toEqual({
|
|
|
|
stop: false,
|
|
|
|
used: 28,
|
|
|
|
projected: 31,
|
2023-11-09 19:11:11 -05:00
|
|
|
threshold: 90,
|
2023-07-06 00:58:28 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("verify end-to-end disk utilization exceeds threshold", async () => {
|
|
|
|
const params = {
|
|
|
|
diskUtilization: 90,
|
|
|
|
combineWARC: false,
|
2023-11-09 19:11:11 -05:00
|
|
|
generateWACZ: true,
|
2023-07-06 00:58:28 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const mockDfOutput = `\
|
|
|
|
Filesystem 1K-blocks Used Available Use% Mounted on
|
|
|
|
grpcfuse 100000 85000 15000 85% /crawls`;
|
|
|
|
|
|
|
|
// with generateWACZ, projected is 85k + 3k x 2 = 91k = 91%
|
|
|
|
// exceeds 90% threshold
|
2023-11-09 19:11:11 -05:00
|
|
|
const returnValue = await checkDiskUtilization(
|
2024-06-07 19:13:15 +02:00
|
|
|
'/crawls',
|
2023-11-09 19:11:11 -05:00
|
|
|
params,
|
|
|
|
3000 * 1024,
|
|
|
|
mockDfOutput,
|
2024-06-26 13:05:13 -07:00
|
|
|
false
|
2023-11-09 19:11:11 -05:00
|
|
|
);
|
2023-07-06 00:58:28 -04:00
|
|
|
expect(returnValue).toEqual({
|
|
|
|
stop: true,
|
|
|
|
used: 85,
|
|
|
|
projected: 91,
|
2023-11-09 19:11:11 -05:00
|
|
|
threshold: 90,
|
2023-07-06 00:58:28 -04:00
|
|
|
});
|
|
|
|
});
|