-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add an unused implementation NoOpTransportSocketCallbacks #4181
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
Changes from 6 commits
bf1cee8
dffd2d1
d1a9c25
a85ec49
b8605bd
41f9978
d97d11f
dd1f97a
2bb3bbe
d2755dc
de8caf3
f0aeb4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include "envoy/network/transport_socket.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace TransportSockets { | ||
| namespace Alts { | ||
|
|
||
| /** | ||
| * A TransportSocketCallbacks for wrapped TransportSocket object. Some | ||
| * TransportSocket implementation wraps another socket which does actual I/O. | ||
| * This class is used by the wrapped socket as its callbacks instead of the real | ||
| * connection to hold back callbacks from the underlying socket to connection. | ||
| */ | ||
| class NoOpTransportSocketCallbacks : public Network::TransportSocketCallbacks { | ||
| public: | ||
| explicit NoOpTransportSocketCallbacks(Network::TransportSocket* parent) : parent_(parent) {} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah if you delay creating TransportSocketCallbacks, i.e. in parent setTransportSocketCallbacks, you should be able to just take
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point! Done. |
||
|
|
||
| int fd() const override { return parent_->callbacks()->fd(); } | ||
| Network::Connection& connection() override { return parent_->callbacks()->connection(); } | ||
| bool shouldDrainReadBuffer() override { return false; } | ||
| /* | ||
| * No-op for these two methods to hold back the callbacks. | ||
| */ | ||
| void setReadBufferReady() override {} | ||
| void raiseEvent(Network::ConnectionEvent) override {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with this landing as is, but can you please loop me in when it is used? I have some concerns about these particular events being swallowed. Maybe we can add ASSERTs that they're not used so we'll at least catch it in debug builds if a mistake is made? Hopefully seeing where the code is used will allay my concerns :-)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ACK'ed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alyssawilk I will merge master and use this in my PR #4153, ASSERT cannot be added here. In #4153, it have to swallow |
||
|
|
||
| private: | ||
| Network::TransportSocket* parent_; | ||
| }; | ||
|
|
||
| } // namespace Alts | ||
| } // namespace TransportSockets | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #include "extensions/transport_sockets/alts/noop_transport_socket_callbacks.h" | ||
|
|
||
| #include "test/mocks/network/mocks.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace TransportSockets { | ||
| namespace Alts { | ||
| namespace { | ||
|
|
||
| class TestTransportSocketCallbacks : public Network::TransportSocketCallbacks { | ||
| public: | ||
| TestTransportSocketCallbacks(Network::Connection* connection) : connection_(connection) {} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if connection_ couldn't be null, make it a reference. also make constructor explicit
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
|
||
| int fd() const override { return 1; } | ||
| Network::Connection& connection() override { return *connection_; } | ||
| bool shouldDrainReadBuffer() override { return false; } | ||
| void setReadBufferReady() override { set_read_buffer_ready_ = true; } | ||
| void raiseEvent(Network::ConnectionEvent) override { event_raised_ = true; } | ||
|
|
||
| bool event_raised() const { return event_raised_; } | ||
| bool set_read_buffer_ready() const { return set_read_buffer_ready_; } | ||
|
|
||
| private: | ||
| bool event_raised_{false}; | ||
| bool set_read_buffer_ready_{false}; | ||
| Network::Connection* connection_; | ||
| }; | ||
|
|
||
| class NoOpTransportSocketCallbacksTest : public testing::Test { | ||
| protected: | ||
| NoOpTransportSocketCallbacksTest() | ||
| : wrapper_callbacks_(&connection_), wrapped_callbacks_(&wrapper_socket_) { | ||
| wrapper_socket_.setTransportSocketCallbacks(wrapper_callbacks_); | ||
| } | ||
|
|
||
| Network::MockConnection connection_; | ||
| TestTransportSocketCallbacks wrapper_callbacks_; | ||
| Network::MockTransportSocket wrapper_socket_; | ||
| NoOpTransportSocketCallbacks wrapped_callbacks_; | ||
| }; | ||
|
|
||
| TEST_F(NoOpTransportSocketCallbacksTest, TestAllCallbacks) { | ||
| EXPECT_EQ(wrapper_callbacks_.fd(), wrapped_callbacks_.fd()); | ||
| EXPECT_EQ(&connection_, &wrapped_callbacks_.connection()); | ||
| EXPECT_FALSE(wrapped_callbacks_.shouldDrainReadBuffer()); | ||
|
|
||
| wrapped_callbacks_.setReadBufferReady(); | ||
| EXPECT_FALSE(wrapper_callbacks_.set_read_buffer_ready()); | ||
| wrapped_callbacks_.raiseEvent(Network::ConnectionEvent::Connected); | ||
| EXPECT_FALSE(wrapper_callbacks_.event_raised()); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace Alts | ||
| } // namespace TransportSockets | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -428,7 +428,9 @@ class MockTransportSocket : public TransportSocket { | |
| MockTransportSocket(); | ||
| ~MockTransportSocket(); | ||
|
|
||
| MOCK_METHOD1(setTransportSocketCallbacks, void(TransportSocketCallbacks& callbacks)); | ||
| void setTransportSocketCallbacks(TransportSocketCallbacks& callbacks) override { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep this (and This will allow test to do EXPECT_CALL etc.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| callbacks_ = &callbacks; | ||
| } | ||
| MOCK_CONST_METHOD0(protocol, std::string()); | ||
| MOCK_METHOD0(canFlushClose, bool()); | ||
| MOCK_METHOD1(closeSocket, void(Network::ConnectionEvent event)); | ||
|
|
@@ -437,6 +439,10 @@ class MockTransportSocket : public TransportSocket { | |
| MOCK_METHOD0(onConnected, void()); | ||
| MOCK_METHOD0(ssl, Ssl::Connection*()); | ||
| MOCK_CONST_METHOD0(ssl, const Ssl::Connection*()); | ||
| Network::TransportSocketCallbacks* callbacks() override { return callbacks_; } | ||
|
|
||
| private: | ||
| Network::TransportSocketCallbacks* callbacks_; | ||
| }; | ||
|
|
||
| class MockTransportSocketFactory : public TransportSocketFactory { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this as I think where you need get
callbacksis in the scope you set it. No strong opinion on it though. If this is needed internally, ping me on hangout.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done