This commit is contained in:
@@ -161,6 +161,82 @@ describe('capacity history', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('excludes inactive hosts from resource totals and coverage while retaining their temperatures', async () => {
|
||||
await host('active');
|
||||
await host('disabled');
|
||||
await host('draining');
|
||||
await host('disabled-without-samples');
|
||||
await sample('active', epoch - 45_000);
|
||||
await sample('disabled', epoch - 45_000);
|
||||
await sample('disabled', epoch - 90_000);
|
||||
await sample('draining', epoch - 45_000);
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
db().prepare("UPDATE ec_hosts SET mode='disabled' WHERE id LIKE 'disabled%'").run();
|
||||
db().prepare("UPDATE ec_hosts SET mode='draining' WHERE id='draining'").run();
|
||||
const { recordTemperatures } = await import('../../src/lib/server/hosts/temperatures.js');
|
||||
recordTemperatures(
|
||||
'disabled',
|
||||
{
|
||||
temperatures: [
|
||||
{
|
||||
id: 'pkg',
|
||||
device: 'coretemp',
|
||||
kind: 'cpu-package',
|
||||
label: 'Package id 0',
|
||||
celsius: 65
|
||||
}
|
||||
]
|
||||
},
|
||||
new Date(epoch - 45_000).toISOString()
|
||||
);
|
||||
const { readCapacityHistory } =
|
||||
await import('../../src/lib/server/hosts/capacity-history.js');
|
||||
const history = readCapacityHistory(query, epoch);
|
||||
expect(history.points.at(-1)).toMatchObject({
|
||||
memoryBytesAvailable: 4 * GiB - 500_000_000,
|
||||
reportingHosts: 1,
|
||||
expectedHosts: 1
|
||||
});
|
||||
expect(history.points.at(-1)?.cpuCoresAvailable).toBeCloseTo(5.6);
|
||||
expect(history.points.at(-2)).toMatchObject({
|
||||
cpuCoresAvailable: null,
|
||||
memoryBytesAvailable: null,
|
||||
reportingHosts: 0,
|
||||
expectedHosts: 1
|
||||
});
|
||||
expect(
|
||||
history.temperatures.find((series) => series.hostId === 'disabled')?.points.at(-1)
|
||||
).toMatchObject({ celsius: 65 });
|
||||
});
|
||||
|
||||
it.each(['disabled', 'draining'])(
|
||||
'omits a selected %s host until it is active again',
|
||||
async (mode) => {
|
||||
await host('one');
|
||||
await sample('one', epoch - 45_000);
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
db().prepare('UPDATE ec_hosts SET mode=? WHERE id=?').run(mode, 'one');
|
||||
const { readCapacityHistory } =
|
||||
await import('../../src/lib/server/hosts/capacity-history.js');
|
||||
for (const hostId of [null, 'one']) {
|
||||
const history = readCapacityHistory({ ...query, hostId }, epoch);
|
||||
expect(
|
||||
history.points.every(
|
||||
(point) =>
|
||||
point.cpuCoresAvailable === null &&
|
||||
point.memoryBytesAvailable === null &&
|
||||
point.reportingHosts === 0 &&
|
||||
point.expectedHosts === 0
|
||||
)
|
||||
).toBe(true);
|
||||
}
|
||||
db().prepare("UPDATE ec_hosts SET mode='active' WHERE id='one'").run();
|
||||
const history = readCapacityHistory({ ...query, hostId: 'one' }, epoch);
|
||||
expect(history.points.at(-1)?.cpuCoresAvailable).toBeCloseTo(5.6);
|
||||
expect(history.points.at(-1)).toMatchObject({ reportingHosts: 1, expectedHosts: 1 });
|
||||
}
|
||||
);
|
||||
|
||||
it('scopes history to the selected registered host and does not add hosts before they existed', async () => {
|
||||
await host('one');
|
||||
await host('two', epoch - 30_000);
|
||||
|
||||
Reference in New Issue
Block a user