()
| 125 | } |
| 126 | |
| 127 | func (m *nodeMock) recvLoop() { |
| 128 | defer close(m.done) |
| 129 | for { |
| 130 | msg, err := m.stream.Recv() |
| 131 | if err != nil { |
| 132 | return |
| 133 | } |
| 134 | if msg.GetCancelId() != "" { |
| 135 | select { |
| 136 | case m.cancelIDs <- msg.GetCancelId(): |
| 137 | default: |
| 138 | } |
| 139 | continue |
| 140 | } |
| 141 | if msg.GetMethod() == "ack" { |
| 142 | select { |
| 143 | case m.acks <- msg.GetBody(): |
| 144 | default: |
| 145 | } |
| 146 | continue |
| 147 | } |
| 148 | // 普通请求 |
| 149 | m.mu.Lock() |
| 150 | fn, ok := m.handlers[msg.GetMethod()] |
| 151 | m.mu.Unlock() |
| 152 | if m.silent.Load() { |
| 153 | continue |
| 154 | } |
| 155 | if !ok { |
| 156 | // 默认回 ok=true, body=null |
| 157 | m.sendNode(&nodev1.NodeMessage{Id: msg.GetId(), Ok: true}) |
| 158 | continue |
| 159 | } |
| 160 | ok2, body, errStr := fn(msg.GetId(), msg.GetBody()) |
| 161 | m.sendNode(&nodev1.NodeMessage{Id: msg.GetId(), Ok: ok2, Body: body, Error: errStr}) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | func (m *nodeMock) sendNode(msg *nodev1.NodeMessage) { |
| 166 | m.sendMu.Lock() |
no test coverage detected