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

test/fuzz: some h1_capture_fuzz_test stability improvements on connec… #3376

Merged
merged 3 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions test/integration/fake_upstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,11 @@ std::string FakeRawConnection::waitForData(uint64_t num_bytes) {
}

void FakeRawConnection::write(const std::string& data, bool end_stream) {
std::unique_lock<std::mutex> lock(lock_);
ASSERT_FALSE(disconnected_);
connection_.dispatcher().post([data, end_stream, this]() -> void {
std::unique_lock<std::mutex> lock(lock_);
ASSERT_FALSE(disconnected_);
Buffer::OwnedImpl to_write(data);
connection_.write(to_write, end_stream);
});
Expand Down
6 changes: 5 additions & 1 deletion test/integration/fake_upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,18 @@ class FakeConnectionBase : public Network::ConnectionCallbacks {
connection_.dispatcher().post([this]() -> void { connection_.addConnectionCallbacks(*this); });
}
void enableHalfClose(bool enabled);
bool connected() const {
std::unique_lock<std::mutex> lock(lock_);
return !disconnected_;
}

protected:
FakeConnectionBase(QueuedConnectionWrapperPtr connection_wrapper)
: connection_(connection_wrapper->connection()),
connection_wrapper_(std::move(connection_wrapper)) {}

Network::Connection& connection_;
std::mutex lock_;
mutable std::mutex lock_;
std::condition_variable connection_event_;
bool disconnected_{};
bool half_closed_{};
Expand Down

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions test/integration/h1_capture_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class H1FuzzIntegrationTest : public HttpIntegrationTest {
}
switch (event.event_selector_case()) {
case test::integration::Event::kDownstreamSendBytes:
tcp_client->write(event.downstream_send_bytes());
tcp_client->write(event.downstream_send_bytes(), false, false);
break;
case test::integration::Event::kDownstreamRecvBytes:
// TODO(htuch): Should we wait for some data?
Expand All @@ -40,11 +40,15 @@ class H1FuzzIntegrationTest : public HttpIntegrationTest {
fake_upstream_connection = fake_upstreams_[0]->waitForRawConnection(max_wait_ms_);
// If we timed out, we fail out.
if (fake_upstream_connection == nullptr) {
EXPECT_NE(nullptr, fake_upstream_connection);
tcp_client->close();
return;
}
}
// If we're no longer connected, we're done.
if (!fake_upstream_connection->connected()) {
tcp_client->close();
return;
}
fake_upstream_connection->write(event.upstream_send_bytes());
break;
case test::integration::Event::kUpstreamRecvBytes:
Expand All @@ -55,7 +59,7 @@ class H1FuzzIntegrationTest : public HttpIntegrationTest {
break;
}
}
if (fake_upstream_connection != nullptr) {
if (fake_upstream_connection != nullptr && fake_upstream_connection->connected()) {
fake_upstream_connection->close();
fake_upstream_connection->waitForDisconnect(true);
}
Expand Down
12 changes: 7 additions & 5 deletions test/integration/integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ IntegrationTcpClient::IntegrationTcpClient(Event::Dispatcher& dispatcher,
EXPECT_CALL(factory, create_(_, _))
.WillOnce(Invoke([&](std::function<void()> below_low,
std::function<void()> above_high) -> Buffer::Instance* {
client_write_buffer_ = new MockWatermarkBuffer(below_low, above_high);
client_write_buffer_ = new NiceMock<MockWatermarkBuffer>(below_low, above_high);
return client_write_buffer_;
}));

Expand Down Expand Up @@ -174,11 +174,13 @@ void IntegrationTcpClient::waitForHalfClose() {

void IntegrationTcpClient::readDisable(bool disabled) { connection_->readDisable(disabled); }

void IntegrationTcpClient::write(const std::string& data, bool end_stream) {
void IntegrationTcpClient::write(const std::string& data, bool end_stream, bool verify) {
Buffer::OwnedImpl buffer(data);
EXPECT_CALL(*client_write_buffer_, move(_));
if (!data.empty()) {
EXPECT_CALL(*client_write_buffer_, write(_)).Times(AtLeast(1));
if (verify) {
EXPECT_CALL(*client_write_buffer_, move(_));
if (!data.empty()) {
EXPECT_CALL(*client_write_buffer_, write(_)).Times(AtLeast(1));
}
}

int bytes_expected = client_write_buffer_->bytes_written() + data.size();
Expand Down
2 changes: 1 addition & 1 deletion test/integration/integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class IntegrationTcpClient {
void waitForDisconnect();
void waitForHalfClose();
void readDisable(bool disabled);
void write(const std::string& data, bool end_stream = false);
void write(const std::string& data, bool end_stream = false, bool verify = true);
const std::string& data() { return payload_reader_->data(); }
bool connected() const { return !disconnected_; }

Expand Down