Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ValyaB committed Oct 4, 2024
1 parent 4952af9 commit cf5b9d1
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 170 deletions.
13 changes: 8 additions & 5 deletions internal/proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ func (c *Client) send(ctx context.Context, stream cloudproxyv1alpha.CloudProxyAP
return ctx.Err()
case <-stream.Context().Done():
return fmt.Errorf("stream closed %w", stream.Context().Err())
case req := <-c.sendCh:
case req, ok := <-c.sendCh:
if !ok {
return fmt.Errorf("send channel closed %w", ctx.Err())
}
c.log.Printf("Sending message to stream %v len=%v", req.GetResponse().GetMessageId(), len(req.GetResponse().GetHttpResponse().GetBody()))
if err := stream.Send(req); err != nil {
c.log.WithError(err).Warn("failed to send message to stream")
Expand Down Expand Up @@ -329,7 +332,7 @@ func (c *Client) processHTTPRequest(req *cloudproxyv1alpha.HTTPRequest) *cloudpr
Error: lo.ToPtr("nil http request"),
}
}
httpReq, err := c.toHTTPRequest(req)
httpReq, err := toHTTPRequest(req)
if err != nil {
return &cloudproxyv1alpha.HTTPResponse{
Error: lo.ToPtr(fmt.Sprintf("toHTTPRequest: %v", err)),
Expand All @@ -344,7 +347,7 @@ func (c *Client) processHTTPRequest(req *cloudproxyv1alpha.HTTPRequest) *cloudpr
}
c.processedCount.Add(1)

return c.toResponse(resp)
return toResponse(resp)
}

var errAlive = fmt.Errorf("client connection is not alive")
Expand Down Expand Up @@ -411,7 +414,7 @@ func (c *Client) sendKeepAlive(ctx context.Context, stream cloudproxyv1alpha.Clo

var errBadRequest = fmt.Errorf("bad request")

func (c *Client) toHTTPRequest(req *cloudproxyv1alpha.HTTPRequest) (*http.Request, error) {
func toHTTPRequest(req *cloudproxyv1alpha.HTTPRequest) (*http.Request, error) {
if req == nil {
return nil, fmt.Errorf("nil http request %w", errBadRequest)
}
Expand All @@ -430,7 +433,7 @@ func (c *Client) toHTTPRequest(req *cloudproxyv1alpha.HTTPRequest) (*http.Reques
return reqHTTP, nil
}

func (c *Client) toResponse(resp *http.Response) *cloudproxyv1alpha.HTTPResponse {
func toResponse(resp *http.Response) *cloudproxyv1alpha.HTTPResponse {
if resp == nil {
return &cloudproxyv1alpha.HTTPResponse{
Error: lo.ToPtr("nil response"),
Expand Down
Loading

0 comments on commit cf5b9d1

Please sign in to comment.