-- SpiteStream (bidirectional) ---------------------------------------------
(stream listenerrpc.ListenerRPC_SpiteStreamServer)
| 133 | // -- SpiteStream (bidirectional) --------------------------------------------- |
| 134 | |
| 135 | func (s *testServer) SpiteStream(stream listenerrpc.ListenerRPC_SpiteStreamServer) error { |
| 136 | // Validate pipeline_id metadata (mirrors real server). |
| 137 | md, ok := metadata.FromIncomingContext(stream.Context()) |
| 138 | if !ok { |
| 139 | return status.Error(codes.InvalidArgument, "missing metadata") |
| 140 | } |
| 141 | pids := md.Get("pipeline_id") |
| 142 | if len(pids) == 0 || pids[0] == "" { |
| 143 | return status.Error(codes.InvalidArgument, "missing pipeline_id") |
| 144 | } |
| 145 | s.mu.Lock() |
| 146 | missingPipeline := s.missingPipeline |
| 147 | s.mu.Unlock() |
| 148 | if missingPipeline { |
| 149 | return status.Error(codes.NotFound, "Pipeline not found") |
| 150 | } |
| 151 | |
| 152 | ctx := stream.Context() |
| 153 | errCh := make(chan error, 2) |
| 154 | |
| 155 | // Send requests to bridge. |
| 156 | go func() { |
| 157 | for { |
| 158 | select { |
| 159 | case req, ok := <-s.spiteReqCh: |
| 160 | if !ok { |
| 161 | errCh <- context.Canceled // signal stream end |
| 162 | return |
| 163 | } |
| 164 | if err := stream.Send(req); err != nil { |
| 165 | errCh <- err |
| 166 | return |
| 167 | } |
| 168 | case <-ctx.Done(): |
| 169 | return |
| 170 | } |
| 171 | } |
| 172 | }() |
| 173 | |
| 174 | // Receive responses from bridge. |
| 175 | go func() { |
| 176 | for { |
| 177 | resp, err := stream.Recv() |
| 178 | if err != nil { |
| 179 | errCh <- err |
| 180 | return |
| 181 | } |
| 182 | select { |
| 183 | case s.spiteRespCh <- resp: |
| 184 | default: |
| 185 | // drop if buffer full |
| 186 | } |
| 187 | } |
| 188 | }() |
| 189 | |
| 190 | select { |
| 191 | case <-ctx.Done(): |
| 192 | return ctx.Err() |
no test coverage detected