-
Notifications
You must be signed in to change notification settings - Fork 5.3k
tcp: extending tcp integration test #14451
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
Merged
alyssawilk
merged 3 commits into
envoyproxy:master
from
alyssawilk:tcp_integration_test
Dec 17, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
|
|
||
| using testing::_; | ||
| using testing::AtLeast; | ||
| using testing::HasSubstr; | ||
| using testing::Invoke; | ||
| using testing::MatchesRegex; | ||
| using testing::NiceMock; | ||
|
|
@@ -150,6 +151,86 @@ TEST_P(TcpProxyIntegrationTest, TcpProxyDownstreamDisconnect) { | |
| tcp_client->waitForDisconnect(); | ||
| } | ||
|
|
||
| TEST_P(TcpProxyIntegrationTest, TcpProxyManyConnections) { | ||
| autonomous_upstream_ = true; | ||
| initialize(); | ||
| const int num_connections = 50; | ||
| std::vector<IntegrationTcpClientPtr> clients(num_connections); | ||
|
|
||
| for (int i = 0; i < num_connections; ++i) { | ||
| clients[i] = makeTcpConnection(lookupPort("tcp_proxy")); | ||
| } | ||
| test_server_->waitForCounterGe("cluster.cluster_0.upstream_cx_total", num_connections); | ||
| for (int i = 0; i < num_connections; ++i) { | ||
| IntegrationTcpClientPtr& tcp_client = clients[i]; | ||
| // The autonomous upstream is an HTTP upstream, so send raw HTTP. | ||
| // This particular request will result in the upstream sending a response, | ||
| // and flush-closing due to the 'close_after_response' header. | ||
| ASSERT_TRUE(tcp_client->write( | ||
| "GET / HTTP/1.1\r\nHost: foo\r\nclose_after_response: yes\r\ncontent-length: 0\r\n\r\n", | ||
| false)); | ||
| tcp_client->waitForHalfClose(); | ||
| tcp_client->close(); | ||
| EXPECT_THAT(tcp_client->data(), HasSubstr("aaaaaaaaaa")); | ||
| } | ||
| } | ||
|
|
||
| TEST_P(TcpProxyIntegrationTest, TcpProxyRandomBehavior) { | ||
| autonomous_upstream_ = true; | ||
| initialize(); | ||
| std::list<IntegrationTcpClientPtr> clients; | ||
|
|
||
| // The autonomous upstream parses HTTP, and HTTP headers and sends responses | ||
| // when full requests are received. basic_request will result in | ||
| // bidirectional data. request_with_close will result in bidirectional data, | ||
| // but also the upstream closing the connection. | ||
| const char* basic_request = "GET / HTTP/1.1\r\nHost: foo\r\ncontent-length: 0\r\n\r\n"; | ||
| const char* request_with_close = | ||
| "GET / HTTP/1.1\r\nHost: foo\r\nclose_after_response: yes\r\ncontent-length: 0\r\n\r\n"; | ||
| TestRandomGenerator rand; | ||
|
|
||
| // Seed some initial clients | ||
| for (int i = 0; i < 5; ++i) { | ||
| clients.push_back(makeTcpConnection(lookupPort("tcp_proxy"))); | ||
| } | ||
|
|
||
| // Now randomly write / add more connections / close. | ||
| for (int i = 0; i < 50; ++i) { | ||
| int action = rand.random() % 3; | ||
|
|
||
| if (action == 0) { | ||
| // Add a new connection. | ||
| clients.push_back(makeTcpConnection(lookupPort("tcp_proxy"))); | ||
| } | ||
| if (clients.empty()) { | ||
| break; | ||
|
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. It looks like 2/3 of the time this test will do nothing; is that intended? Do you want to seed the list with a few clients first? |
||
| } | ||
| IntegrationTcpClientPtr& tcp_client = clients.front(); | ||
| if (action == 1) { | ||
| // Write to the first connection. | ||
| ASSERT_TRUE(tcp_client->write(basic_request, false)); | ||
| tcp_client->waitForData("\r\n\r\n", false); | ||
| tcp_client->clearData(tcp_client->data().size()); | ||
| } else if (action == 2) { | ||
| // Close the first connection. | ||
| ASSERT_TRUE(tcp_client->write(request_with_close, false)); | ||
| tcp_client->waitForData("\r\n\r\n", false); | ||
| tcp_client->waitForHalfClose(); | ||
| tcp_client->close(); | ||
| clients.pop_front(); | ||
| } | ||
| } | ||
|
|
||
| while (!clients.empty()) { | ||
| IntegrationTcpClientPtr& tcp_client = clients.front(); | ||
| ASSERT_TRUE(tcp_client->write(request_with_close, false)); | ||
| tcp_client->waitForData("\r\n\r\n", false); | ||
| tcp_client->waitForHalfClose(); | ||
| tcp_client->close(); | ||
| clients.pop_front(); | ||
| } | ||
| } | ||
|
|
||
| TEST_P(TcpProxyIntegrationTest, NoUpstream) { | ||
| // Set the first upstream to have an invalid port, so connection will fail, | ||
| // but it won't fail synchronously (as it would if there were simply no | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
it seems unexpected that we are using HTTP manually in a TCP test. Do you want to comment on what the testing strategy is here?