startHub 用 bufconn 起一个 nodehub.Hub,PeerExtractor 总是返回 "n1"。
(t *testing.T, ph nodehub.PushHandler)
| 65 | |
| 66 | // startHub 用 bufconn 起一个 nodehub.Hub,PeerExtractor 总是返回 "n1"。 |
| 67 | func startHub(t *testing.T, ph nodehub.PushHandler) (*nodehub.Hub, func(context.Context, string) (net.Conn, error), func()) { |
| 68 | t.Helper() |
| 69 | lis := bufconn.Listen(1 << 20) |
| 70 | srv := grpc.NewServer() |
| 71 | hub := nodehub.New(nodehub.Options{ |
| 72 | PushHandler: ph, |
| 73 | PeerExtractor: func(_ context.Context) (string, error) { return "n1", nil }, |
| 74 | }) |
| 75 | nodev1.RegisterNodeAgentServer(srv, hub) |
| 76 | go func() { _ = srv.Serve(lis) }() |
| 77 | dialer := func(ctx context.Context, _ string) (net.Conn, error) { return lis.DialContext(ctx) } |
| 78 | return hub, dialer, func() { srv.Stop() } |
| 79 | } |
| 80 | |
| 81 | // TestIntegration_HelloAndCall 验证 hello 含 config_hash + hub.Call → dispatcher 路由。 |
| 82 | func TestIntegration_HelloAndCall(t *testing.T) { |
no test coverage detected