Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests #20

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 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 @@ -401,7 +404,7 @@ func (c *Client) sendKeepAlive(ctx context.Context, stream cloudproxyv1alpha.Clo
return fmt.Errorf("stream ended with %w", stream.Context().Err())
}
if err := c.isAlive(); err != nil {
return err
return fmt.Errorf("isAlive: %w", err)
}
}
}
Expand All @@ -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
Loading