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}> <span className="font-medium" data-testid={key}>
{key === TABLE_FRESHNESS_KEY && isNumber(value) {key === TABLE_FRESHNESS_KEY && isNumber(value)
? // freshness will always be in seconds, so we need to convert it to milliseconds ? // 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} : value}
</span> </span>
</li> </li>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -766,6 +766,7 @@
"last-run": "마지막 실행", "last-run": "마지막 실행",
"last-run-result": "마지막 실행 결과", "last-run-result": "마지막 실행 결과",
"last-updated": "마지막 업데이트", "last-updated": "마지막 업데이트",
"late-by": "지연됨",
"latest": "최신", "latest": "최신",
"latest-offset": "최신 오프셋", "latest-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": "विलंबाने",
"latest": "नवीनतम", "latest": "नवीनतम",
"latest-offset": "नवीनतम ऑफसेट", "latest-offset": "नवीनतम ऑफसेट",
"layer": "स्तर", "layer": "स्तर",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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