Activator unit tests#1689
Conversation
|
/assign @josephburnett @akyyy @mdemirhan |
| } | ||
| } | ||
|
|
||
| func (h uploadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
There was a problem hiding this comment.
Can you define the method on the pointer rather than the value type?
func (h *uploadHandler) ServeHTTP(...)
| } | ||
| } | ||
|
|
||
| func (fa fakeActivator) ActiveEndpoint(namespace, name string) (activator.Endpoint, activator.Status, error) { |
There was a problem hiding this comment.
Define the func on the pointer rather than the value type.
| var baseTransport http.RoundTripper = roundTripperFunc(func(r *http.Request) (*http.Response, error) { | ||
| var transport http.RoundTripper = http.DefaultTransport | ||
| if r.ProtoMajor == 2 { | ||
| transport = h2cutil.DefaultTransport |
There was a problem hiding this comment.
My preference would be getting rid of this func and providing http1 and http2 transports as inputs to the rountripper. That way, we will get better coverage (i.e. the logic to select rounttripper is also covered) and also the tests wouldn't have to know the internals of rounttripper as much.
See: https://github.com/mdemirhan/serving/blob/2bf10f2fca8e56ea174b3259287f62bc2385f26c/pkg/activator/httptransport.go#L33 as an example.
And corresponding fake transport: https://github.com/mdemirhan/serving/blob/2bf10f2fca8e56ea174b3259287f62bc2385f26c/pkg/activator/httptransport_test.go#L38
And table tests:
https://github.com/mdemirhan/serving/blob/2bf10f2fca8e56ea174b3259287f62bc2385f26c/pkg/activator/httptransport_test.go#L69
There was a problem hiding this comment.
It feels a little weird to have RetryRoundTripper be concerned with transport protocol selection. If there was better test coverage, would you be OK with keeping this logic separate?
There was a problem hiding this comment.
Yes, that sounds good to me. Thanks!
| if resp.StatusCode == status { | ||
| resp.Body.Close() | ||
|
|
||
| return nil, fmt.Errorf("Filtering %d", status) |
There was a problem hiding this comment.
Converting an HTTP response to error doesn't seem right. This will definitely confuse people who are debugging this.
Instead of making this two roundtrippers that are chained together, can you simply get a func as an input: something like type ShouldRetryFunc func(*http.Response) (bool) and removing the statusFilterRoundTripper in favor of this func.
There was a problem hiding this comment.
Yeah, that makes sense. I'll take a stab at this.
| } | ||
|
|
||
| // TODO: add metrics for number of tries and the response code. | ||
| if resp != nil { |
There was a problem hiding this comment.
Can you change this so that we also log error cases? It seems weird that we log happy path but not unhappy path. Something like:
if resp != nil {
rrt.logger.Infof("Activation finished after %d attempt(s). Response code: %d", i, resp.StatusCode)
} else {
rrt.logger.Errorf("Activation failed after %d attempts. Last error: %v", i, err)
}
| status int | ||
| err error | ||
| }{ | ||
| {"filtered status", goodRT, 502, errors.New("Filtering 502")}, |
There was a problem hiding this comment.
Test cases here seem to be too limited. Can we add tests to cover all the cases listed below?
There was a problem hiding this comment.
Sure, I'll add test cases for http1/http2. I think everything else is covered in other, separate tests?
There was a problem hiding this comment.
Actually there are a few more. List of test cases to add so far:
- http1/http2
- nil response body
There was a problem hiding this comment.
Is the nil response body check actually necessary? From the source, Response Body is guaranteed to be non-nil:
https://github.com/golang/go/blob/master/src/net/http/response.go#L57-L62
35294e6 to
70952ff
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tanzeeb If they are not already assigned, you can assign the PR to them by writing The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Thanks for the feedback @mdemirhan. I've made some updates to the |
Refactored retryRoundTripper and activationHandler into multiple components to make testing simpler. Fixes knative#1231
…dition as parameters
Co-authored-by: Nader Ziada <nziada@pivotal.io> Co-authored-by: David Protasowski <dprotasowski@pivotal.io>
f57f317 to
41287ba
Compare
|
The following is the coverage report on pkg/.
|
dprotaso
left a comment
There was a problem hiding this comment.
I helped wrap this up so I approve ;)
|
|
||
| // NewLinearRetryer will return a retryer that retries `action` up to | ||
| // `maxRetries` times with `interval` delay between retries | ||
| func NewLinearRetryer(interval time.Duration, maxRetries int) Retryer { |
There was a problem hiding this comment.
@markusthoemmes is adding exponential backoff in #1814 and I've suggested to @pivotal-sukhil-suresh to reuse that code in #1665 (review). This would be a good way to do that reuse, with an ExponentialRetrier.
So there are three changes in-flight in this space. I'm not sure what order they should land in. Any suggestions?
There was a problem hiding this comment.
I'd suggest to land this one first. Then I can base my PR on top of it (I felt bad because I had no tests anyway) and then @pivotal-sukhil-suresh can base off of mine to gain the ability of having an exponential backoff. WDYT @josephburnett
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dprotaso, josephburnett, tanzeeb The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@mdemirhan is on leave. It looks like all his review comments have been addressed. |
|
Thanks @josephburnett, will look at #1665 with @pivotal-sukhil-suresh after @markusthoemmes PR is merged in. |
Was originally fixed in knative#1733, but accidentally reverted in knative#1689
Refactored
retryRoundTripperandactivationHandlerinto multiplecomponents to make testing simpler.
Fixes #1231
(Continuation of #1585)