import dev.modzuozhi.core.compat.TickProgress; public final class TickProgressRegression { public static void main(String[] args) { TickProgress p = new TickProgress(); check(Double.isNaN(p.snapshot(0).tps()), "unobserved must not claim 20 TPS"); for (int i = 0; i < 200; i++) { p.begin(i * 50_000_000L); p.finish(i * 50_000_000L + 10_000_000L, 10_000_000L, true); } var normal = p.snapshot(10_000_000_000L); check(normal.tps() >= 19.8 && normal.tps() <= 20.1, "real completion rate"); check(normal.averageWorkMs() == 10 && normal.lastWorkMs() == 10, "work MSPT"); p.begin(10_000_000_000L); var stuck = p.snapshot(21_000_000_000L); check(stuck.tps() == 0, "stale samples must decay to zero"); check(stuck.runningMs() == 11000 && stuck.sinceCompletedMs() > 11000, "live blocked duration"); p.finish(22_000_000_000L, 12_000_000_000L, false); var failed = p.snapshot(22_000_000_000L); check(failed.tps() == 0 && failed.failures() == 1, "failed ticks are not successful completions"); check(Double.isNaN(failed.runningMs()), "idle has no running tick"); p.begin(23_000_000_000L); p.finish(23_010_000_000L, 10_000_000L, true); check(p.snapshot(23_010_000_000L).sinceCompletedMs() == 0, "resume records fresh progress"); check(Double.isNaN(new TickProgress().snapshot(24_000_000_000L).tps()), "new world has no stale data"); TickProgress slow = new TickProgress(); for (int i = 0; i < 50; i++) { slow.begin(i * 200_000_000L); slow.finish(i * 200_000_000L + 1_000_000L, 1_000_000L, true); } check(Math.abs(slow.snapshot(10_000_000_000L).tps() - 5) <= 0.1, "1ms work must not hide 5 TPS scheduling cadence"); System.out.println("PASS: actual TPS, no data, stalled tick, stale window, failure and resume"); } private static void check(boolean ok, String message) { if (!ok) throw new AssertionError(message); } }