MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / TestReaper_KeepsActiveConnection

Function TestReaper_KeepsActiveConnection

internal/nodehub/keepalive_test.go:56–97  ·  view source on GitHub ↗

TestReaper_KeepsActiveConnection 验证持续发帧的连接不会被 reaper 误杀。

(t *testing.T)

Source from the content-addressed store, hash-verified

54
55// TestReaper_KeepsActiveConnection 验证持续发帧的连接不会被 reaper 误杀。
56func TestReaper_KeepsActiveConnection(t *testing.T) {
57 hub := New(Options{
58 PeerExtractor: mdPeerExtractor,
59 DeadConnectionTimeout: 100 * time.Millisecond,
60 ReaperInterval: 20 * time.Millisecond,
61 })
62 env := newTestEnv(t, hub)
63
64 ctx, cancel := context.WithCancel(context.Background())
65 t.Cleanup(cancel)
66 go hub.RunReaper(ctx)
67
68 cc := env.dial(t)
69 mock := startNodeMock(t, cc, "alive-node")
70 waitOnline(t, hub, "alive-node")
71
72 stopPing := make(chan struct{})
73 defer close(stopPing)
74 go func() {
75 var seq uint64
76 ticker := time.NewTicker(30 * time.Millisecond)
77 defer ticker.Stop()
78 for {
79 select {
80 case <-stopPing:
81 return
82 case <-ticker.C:
83 seq++
84 mock.pushUsage(seq, []byte(`{}`))
85 }
86 }
87 }()
88
89 // 跑 500ms(>5x DeadConnectionTimeout),节点应一直在线。
90 end := time.Now().Add(500 * time.Millisecond)
91 for time.Now().Before(end) {
92 if !hub.IsOnline("alive-node") {
93 t.Fatalf("alive-node was reaped despite continuous traffic")
94 }
95 time.Sleep(50 * time.Millisecond)
96 }
97}
98
99// TestServerKeepaliveDefaults 仅做编译/默认填充层面的 sanity check:
100// 调用 ListenAndServe 的代码路径会在所有 keepalive 字段为 0 时填充默认值。

Callers

nothing calls this directly

Calls 11

newTestEnvFunction · 0.85
startNodeMockFunction · 0.85
waitOnlineFunction · 0.85
CleanupMethod · 0.80
RunReaperMethod · 0.80
dialMethod · 0.80
pushUsageMethod · 0.80
AddMethod · 0.80
IsOnlineMethod · 0.80
NewFunction · 0.70
StopMethod · 0.65

Tested by

no test coverage detected