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

Function TestIntegration_HelloAndCall

internal/nodeagent/integration_test.go:82–157  ·  view source on GitHub ↗

TestIntegration_HelloAndCall 验证 hello 含 config_hash + hub.Call → dispatcher 路由。

(t *testing.T)

Source from the content-addressed store, hash-verified

80
81// TestIntegration_HelloAndCall 验证 hello 含 config_hash + hub.Call → dispatcher 路由。
82func TestIntegration_HelloAndCall(t *testing.T) {
83 t.Parallel()
84 ph := &integrationPushHandler{}
85 hub, dialer, stop := startHub(t, ph)
86 defer stop()
87
88 api := newTestAPI()
89 disp := NewAPIDispatcher(api, nil)
90
91 ctx, cancel := context.WithCancel(context.Background())
92 defer cancel()
93
94 cfg := Config{
95 NodeID: "n1",
96 ServerAddr: "passthrough:///bufnet",
97 Dispatcher: disp,
98 HelloProvider: DefaultHelloProvider("n1", ConfigHasher(api)),
99 Dialer: func(_ context.Context) (*grpc.ClientConn, error) {
100 return grpc.NewClient("passthrough:///bufnet",
101 grpc.WithContextDialer(dialer),
102 grpc.WithTransportCredentials(insecure.NewCredentials()),
103 )
104 },
105 ReconnectBackoff: []time.Duration{20 * time.Millisecond},
106 }
107 done := make(chan error, 1)
108 go func() { done <- Run(ctx, cfg) }()
109 defer func() { cancel(); <-done }()
110
111 deadline := time.Now().Add(2 * time.Second)
112 for time.Now().Before(deadline) {
113 if hb, _ := ph.snapshot(); len(hb) > 0 {
114 break
115 }
116 time.Sleep(20 * time.Millisecond)
117 }
118 hb, _ := ph.snapshot()
119 if len(hb) == 0 {
120 t.Fatalf("no hello received")
121 }
122 var payload struct {
123 NodeID string `json:"node_id"`
124 ConfigHash string `json:"config_hash"`
125 Version string `json:"version"`
126 }
127 if err := json.Unmarshal(hb[0], &payload); err != nil {
128 t.Fatalf("decode hello: %v", err)
129 }
130 if payload.NodeID != "n1" {
131 t.Fatalf("hello node_id=%q want n1", payload.NodeID)
132 }
133 // xray 未启动时 config 字符串为空,hash 也为空;这是已知行为。
134 _ = payload.ConfigHash
135
136 // 等 hub 看到这个 conn 上线。
137 deadline = time.Now().Add(time.Second)
138 for time.Now().Before(deadline) && !hub.IsOnline("n1") {
139 time.Sleep(10 * time.Millisecond)

Callers

nothing calls this directly

Calls 10

snapshotMethod · 0.95
startHubFunction · 0.85
newTestAPIFunction · 0.85
NewAPIDispatcherFunction · 0.85
DefaultHelloProviderFunction · 0.85
ConfigHasherFunction · 0.85
AddMethod · 0.80
IsOnlineMethod · 0.80
RunFunction · 0.70
CallMethod · 0.65

Tested by

no test coverage detected