1
0
Files
DiAL/docs/user/checkers/ws.md

2.8 KiB
Raw Permalink Blame History

WS Checker

type: ws 用于 WebSocket 服务可达性检查和消息交互验证。

配置项

字段 说明 必填 默认值
ws.url 目标 URL必须以 ws://wss:// 开头
ws.headers 握手 HTTP 头 {}
ws.subprotocols 子协议协商 []
ws.ignoreSSL 忽略 TLS 证书校验 false
ws.send 发送的 text 消息,配置后进入请求-响应模式
ws.receiveTimeout 等待响应超时,毫秒 5000
ws.maxMessageBytes 单条消息最大字节数,支持 KBMBGB 单位 4KB

expect 校验项

字段 说明 必填 默认值
connected 期望连接结果,true 可达或 false 期望不可达 true
handshakeHeaders 握手响应头校验,使用 KeyedExpectations
message 收到的消息内容校验,使用 ContentExpectations 数组,需配置 ws.send
connectTimeMs 连接建立耗时校验,使用 ValueMatcher
durationMs 完整执行耗时校验,使用 ValueMatcher

两种模式

不配置 ws.send 时只做可达性检查(连接后立即关闭),配置 ws.send 后进入请求-响应模式(发送消息并等待首条响应)。

示例

可达性检查:

- id: "ws-reachability"
  name: "WebSocket 服务可达"
  type: ws
  ws:
    url: "wss://api.example.com/ws"
  expect:
    durationMs:
      lte: 3000

带鉴权的请求-响应:

- id: "ws-echo"
  name: "WebSocket Echo 检查"
  type: ws
  ws:
    url: "wss://echo.example.com/ws"
    headers:
      Authorization: "Bearer ${TOKEN}"
    subprotocols: ["json"]
    send: '{"action":"ping"}'
    receiveTimeout: 3000
  expect:
    handshakeHeaders:
      Sec-WebSocket-Protocol:
        equals: "json"
    message:
      - json:
          path: "$.action"
          equals: "pong"
    durationMs:
      lte: 5000

期望不可达:

- id: "ws-internal-down"
  name: "内部服务已下线"
  type: ws
  ws:
    url: "ws://internal.monitor:9443/ws"
  expect:
    connected: false