fix: #21872 Freshness test displays 0 for negative values (#21880)

This commit is contained in:
Shailesh Parmar 2025-06-23 00:14:03 +05:30 committed by GitHub
parent 7a4001f623
commit 520c7d8642
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 82 additions and 19 deletions

View File

@ -85,7 +85,13 @@ const TestSummaryCustomTooltip = (
<span className="font-medium" data-testid={key}>
{key === TABLE_FRESHNESS_KEY && isNumber(value)
? // freshness will always be in seconds, so we need to convert it to milliseconds
convertMillisecondsToHumanReadableFormat(value * 1000)
convertMillisecondsToHumanReadableFormat(
value * 1000,
undefined,
false,
// negative value will be shown as late by
`${t('label.late-by')} `
)
: value}
</span>
</li>

View File

@ -766,6 +766,7 @@
"last-run": "Letzte Ausführung",
"last-run-result": "Ergebnis der letzten Ausführung",
"last-updated": "Zuletzt aktualisiert",
"late-by": "Late by",
"latest": "Neueste",
"latest-offset": "Neuester Offset",
"layer": "Layer",

View File

@ -766,6 +766,7 @@
"last-run": "Last Run",
"last-run-result": "Last Run Result",
"last-updated": "Last Updated",
"late-by": "Late by",
"latest": "Latest",
"latest-offset": "Latest Offset",
"layer": "Layer",

View File

@ -766,6 +766,7 @@
"last-run": "Última ejecución",
"last-run-result": "Último resultado de la ejecución",
"last-updated": "Última actualización",
"late-by": "Tardío por",
"latest": "Último",
"latest-offset": "Último desplazamiento",
"layer": "Layer",

View File

@ -766,6 +766,7 @@
"last-run": "Dernière Exécution",
"last-run-result": "Résultat de la Dernière Exécution",
"last-updated": "Dernière Mise à Jour",
"late-by": "En retard de",
"latest": "Dernier·ère",
"latest-offset": "Dernier décalage",
"layer": "Layer",

View File

@ -766,6 +766,7 @@
"last-run": "Última execución",
"last-run-result": "Resultado da última execución",
"last-updated": "Última actualización",
"late-by": "Tardío por",
"latest": "Último",
"latest-offset": "Último desprazamento",
"layer": "Capa",

View File

@ -766,6 +766,7 @@
"last-run": "הרצה אחרונה",
"last-run-result": "תוצאת הרצה אחרונה",
"last-updated": "עודכן לאחרונה",
"late-by": "מאחורי",
"latest": "אחרון",
"latest-offset": "היסט אחרון",
"layer": "Layer",

View File

@ -766,6 +766,7 @@
"last-run": "Last Run",
"last-run-result": "Last Run Result",
"last-updated": "最終更新日",
"late-by": "遅れています",
"latest": "最新",
"latest-offset": "最新のオフセット",
"layer": "Layer",

View File

@ -766,6 +766,7 @@
"last-run": "마지막 실행",
"last-run-result": "마지막 실행 결과",
"last-updated": "마지막 업데이트",
"late-by": "지연됨",
"latest": "최신",
"latest-offset": "최신 오프셋",
"layer": "계층",

View File

@ -766,6 +766,7 @@
"last-run": "शेवटची धाव",
"last-run-result": "शेवटचा धाव परिणाम",
"last-updated": "शेवटचे अद्यतनित",
"late-by": "विलंबाने",
"latest": "नवीनतम",
"latest-offset": "नवीनतम ऑफसेट",
"layer": "स्तर",

View File

@ -766,6 +766,7 @@
"last-run": "Laatste uitvoering",
"last-run-result": "Laatste uitvoerresultaat",
"last-updated": "Laatst bijgewerkt",
"late-by": "Vooruitgang",
"latest": "Laatste",
"latest-offset": "Laatste offset",
"layer": "Layer",

View File

@ -766,6 +766,7 @@
"last-run": "آخرین اجرا",
"last-run-result": "نتیجه آخرین اجرا",
"last-updated": "آخرین به‌روزرسانی",
"late-by": "تأخیر",
"latest": "آخرین",
"latest-offset": "آخرین آفست",
"layer": "Layer",

View File

@ -766,6 +766,7 @@
"last-run": "Última Execução",
"last-run-result": "Resultado da Última Execução",
"last-updated": "Última Atualização",
"late-by": "Atrasado por",
"latest": "Mais Recente",
"latest-offset": "Último deslocamento",
"layer": "Camada",

View File

@ -766,6 +766,7 @@
"last-run": "Última Execução",
"last-run-result": "Resultado da Última Execução",
"last-updated": "Última Atualização",
"late-by": "Atrasado por",
"latest": "Mais Recente",
"latest-offset": "Latest Offset",
"layer": "Layer",

View File

@ -766,6 +766,7 @@
"last-run": "Последний запуск",
"last-run-result": "Результат последнего запуска",
"last-updated": "Последнее обновление",
"late-by": "Позже на",
"latest": "Последний",
"latest-offset": "Последнее смещение",
"layer": "Layer",

View File

@ -766,6 +766,7 @@
"last-run": "รันล่าสุด",
"last-run-result": "ผลลัพธ์การรันล่าสุด",
"last-updated": "อัปเดตล่าสุด",
"late-by": "ล่าช้า",
"latest": "ล่าสุด",
"latest-offset": "ออฟเซ็ตล่าสุด",
"layer": "ชั้น",

View File

@ -766,6 +766,7 @@
"last-run": "Son Çalışma",
"last-run-result": "Son Çalışma Sonucu",
"last-updated": "Son Güncelleme",
"late-by": "Gecikme",
"latest": "En Son",
"latest-offset": "En Son Ofset",
"layer": "Katman",

View File

@ -766,6 +766,7 @@
"last-run": "最近运行",
"last-run-result": "最近运行结果",
"last-updated": "最近更新",
"late-by": "延迟",
"latest": "最新",
"latest-offset": "最新偏移量",
"layer": "Layer",

View File

@ -149,7 +149,7 @@ describe('convertMillisecondsToHumanReadableFormat', () => {
{ input: 3661000, expected: '1h 1m 1s' },
{ input: 86400000, expected: '1d' },
{ input: 90061000, expected: '1d 1h 1m 1s' },
{ input: -1000, expected: '0s' },
{ input: -1000, expected: '-1s' },
{ input: 1200, expected: '1s 200ms', showMilliseconds: true },
{
input: 90061560,
@ -158,19 +158,40 @@ describe('convertMillisecondsToHumanReadableFormat', () => {
showMilliseconds: true,
},
{ input: 90061560, expected: '1d 1h', length: 2, showMilliseconds: true },
{ input: -61000, expected: '-1m 1s' },
{
input: -3661000,
expected: 'Late by 1h 1m 1s',
prependForNegativeValue: 'Late by ',
},
{ input: -86400000, expected: '-1d' },
{
input: -90061000,
expected: 'Late by 1d 1h 1m 1s',
prependForNegativeValue: 'Late by ',
},
];
testCases.forEach(({ input, expected, length, showMilliseconds }) => {
it(`should return "${expected}" for ${input} milliseconds`, () => {
expect(
convertMillisecondsToHumanReadableFormat(
input,
length,
showMilliseconds
)
).toBe(expected);
});
});
testCases.forEach(
({
input,
expected,
length,
showMilliseconds,
prependForNegativeValue,
}) => {
it(`should return "${expected}" for ${input} milliseconds`, () => {
expect(
convertMillisecondsToHumanReadableFormat(
input,
length,
showMilliseconds,
prependForNegativeValue
)
).toBe(expected);
});
}
);
const testCasesWithLength = [
{

View File

@ -245,13 +245,22 @@ export const calculateInterval = (
export const convertMillisecondsToHumanReadableFormat = (
timestamp: number,
length?: number,
showMilliseconds = false
showMilliseconds = false,
prependForNegativeValue = '-'
): string => {
if (timestamp <= 0 || (!showMilliseconds && timestamp < 1000)) {
// Handle zero and very small positive values
if (
timestamp === 0 ||
(!showMilliseconds && timestamp > 0 && timestamp < 1000)
) {
return '0s';
}
const duration = Duration.fromMillis(timestamp);
// Handle negative values
const isNegative = timestamp < 0;
const absoluteTimestamp = Math.abs(timestamp);
const duration = Duration.fromMillis(absoluteTimestamp);
const result: string[] = [];
// Extract each unit from the duration
@ -286,11 +295,21 @@ export const convertMillisecondsToHumanReadableFormat = (
result.push(`${milliseconds}ms`);
}
if (length && result.length > length) {
return result.slice(0, length).join(' ');
// If no units found, return 0s
if (result.length === 0) {
return '0s';
}
return result.join(' ');
let formattedResult = result.join(' ');
if (length && result.length > length) {
formattedResult = result.slice(0, length).join(' ');
}
// Prepend minus sign for negative values
return isNegative
? `${prependForNegativeValue}${formattedResult}`
: formattedResult;
};
export const formatDuration = (ms: number) => {