Skip to content
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
24 changes: 24 additions & 0 deletions test/integration/fake_upstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,30 @@ testing::AssertionResult FakeUpstream::rawWriteConnection(uint32_t index, const
timeout);
}

FakeRawConnection::~FakeRawConnection() {
// If the filter was already deleted, it means the shared_connection_ was too, so don't try to
// access it.
if (auto filter = read_filter_.lock(); filter != nullptr) {
EXPECT_TRUE(shared_connection_.executeOnDispatcher(
[filter = std::move(filter)](Network::Connection& connection) {
connection.removeReadFilter(filter);
}));
}
}

testing::AssertionResult FakeRawConnection::initialize() {
auto filter = Network::ReadFilterSharedPtr{new ReadFilter(*this)};
read_filter_ = filter;
testing::AssertionResult result = shared_connection_.executeOnDispatcher(
[filter = std::move(filter)](Network::Connection& connection) {
connection.addReadFilter(filter);
});
if (!result) {
return result;
}
return FakeConnectionBase::initialize();
}

AssertionResult FakeRawConnection::waitForData(uint64_t num_bytes, std::string* data,
milliseconds timeout) {
absl::MutexLock lock(&lock_);
Expand Down
13 changes: 3 additions & 10 deletions test/integration/fake_upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ class FakeRawConnection : public FakeConnectionBase {
FakeRawConnection(SharedConnectionWrapper& shared_connection, Event::TestTimeSystem& time_system)
: FakeConnectionBase(shared_connection, time_system) {}
using ValidatorFunction = const std::function<bool(const std::string&)>;
~FakeRawConnection() override;

// Writes to data. If data is nullptr, discards the received data.
ABSL_MUST_USE_RESULT
Expand All @@ -493,16 +494,7 @@ class FakeRawConnection : public FakeConnectionBase {
std::chrono::milliseconds timeout = TestUtility::DefaultTimeout);

ABSL_MUST_USE_RESULT
testing::AssertionResult initialize() override {
testing::AssertionResult result =
shared_connection_.executeOnDispatcher([this](Network::Connection& connection) {
connection.addReadFilter(Network::ReadFilterSharedPtr{new ReadFilter(*this)});
});
if (!result) {
return result;
}
return FakeConnectionBase::initialize();
}
testing::AssertionResult initialize() override;

// Creates a ValidatorFunction which returns true when data_to_wait_for is
// contained in the incoming data string. Unlike many of Envoy waitFor functions,
Expand Down Expand Up @@ -530,6 +522,7 @@ class FakeRawConnection : public FakeConnectionBase {
};

std::string data_ ABSL_GUARDED_BY(lock_);
std::weak_ptr<Network::ReadFilter> read_filter_;
};

using FakeRawConnectionPtr = std::unique_ptr<FakeRawConnection>;
Expand Down