dashboard: a success rate never rounds up to 100.0% while failures stand
Gates / frontend (push) Successful in 1m27s
Gates / test (push) Successful in 1m53s
Gates / test-aarch64 (push) Successful in 7m7s
Gates / package (push) Successful in 3m57s
Gates / container (push) Successful in 15s
CI / gates (push) Successful in 13m15s
Gates / frontend (push) Successful in 1m27s
Gates / test (push) Successful in 1m53s
Gates / test-aarch64 (push) Successful in 7m7s
Gates / package (push) Successful in 3m57s
Gates / container (push) Successful in 15s
CI / gates (push) Successful in 13m15s
This commit is contained in:
@@ -149,3 +149,32 @@ test("an empty pool says so instead of drawing a table", () => {
|
||||
expect(screen.getByText("No upstreams configured.")).toBeTruthy();
|
||||
expect(screen.queryByRole("table")).toBeNull();
|
||||
});
|
||||
|
||||
test("a rate a hair under perfect never rounds up to 100.0% while failures stand", () => {
|
||||
// The real row that produced this: 12,698 attempts, 2 failures, 99.984%.
|
||||
renderTable([
|
||||
entry({
|
||||
period: period({ attempts: 12_698, successes: 12_696, failures: 2, success_rate: 12_696 / 12_698 }),
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(screen.queryByText("100.0%")).toBeNull();
|
||||
expect(screen.getByText("99.9%")).toBeTruthy();
|
||||
});
|
||||
|
||||
test("a rate a hair above nothing never rounds down to 0.0% while successes stand", () => {
|
||||
renderTable([
|
||||
entry({
|
||||
period: period({ attempts: 12_698, successes: 2, failures: 12_696, success_rate: 2 / 12_698 }),
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(screen.queryByText("0.0%")).toBeNull();
|
||||
expect(screen.getByText("0.1%")).toBeTruthy();
|
||||
});
|
||||
|
||||
test("a window with no failures at all still reads 100.0%", () => {
|
||||
renderTable([entry({ period: period({ attempts: 500, successes: 500, failures: 0, success_rate: 1 }) })]);
|
||||
|
||||
expect(screen.getByText("100.0%")).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -122,9 +122,18 @@ function statusNow(upstream: UpstreamHealthEntry): "Available" | "Backing off" |
|
||||
/**
|
||||
* `success_rate` is null exactly when the window holds no attempt, and that must
|
||||
* not read as perfect reliability — hence the em-dash rather than `100.0%`.
|
||||
*
|
||||
* One decimal place cannot hold 12,696 of 12,698: it rounds to `100.0%`, and the
|
||||
* row then claims perfection beside a failure count of 2. Neither endpoint may
|
||||
* be reached by rounding — only by actually having no failure, or no success.
|
||||
*/
|
||||
function successRate(period: UpstreamPeriodStats): string {
|
||||
return period.success_rate === null ? "—" : `${(period.success_rate * 100).toFixed(1)}%`;
|
||||
if (period.success_rate === null) return "—";
|
||||
|
||||
const rounded = period.success_rate * 100;
|
||||
if (rounded > 99.9 && period.failures > 0) return "99.9%";
|
||||
if (rounded < 0.1 && period.successes > 0) return "0.1%";
|
||||
return `${rounded.toFixed(1)}%`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user