http: prefer to return reference rather than shared ptr for clusterInfo()#44068
Conversation
…fo() Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
| Upstream::ClusterInfoConstSharedPtr cluster() override { | ||
| return decoder_filter_callbacks_.clusterInfo(); | ||
| return decoder_filter_callbacks_.clusterInfoSharedPtr(); | ||
| } |
There was a problem hiding this comment.
Shouldn't this one be split into OptRef and SharedPtr variants too?
There was a problem hiding this comment.
I will prefer to make this be another PR because we need evaluate the usage of the cluster() before changes.
| EXPECT_EQ("", route_config.name()); | ||
| EXPECT_EQ(0, route_config.internalOnlyHeaders().size()); | ||
| auto cluster_info = filter_callbacks->clusterInfo(); | ||
| auto cluster_info = filter_callbacks->clusterInfoSharedPtr(); |
There was a problem hiding this comment.
Shouldn't this one be using the optref variant since it's function-scoped?
Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
|
/retest |
| .WillByDefault(Invoke([&callbacks]() -> OptRef<const Upstream::ClusterInfo> { | ||
| return makeOptRefFromPtr<const Upstream::ClusterInfo>(callbacks.cluster_info_.get()); | ||
| })); | ||
| ON_CALL(callbacks, clusterInfoSharedPtr()) | ||
| .WillByDefault(Invoke([&callbacks]() -> Upstream::ClusterInfoConstSharedPtr { | ||
| return callbacks.cluster_info_; | ||
| })); |
There was a problem hiding this comment.
| .WillByDefault(Invoke([&callbacks]() -> OptRef<const Upstream::ClusterInfo> { | |
| return makeOptRefFromPtr<const Upstream::ClusterInfo>(callbacks.cluster_info_.get()); | |
| })); | |
| ON_CALL(callbacks, clusterInfoSharedPtr()) | |
| .WillByDefault(Invoke([&callbacks]() -> Upstream::ClusterInfoConstSharedPtr { | |
| return callbacks.cluster_info_; | |
| })); | |
| .WillByDefault([&callbacks]() -> OptRef<const Upstream::ClusterInfo> { | |
| return makeOptRefFromPtr<const Upstream::ClusterInfo>(callbacks.cluster_info_.get()); | |
| }); | |
| ON_CALL(callbacks, clusterInfoSharedPtr()) | |
| .WillByDefault([&callbacks]() -> Upstream::ClusterInfoConstSharedPtr { | |
| return callbacks.cluster_info_; | |
| }); |
(Invoke is redundant in modern gmock.)
There was a problem hiding this comment.
Although we can skip the Invoke, but because Invoke be used every where in the test, it may make sense to keep consistency?
There was a problem hiding this comment.
That's how you end up with keeping on replicating outdated code style forever. :)
Not too bothered in this PR though if you want to leave it. Maybe I should have an AI go through and remove all the mock Invokes repo-wide so we can stop cargo-cult-duplicating more of them in. :)
Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
| Router::RouteConstSharedPtr route() override { return route_; } | ||
| OptRef<const Upstream::ClusterInfo> clusterInfo() override { | ||
| return makeOptRefFromPtr<const Upstream::ClusterInfo>(clusterInfoSharedPtr().get()); | ||
| const auto info = |
There was a problem hiding this comment.
This will still require a change if info gets updated to returning a ref (because this will try to make a copy), so it might be better to just put it all in one very long line for future compatibility, but at least this way it'll be a compile-time error rather than a thing that can be accidentally left "the wrong way". :)
|
/retest |
…fo() (envoyproxy#44068) Commit Message: http: prefer to return reference rather than shared ptr for clusterInfo() Additional Description: See envoyproxy#44025 for more detail. Risk Level: low. Testing: n/a. Docs Changes: n/a. Release Notes: n/a. Platform Specific Features: n/a. --------- Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
…fo() (envoyproxy#44068) Commit Message: http: prefer to return reference rather than shared ptr for clusterInfo() Additional Description: See envoyproxy#44025 for more detail. Risk Level: low. Testing: n/a. Docs Changes: n/a. Release Notes: n/a. Platform Specific Features: n/a. --------- Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com> Signed-off-by: Xuyang Tao <taoxuy@google.com>
…fo() (envoyproxy#44068) Commit Message: http: prefer to return reference rather than shared ptr for clusterInfo() Additional Description: See envoyproxy#44025 for more detail. Risk Level: low. Testing: n/a. Docs Changes: n/a. Release Notes: n/a. Platform Specific Features: n/a. --------- Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com> Signed-off-by: Jonathan Wu <jtwu@google.com>
…fo() (envoyproxy#44068) Commit Message: http: prefer to return reference rather than shared ptr for clusterInfo() Additional Description: See envoyproxy#44025 for more detail. Risk Level: low. Testing: n/a. Docs Changes: n/a. Release Notes: n/a. Platform Specific Features: n/a. --------- Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com> Signed-off-by: Nick Shipilov <nick.shipilov.n@gmail.com>
…fo() (envoyproxy#44068) Commit Message: http: prefer to return reference rather than shared ptr for clusterInfo() Additional Description: See envoyproxy#44025 for more detail. Risk Level: low. Testing: n/a. Docs Changes: n/a. Release Notes: n/a. Platform Specific Features: n/a. --------- Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
Commit Message: http: prefer to return reference rather than shared ptr for clusterInfo()
Additional Description:
See #44025 for more detail.
Risk Level: low.
Testing: n/a.
Docs Changes: n/a.
Release Notes: n/a.
Platform Specific Features: n/a.