Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

770 B
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";
import { consumeEventLoopPeakMs } from "../../src/lib/healthzLag.ts";

test("a large recent stall is not diluted by lifetime mean and is consumed once", () => {
  const histogram = {
    max: 90_000_000_000,
    mean: 20_100_000,
    reset() {
      this.max = 0;
    },
  };
  assert.equal(consumeEventLoopPeakMs(histogram), 90000);
  assert.equal(consumeEventLoopPeakMs(histogram), 0);
});

test("an uninitialized or non-finite sample is not a warning", () => {
  for (const max of [0, NaN, Infinity]) {
    let resets = 0;
    assert.equal(
      consumeEventLoopPeakMs({
        max,
        reset() {
          resets++;
        },
      }),
      0
    );
    assert.equal(resets, 1);
  }
});