---- 测试:ctx 超时 + cancel_id 下发 ----
(t *testing.T)
| 241 | // ---- 测试:ctx 超时 + cancel_id 下发 ---- |
| 242 | |
| 243 | func 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 |
nothing calls this directly
no test coverage detected