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

Function TestCall_ContextTimeoutSendsCancel

internal/nodehub/hub_test.go:243–267  ·  view source on GitHub ↗

---- 测试:ctx 超时 + cancel_id 下发 ----

(t *testing.T)

Source from the content-addressed store, hash-verified

241// ---- 测试:ctx 超时 + cancel_id 下发 ----
242
243func TestCall_ContextTimeoutSendsCancel(t *testing.T) {
244 hub := New(Options{PeerExtractor: mdPeerExtractor})
245 env := newTestEnv(t, hub)
246 cc := env.dial(t)
247 mock := startNodeMock(t, cc, "n")
248 waitOnline(t, hub, "n")
249
250 mock.silent.Store(true) // 不响应任何请求
251
252 ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
253 defer cancel()
254 _, err := hub.Call(ctx, "n", "slow", nil)
255 if !errors.Is(err, context.DeadlineExceeded) {
256 t.Fatalf("expected DeadlineExceeded, got %v", err)
257 }
258
259 select {
260 case id := <-mock.cancelIDs:
261 if id == "" {
262 t.Fatalf("expected non-empty cancel_id")
263 }
264 case <-time.After(time.Second):
265 t.Fatal("did not receive cancel_id from server")
266 }
267}
268
269// ---- 测试:ErrNodeOffline ----
270

Callers

nothing calls this directly

Calls 6

newTestEnvFunction · 0.85
startNodeMockFunction · 0.85
waitOnlineFunction · 0.85
dialMethod · 0.80
NewFunction · 0.70
CallMethod · 0.65

Tested by

no test coverage detected