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

Remove test-utility wrapper for Buffer::toString(). #51

Merged
merged 2 commits into from
Jun 27, 2018
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion echo2_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST_P(Echo2IntegrationTest, Echo) {
RawConnectionDriver connection(
lookupPort("listener_0"), buffer,
[&](Network::ClientConnection&, const Buffer::Instance& data) -> void {
response.append(TestUtility::bufferToString(data));
response.append(Buffer::OwnedImpl(data).toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't toString() just be called on data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah -- this is the trick :)

In envoyproxy/envoy#3629 @htuch challenged me why we need another interface function (toString()) which is somewhat overlapping with serialize(). So I noted that removing it from the abstract interface and just having that function on BufferOwned::Impl worked (that's the way it is checked in now).

However it doesn't work to just say buffer_interface_var->toString(), even though it worked to call TestUtility::bufferToString(buffer_interface_var). The reason that worked is that OwnedImpl has an implicit constructor from const BufferInstance&, so the compiler automatically finds that.

So in envoyproxy/envoy#3736 I worked around that by adding the new interface in Buffer::Instance, but in this PR, in a different repo, I don't have that. So I help the compiler out by explicitly constructing the Buffer::OwnedImpl from the Buffer::Instance before referencing.

I could also go back to envoyproxy/envoy#3736 and remove the Buffer::Interface::toString(), and instead rely on explicit construction of an OwnedImpl in order to access its toString(). I think that happens about 10 of the 53 times this gets called in that repo. I'm fine either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also just force merge this even though it doesn't pass tests, and then update the SHA here once the other thing merges. That's probably cleaner?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine with me too if it's OK to wind up with Buffer::Instance::toString() permanently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't follow. It's on the interface in your current PR. At that point, can't you just do data.toString()?

connection.close();
},
GetParam());
Expand Down