1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-07-26 19:14:36 +02:00
Files
misskey/packages-private/diagnostics-backend/test/heap-snapshot-sampling.test.ts
syuilo 98ae62c432 enhance(gh): 複数サンプルの値の表示を改善するなど (#17759)
* docs: design backend diagnostics memory noise handling

* chore(gh): tweak workflow

* docs: clarify shared heap snapshot reporting

* docs: plan backend diagnostics memory noise handling

* chore: ignore local worktrees

* feat(diagnostics): add independent delta summary

* feat(diagnostics): make heap snapshot deltas noise-aware

* docs: correct heap snapshot threshold plan

* fix(diagnostics): suppress backend memory noise

* ci: refine backend diagnostics sampling

* test(diagnostics): address final review

* wip

* Update heap-snapshot-sampling.ts

* wip

* wip

* docs: design frontend metric noise reporting

* docs: plan frontend metric noise reporting

* fix(diagnostics): suppress frontend metric noise

* docs: remove temporary frontend metric plans

* test(diagnostics): cover frontend metric thresholds

* docs: design shared diagnostics metric table

* docs: plan shared diagnostics metric table

* refactor(diagnostics): simplify independent delta statistics

* feat(diagnostics): add shared metric table renderer

* refactor(diagnostics): use shared heap snapshot table

* refactor(diagnostics): use shared backend metric table

* refactor(diagnostics): use shared frontend metric table

* docs: remove temporary metric table plans

* tweak

* docs: design metric table no-data output

* fix(diagnostics): show marker for empty metric tables

* chore: remove temporary diagnostics design
2026-07-21 22:43:22 +09:00

43 lines
1.4 KiB
TypeScript

/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { describe, expect, test } from 'vitest';
import {
clampHeapSnapshotRounds,
selectRepresentativeHeapSnapshotRound,
shouldCollectHeapSnapshot,
} from '../src/heap-snapshot-sampling';
describe('heap snapshot sampling', () => {
test('collects only the final requested rounds', () => {
const selected = Array.from({ length: 15 }, (_, index) => index + 1)
.filter(round => shouldCollectHeapSnapshot(round, 15, 3));
expect(selected).toStrictEqual([13, 14, 15]);
});
test('clamps the requested count to the measured round count', () => {
expect(clampHeapSnapshotRounds(5, 20)).toBe(5);
expect(Array.from({ length: 5 }, (_, index) => index + 1)
.filter(round => shouldCollectHeapSnapshot(round, 5, 20)))
.toStrictEqual([1, 2, 3, 4, 5]);
});
test('collects no snapshots when the effective count is zero', () => {
expect(Array.from({ length: 5 }, (_, index) => index + 1)
.filter(round => shouldCollectHeapSnapshot(round, 5, 0)))
.toStrictEqual([]);
});
test('selects the snapshot nearest the median and ignores missing rounds', () => {
const samples = [
{ round: 12, total: null },
{ round: 13, total: 100 },
{ round: 14, total: 110 },
{ round: 15, total: 130 },
];
expect(selectRepresentativeHeapSnapshotRound(samples, 110, sample => sample.total)).toBe(14);
});
});