-
Notifications
You must be signed in to change notification settings - Fork 19
/
tcp_proxy_integration_test.cc
500 lines (417 loc) · 20.8 KB
/
tcp_proxy_integration_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#include "test/integration/tcp_proxy_integration_test.h"
#include "envoy/config/accesslog/v2/file.pb.h"
#include "envoy/config/filter/network/tcp_proxy/v2/tcp_proxy.pb.validate.h"
#include "common/filesystem/filesystem_impl.h"
#include "common/network/utility.h"
#include "common/ssl/context_manager_impl.h"
#include "test/integration/ssl_utility.h"
#include "test/integration/utility.h"
#include "gtest/gtest.h"
using testing::_;
using testing::Invoke;
using testing::MatchesRegex;
using testing::NiceMock;
namespace Envoy {
namespace {
INSTANTIATE_TEST_CASE_P(IpVersions, TcpProxyIntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
void TcpProxyIntegrationTest::initialize() {
config_helper_.renameListener("tcp_proxy");
BaseIntegrationTest::initialize();
}
#if 0
// Test upstream writing before downstream downstream does.
TEST_P(TcpProxyIntegrationTest, TcpProxyUpstreamWritesFirst) {
initialize();
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
ASSERT_TRUE(fake_upstream_connection->write("hello"));
tcp_client->waitForData("hello");
// Make sure inexact matches work also on data already received.
tcp_client->waitForData("ello", false);
tcp_client->write("hello");
ASSERT_TRUE(fake_upstream_connection->waitForData(5));
ASSERT_TRUE(fake_upstream_connection->write("", true));
tcp_client->waitForHalfClose();
tcp_client->write("", true);
ASSERT_TRUE(fake_upstream_connection->waitForHalfClose());
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect());
}
// Test proxying data in both directions, and that all data is flushed properly
// when there is an upstream disconnect.
TEST_P(TcpProxyIntegrationTest, TcpProxyUpstreamDisconnect) {
initialize();
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
tcp_client->write("hello");
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
ASSERT_TRUE(fake_upstream_connection->waitForData(5));
ASSERT_TRUE(fake_upstream_connection->write("world"));
ASSERT_TRUE(fake_upstream_connection->close());
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect());
tcp_client->waitForHalfClose();
tcp_client->close();
EXPECT_EQ("world", tcp_client->data());
}
// Test proxying data in both directions, and that all data is flushed properly
// when the client disconnects.
TEST_P(TcpProxyIntegrationTest, TcpProxyDownstreamDisconnect) {
initialize();
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
tcp_client->write("hello");
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
ASSERT_TRUE(fake_upstream_connection->waitForData(5));
ASSERT_TRUE(fake_upstream_connection->write("world"));
tcp_client->waitForData("world");
tcp_client->write("hello", true);
ASSERT_TRUE(fake_upstream_connection->waitForData(10));
ASSERT_TRUE(fake_upstream_connection->waitForHalfClose());
ASSERT_TRUE(fake_upstream_connection->write("", true));
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect(true));
tcp_client->waitForDisconnect();
}
TEST_P(TcpProxyIntegrationTest, TcpProxyLargeWrite) {
config_helper_.setBufferLimits(1024, 1024);
initialize();
std::string data(1024 * 16, 'a');
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
tcp_client->write(data);
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
ASSERT_TRUE(fake_upstream_connection->waitForData(data.size()));
ASSERT_TRUE(fake_upstream_connection->write(data));
tcp_client->waitForData(data);
tcp_client->close();
ASSERT_TRUE(fake_upstream_connection->waitForHalfClose());
ASSERT_TRUE(fake_upstream_connection->close());
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect());
uint32_t upstream_pauses =
test_server_->counter("cluster.cluster_0.upstream_flow_control_paused_reading_total")
->value();
uint32_t upstream_resumes =
test_server_->counter("cluster.cluster_0.upstream_flow_control_resumed_reading_total")
->value();
EXPECT_EQ(upstream_pauses, upstream_resumes);
uint32_t downstream_pauses =
test_server_->counter("tcp.tcp_stats.downstream_flow_control_paused_reading_total")->value();
uint32_t downstream_resumes =
test_server_->counter("tcp.tcp_stats.downstream_flow_control_resumed_reading_total")->value();
EXPECT_EQ(downstream_pauses, downstream_resumes);
}
// Test that a downstream flush works correctly (all data is flushed)
TEST_P(TcpProxyIntegrationTest, TcpProxyDownstreamFlush) {
// Use a very large size to make sure it is larger than the kernel socket read buffer.
const uint32_t size = 50 * 1024 * 1024;
config_helper_.setBufferLimits(size / 4, size / 4);
initialize();
std::string data(size, 'a');
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
tcp_client->readDisable(true);
tcp_client->write("", true);
// This ensures that readDisable(true) has been run on it's thread
// before tcp_client starts writing.
ASSERT_TRUE(fake_upstream_connection->waitForHalfClose());
ASSERT_TRUE(fake_upstream_connection->write(data, true));
test_server_->waitForCounterGe("cluster.cluster_0.upstream_flow_control_paused_reading_total", 1);
EXPECT_EQ(test_server_->counter("cluster.cluster_0.upstream_flow_control_resumed_reading_total")
->value(),
0);
tcp_client->readDisable(false);
tcp_client->waitForData(data);
tcp_client->waitForHalfClose();
ASSERT_TRUE(fake_upstream_connection->waitForHalfClose());
uint32_t upstream_pauses =
test_server_->counter("cluster.cluster_0.upstream_flow_control_paused_reading_total")
->value();
uint32_t upstream_resumes =
test_server_->counter("cluster.cluster_0.upstream_flow_control_resumed_reading_total")
->value();
EXPECT_GE(upstream_pauses, upstream_resumes);
EXPECT_GT(upstream_resumes, 0);
}
// Test that an upstream flush works correctly (all data is flushed)
TEST_P(TcpProxyIntegrationTest, TcpProxyUpstreamFlush) {
// Use a very large size to make sure it is larger than the kernel socket read buffer.
const uint32_t size = 50 * 1024 * 1024;
config_helper_.setBufferLimits(size, size);
initialize();
std::string data(size, 'a');
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
ASSERT_TRUE(fake_upstream_connection->readDisable(true));
ASSERT_TRUE(fake_upstream_connection->write("", true));
// This ensures that fake_upstream_connection->readDisable has been run on it's thread
// before tcp_client starts writing.
tcp_client->waitForHalfClose();
tcp_client->write(data, true);
test_server_->waitForGaugeEq("tcp.tcp_stats.upstream_flush_active", 1);
ASSERT_TRUE(fake_upstream_connection->readDisable(false));
ASSERT_TRUE(fake_upstream_connection->waitForData(data.size()));
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect());
tcp_client->waitForHalfClose();
EXPECT_EQ(test_server_->counter("tcp.tcp_stats.upstream_flush_total")->value(), 1);
EXPECT_EQ(test_server_->gauge("tcp.tcp_stats.upstream_flush_active")->value(), 0);
}
// Test that Envoy doesn't crash or assert when shutting down with an upstream flush active
TEST_P(TcpProxyIntegrationTest, TcpProxyUpstreamFlushEnvoyExit) {
// Use a very large size to make sure it is larger than the kernel socket read buffer.
const uint32_t size = 50 * 1024 * 1024;
config_helper_.setBufferLimits(size, size);
initialize();
std::string data(size, 'a');
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
ASSERT_TRUE(fake_upstream_connection->readDisable(true));
ASSERT_TRUE(fake_upstream_connection->write("", true));
// This ensures that fake_upstream_connection->readDisable has been run on it's thread
// before tcp_client starts writing.
tcp_client->waitForHalfClose();
tcp_client->write(data, true);
test_server_->waitForGaugeEq("tcp.tcp_stats.upstream_flush_active", 1);
test_server_.reset();
ASSERT_TRUE(fake_upstream_connection->close());
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect());
// Success criteria is that no ASSERTs fire and there are no leaks.
}
TEST_P(TcpProxyIntegrationTest, AccessLog) {
std::string access_log_path = TestEnvironment::temporaryPath(
fmt::format("access_log{}.txt", GetParam() == Network::Address::IpVersion::v4 ? "v4" : "v6"));
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v2::Bootstrap& bootstrap) -> void {
auto* listener = bootstrap.mutable_static_resources()->mutable_listeners(0);
auto* filter_chain = listener->mutable_filter_chains(0);
auto* config_blob = filter_chain->mutable_filters(0)->mutable_config();
envoy::config::filter::network::tcp_proxy::v2::TcpProxy tcp_proxy_config;
MessageUtil::jsonConvert(*config_blob, tcp_proxy_config);
auto* access_log = tcp_proxy_config.add_access_log();
access_log->set_name("envoy.file_access_log");
envoy::config::accesslog::v2::FileAccessLog access_log_config;
access_log_config.set_path(access_log_path);
access_log_config.set_format(
"upstreamlocal=%UPSTREAM_LOCAL_ADDRESS% "
"upstreamhost=%UPSTREAM_HOST% downstream=%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT%\n");
MessageUtil::jsonConvert(access_log_config, *access_log->mutable_config());
MessageUtil::jsonConvert(tcp_proxy_config, *config_blob);
});
initialize();
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
ASSERT_TRUE(fake_upstream_connection->write("hello"));
tcp_client->waitForData("hello");
ASSERT_TRUE(fake_upstream_connection->write("", true));
tcp_client->waitForHalfClose();
tcp_client->write("", true);
ASSERT_TRUE(fake_upstream_connection->waitForHalfClose());
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect());
std::string log_result;
// Access logs only get flushed to disk periodically, so poll until the log is non-empty
do {
log_result = Filesystem::fileReadToEnd(access_log_path);
} while (log_result.empty());
// Regex matching localhost:port
const std::string ip_port_regex = (GetParam() == Network::Address::IpVersion::v4)
? R"EOF(127\.0\.0\.1:[0-9]+)EOF"
: R"EOF(\[::1\]:[0-9]+)EOF";
const std::string ip_regex =
(GetParam() == Network::Address::IpVersion::v4) ? R"EOF(127\.0\.0\.1)EOF" : R"EOF(::1)EOF";
// Test that all three addresses were populated correctly. Only check the first line of
// log output for simplicity.
EXPECT_THAT(log_result,
MatchesRegex(fmt::format("upstreamlocal={0} upstreamhost={0} downstream={1}\n.*",
ip_port_regex, ip_regex)));
}
// Test that the server shuts down without crashing when connections are open.
TEST_P(TcpProxyIntegrationTest, ShutdownWithOpenConnections) {
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v2::Bootstrap& bootstrap) -> void {
auto* static_resources = bootstrap.mutable_static_resources();
for (int i = 0; i < static_resources->clusters_size(); ++i) {
auto* cluster = static_resources->mutable_clusters(i);
cluster->set_close_connections_on_host_health_failure(true);
}
});
initialize();
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
tcp_client->write("hello");
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
ASSERT_TRUE(fake_upstream_connection->waitForData(5));
ASSERT_TRUE(fake_upstream_connection->write("world"));
tcp_client->waitForData("world");
tcp_client->write("hello", false);
ASSERT_TRUE(fake_upstream_connection->waitForData(10));
test_server_.reset();
ASSERT_TRUE(fake_upstream_connection->waitForHalfClose());
ASSERT_TRUE(fake_upstream_connection->close());
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect(true));
tcp_client->waitForHalfClose();
tcp_client->close();
// Success criteria is that no ASSERTs fire and there are no leaks.
}
#endif
TEST_P(TcpProxyIntegrationTest, TestIdletimeoutWithNoData) {
autonomous_upstream_ = true;
enable_half_close_ = false;
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v2::Bootstrap& bootstrap) -> void {
auto* listener = bootstrap.mutable_static_resources()->mutable_listeners(0);
auto* filter_chain = listener->mutable_filter_chains(0);
auto* config_blob = filter_chain->mutable_filters(0)->mutable_config();
envoy::config::filter::network::tcp_proxy::v2::TcpProxy tcp_proxy_config;
MessageUtil::jsonConvert(*config_blob, tcp_proxy_config);
tcp_proxy_config.mutable_idle_timeout()->set_nanos(
std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::milliseconds(100))
.count());
MessageUtil::jsonConvert(tcp_proxy_config, *config_blob);
});
initialize();
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
tcp_client->waitForDisconnect(true);
}
TEST_P(TcpProxyIntegrationTest, TestIdletimeoutWithLargeOutstandingData) {
config_helper_.setBufferLimits(1024, 1024);
enable_half_close_ = false;
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v2::Bootstrap& bootstrap) -> void {
auto* listener = bootstrap.mutable_static_resources()->mutable_listeners(0);
auto* filter_chain = listener->mutable_filter_chains(0);
auto* config_blob = filter_chain->mutable_filters(0)->mutable_config();
envoy::config::filter::network::tcp_proxy::v2::TcpProxy tcp_proxy_config;
MessageUtil::jsonConvert(*config_blob, tcp_proxy_config);
tcp_proxy_config.mutable_idle_timeout()->set_nanos(
std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::milliseconds(500))
.count());
MessageUtil::jsonConvert(tcp_proxy_config, *config_blob);
});
initialize();
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
std::string data(1024 * 16, 'a');
tcp_client->write(data);
ASSERT_TRUE(fake_upstream_connection->write(data));
tcp_client->waitForDisconnect(true);
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect(true));
}
INSTANTIATE_TEST_CASE_P(IpVersions, TcpProxySslIntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
void TcpProxySslIntegrationTest::initialize() {
config_helper_.addSslConfig();
TcpProxyIntegrationTest::initialize();
context_manager_.reset(new Ssl::ContextManagerImpl(runtime_));
payload_reader_.reset(new WaitForPayloadReader(*dispatcher_));
}
void TcpProxySslIntegrationTest::setupConnections() {
initialize();
// Set up the mock buffer factory so the newly created SSL client will have a mock write
// buffer. This allows us to track the bytes actually written to the socket.
EXPECT_CALL(*mock_buffer_factory_, create_(_, _))
.Times(1)
.WillOnce(Invoke([&](std::function<void()> below_low,
std::function<void()> above_high) -> Buffer::Instance* {
client_write_buffer_ = new NiceMock<MockWatermarkBuffer>(below_low, above_high);
ON_CALL(*client_write_buffer_, move(_))
.WillByDefault(Invoke(client_write_buffer_, &MockWatermarkBuffer::baseMove));
ON_CALL(*client_write_buffer_, drain(_))
.WillByDefault(Invoke(client_write_buffer_, &MockWatermarkBuffer::trackDrains));
return client_write_buffer_;
}));
// Set up the SSl client.
Network::Address::InstanceConstSharedPtr address =
Ssl::getSslAddress(version_, lookupPort("tcp_proxy"));
context_ = Ssl::createClientSslTransportSocketFactory(false, false, *context_manager_);
ssl_client_ =
dispatcher_->createClientConnection(address, Network::Address::InstanceConstSharedPtr(),
context_->createTransportSocket(), nullptr);
// Perform the SSL handshake. Loopback is whitelisted in tcp_proxy.json for the ssl_auth
// filter so there will be no pause waiting on auth data.
ssl_client_->addConnectionCallbacks(connect_callbacks_);
ssl_client_->enableHalfClose(true);
ssl_client_->addReadFilter(payload_reader_);
ssl_client_->connect();
while (!connect_callbacks_.connected()) {
dispatcher_->run(Event::Dispatcher::RunType::NonBlock);
}
AssertionResult result = fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection_);
RELEASE_ASSERT(result, result.message());
}
// Test proxying data in both directions with envoy doing TCP and TLS
// termination.
void TcpProxySslIntegrationTest::sendAndReceiveTlsData(const std::string& data_to_send_upstream,
const std::string& data_to_send_downstream) {
// Ship some data upstream.
Buffer::OwnedImpl buffer(data_to_send_upstream);
ssl_client_->write(buffer, false);
while (client_write_buffer_->bytes_drained() != data_to_send_upstream.size()) {
dispatcher_->run(Event::Dispatcher::RunType::NonBlock);
}
// Make sure the data makes it upstream.
ASSERT_TRUE(fake_upstream_connection_->waitForData(data_to_send_upstream.size()));
// Now send data downstream and make sure it arrives.
ASSERT_TRUE(fake_upstream_connection_->write(data_to_send_downstream));
payload_reader_->set_data_to_wait_for(data_to_send_downstream);
ssl_client_->dispatcher().run(Event::Dispatcher::RunType::Block);
// Clean up.
Buffer::OwnedImpl empty_buffer;
ssl_client_->write(empty_buffer, true);
dispatcher_->run(Event::Dispatcher::RunType::NonBlock);
ASSERT_TRUE(fake_upstream_connection_->waitForHalfClose());
ASSERT_TRUE(fake_upstream_connection_->write("", true));
ASSERT_TRUE(fake_upstream_connection_->waitForDisconnect());
ssl_client_->dispatcher().run(Event::Dispatcher::RunType::Block);
EXPECT_TRUE(payload_reader_->readLastByte());
EXPECT_TRUE(connect_callbacks_.closed());
}
TEST_P(TcpProxySslIntegrationTest, SendTlsToTlsListener) {
setupConnections();
sendAndReceiveTlsData("hello", "world");
}
TEST_P(TcpProxySslIntegrationTest, LargeBidirectionalTlsWrites) {
setupConnections();
std::string large_data(1024 * 8, 'a');
sendAndReceiveTlsData(large_data, large_data);
}
// Test that a half-close on the downstream side is proxied correctly.
TEST_P(TcpProxySslIntegrationTest, DownstreamHalfClose) {
setupConnections();
Buffer::OwnedImpl empty_buffer;
ssl_client_->write(empty_buffer, true);
dispatcher_->run(Event::Dispatcher::RunType::NonBlock);
ASSERT_TRUE(fake_upstream_connection_->waitForHalfClose());
const std::string data("data");
ASSERT_TRUE(fake_upstream_connection_->write(data, false));
payload_reader_->set_data_to_wait_for(data);
ssl_client_->dispatcher().run(Event::Dispatcher::RunType::Block);
EXPECT_FALSE(payload_reader_->readLastByte());
ASSERT_TRUE(fake_upstream_connection_->write("", true));
ssl_client_->dispatcher().run(Event::Dispatcher::RunType::Block);
EXPECT_TRUE(payload_reader_->readLastByte());
}
// Test that a half-close on the upstream side is proxied correctly.
TEST_P(TcpProxySslIntegrationTest, UpstreamHalfClose) {
setupConnections();
ASSERT_TRUE(fake_upstream_connection_->write("", true));
ssl_client_->dispatcher().run(Event::Dispatcher::RunType::Block);
EXPECT_TRUE(payload_reader_->readLastByte());
EXPECT_FALSE(connect_callbacks_.closed());
const std::string& val("data");
Buffer::OwnedImpl buffer(val);
ssl_client_->write(buffer, false);
while (client_write_buffer_->bytes_drained() != val.size()) {
dispatcher_->run(Event::Dispatcher::RunType::NonBlock);
}
ASSERT_TRUE(fake_upstream_connection_->waitForData(val.size()));
Buffer::OwnedImpl empty_buffer;
ssl_client_->write(empty_buffer, true);
while (!connect_callbacks_.closed()) {
dispatcher_->run(Event::Dispatcher::RunType::NonBlock);
}
ASSERT_TRUE(fake_upstream_connection_->waitForHalfClose());
}
} // namespace
} // namespace Envoy