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

Function TestSession_ReconnectKicksOld

internal/nodehub/hub_test.go:326–354  ·  view source on GitHub ↗

---- 测试:重连踢旧连接 ----

(t *testing.T)

Source from the content-addressed store, hash-verified

324// ---- 测试:重连踢旧连接 ----
325
326func TestSession_ReconnectKicksOld(t *testing.T) {
327 hub := New(Options{PeerExtractor: mdPeerExtractor})
328 env := newTestEnv(t, hub)
329
330 cc1 := env.dial(t)
331 mock1 := startNodeMock(t, cc1, "same-id")
332 waitOnline(t, hub, "same-id")
333
334 // 第二次连接(同一 nodeID)
335 cc2 := env.dial(t)
336 _ = startNodeMock(t, cc2, "same-id")
337
338 // 旧连接的 closed 通道应该被关闭,且老 stream 在 server 侧的 conn 注册被替换。
339 // 我们通过观察 hub.OnlineNodes() 仍只有 1 个 + 老 mock 的 done 关闭来验证。
340 // 关闭老 client conn 让其 Recv 返回 EOF:
341 _ = cc1.Close()
342
343 select {
344 case <-mock1.done:
345 // ok
346 case <-time.After(2 * time.Second):
347 t.Fatal("old session did not exit after reconnect")
348 }
349
350 online := hub.OnlineNodes()
351 if len(online) != 1 || online[0] != "same-id" {
352 t.Fatalf("expected single online node 'same-id', got %v", online)
353 }
354}
355
356// ---- 测试:usage_push ack ----
357

Callers

nothing calls this directly

Calls 7

newTestEnvFunction · 0.85
startNodeMockFunction · 0.85
waitOnlineFunction · 0.85
dialMethod · 0.80
OnlineNodesMethod · 0.80
NewFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected