惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
Y
Y Combinator Blog
IT之家
IT之家
博客园 - 聂微东
L
LangChain Blog
爱范儿
爱范儿
H
Help Net Security
GbyAI
GbyAI
F
Fortinet All Blogs
B
Blog
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
D
DataBreaches.Net
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(discord): avoid false heartbeat ACK timeouts · opencl...
bryce-d-grey · 2026-05-06 · via Recent Commits to openclaw:main

@@ -0,0 +1,114 @@

1+

import { afterEach, describe, expect, it, vi } from "vitest";

2+

import { GatewayHeartbeatTimers } from "./gateway-lifecycle.js";

3+4+

describe("GatewayHeartbeatTimers", () => {

5+

afterEach(() => {

6+

vi.restoreAllMocks();

7+

vi.useRealTimers();

8+

});

9+10+

it("does not false-timeout when the first heartbeat fires near the interval boundary", () => {

11+

vi.useFakeTimers();

12+13+

const onHeartbeat = vi.fn();

14+

const onAckTimeout = vi.fn();

15+

const isAcked = vi.fn().mockReturnValue(false);

16+

const timers = new GatewayHeartbeatTimers();

17+18+

timers.start({

19+

intervalMs: 45_000,

20+

isAcked,

21+

onAckTimeout,

22+

onHeartbeat,

23+

random: () => 0.95,

24+

});

25+26+

vi.advanceTimersByTime(42_750);

27+

expect(onHeartbeat).toHaveBeenCalledTimes(1);

28+

expect(onAckTimeout).not.toHaveBeenCalled();

29+30+

vi.advanceTimersByTime(2_250);

31+

expect(onAckTimeout).not.toHaveBeenCalled();

32+33+

isAcked.mockReturnValue(true);

34+

vi.advanceTimersByTime(42_750);

35+

expect(onHeartbeat).toHaveBeenCalledTimes(2);

36+

expect(onAckTimeout).not.toHaveBeenCalled();

37+38+

timers.stop();

39+

});

40+41+

it("fires an ACK timeout when a heartbeat is genuinely not acknowledged", () => {

42+

vi.useFakeTimers();

43+44+

const timers = new GatewayHeartbeatTimers();

45+

const onHeartbeat = vi.fn();

46+

const onAckTimeout = vi.fn();

47+48+

timers.start({

49+

intervalMs: 45_000,

50+

isAcked: () => false,

51+

onAckTimeout,

52+

onHeartbeat,

53+

random: () => 0,

54+

});

55+56+

vi.advanceTimersByTime(0);

57+

expect(onHeartbeat).toHaveBeenCalledTimes(1);

58+59+

vi.advanceTimersByTime(45_000);

60+

expect(onAckTimeout).toHaveBeenCalledTimes(1);

61+62+

timers.stop();

63+

});

64+65+

it("sends heartbeats at regular intervals after the initial random delay", () => {

66+

vi.useFakeTimers();

67+68+

const timers = new GatewayHeartbeatTimers();

69+

const onHeartbeat = vi.fn();

70+

const onAckTimeout = vi.fn();

71+72+

timers.start({

73+

intervalMs: 10_000,

74+

isAcked: () => true,

75+

onAckTimeout,

76+

onHeartbeat,

77+

random: () => 0.5,

78+

});

79+80+

vi.advanceTimersByTime(5_000);

81+

expect(onHeartbeat).toHaveBeenCalledTimes(1);

82+83+

vi.advanceTimersByTime(10_000);

84+

expect(onHeartbeat).toHaveBeenCalledTimes(2);

85+86+

vi.advanceTimersByTime(10_000);

87+

expect(onHeartbeat).toHaveBeenCalledTimes(3);

88+

expect(onAckTimeout).not.toHaveBeenCalled();

89+90+

timers.stop();

91+

});

92+93+

it("stop cancels all pending timers", () => {

94+

vi.useFakeTimers();

95+96+

const timers = new GatewayHeartbeatTimers();

97+

const onHeartbeat = vi.fn();

98+

const onAckTimeout = vi.fn();

99+100+

timers.start({

101+

intervalMs: 10_000,

102+

isAcked: () => true,

103+

onAckTimeout,

104+

onHeartbeat,

105+

random: () => 0.5,

106+

});

107+108+

timers.stop();

109+

vi.advanceTimersByTime(100_000);

110+111+

expect(onHeartbeat).not.toHaveBeenCalled();

112+

expect(onAckTimeout).not.toHaveBeenCalled();

113+

});

114+

});