-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Changes from 2 commits
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 |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
|
|
||
| using testing::_; | ||
| using testing::AtLeast; | ||
| using testing::HasSubstr; | ||
| using testing::Invoke; | ||
| using testing::MatchesRegex; | ||
| using testing::NiceMock; | ||
|
|
@@ -150,6 +151,73 @@ TEST_P(TcpProxyIntegrationTest, TcpProxyDownstreamDisconnect) { | |
| tcp_client->waitForDisconnect(); | ||
| } | ||
|
|
||
| TEST_P(TcpProxyIntegrationTest, TcpProxyManyConnections) { | ||
| autonomous_upstream_ = true; | ||
| initialize(); | ||
| 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]; | ||
| 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", | ||
|
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 seems unexpected that we are using HTTP manually in a TCP test. Do you want to comment on what the testing strategy is here? |
||
| 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; | ||
|
|
||
| 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; | ||
|
|
||
| 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 | ||
|
|
||
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.
nit: const