fix(test): Fix connection context access (#2228)

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
This commit is contained in:
Vladislav 2023-11-28 17:05:13 +03:00 committed by GitHub
parent 0c5bb7b894
commit 43431d1986
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View file

@ -301,6 +301,9 @@ class Connection : public util::Connection {
std::pair<std::string, std::string> GetClientInfoBeforeAfterTid() const;
protected:
std::unique_ptr<ConnectionContext> cc_; // Null for http connections
private:
std::deque<MessageHandle> dispatch_q_; // dispatch queue
dfly::EventCount evc_; // dispatch queue waker
@ -326,10 +329,6 @@ class Connection : public util::Connection {
Phase phase_ = SETUP;
std::string name_;
// A pointer to the ConnectionContext object if it exists. Some connections (like http
// requests) don't have it.
std::unique_ptr<ConnectionContext> cc_;
unsigned parser_error_ = 0;
bool break_cb_engaged_ = false;

View file

@ -65,6 +65,7 @@ static vector<string> SplitLines(const std::string& src) {
TestConnection::TestConnection(Protocol protocol, io::StringSink* sink)
: facade::Connection(protocol, nullptr, nullptr, nullptr), sink_(sink) {
cc_.reset(new dfly::ConnectionContext(sink_, this));
}
void TestConnection::SendPubMessageAsync(PubMessage pmsg) {
@ -105,7 +106,7 @@ class BaseFamilyTest::TestConnWrapper {
const facade::Connection::PubMessage& GetPubMessage(size_t index) const;
ConnectionContext* cmd_cntx() {
return &cmd_cntx_;
return static_cast<ConnectionContext*>(dummy_conn_->cntx());
}
StringVec SplitLines() const {
@ -125,14 +126,13 @@ class BaseFamilyTest::TestConnWrapper {
std::unique_ptr<TestConnection> dummy_conn_;
ConnectionContext cmd_cntx_;
std::vector<std::unique_ptr<std::string>> tmp_str_vec_;
std::unique_ptr<RedisParser> parser_;
};
BaseFamilyTest::TestConnWrapper::TestConnWrapper(Protocol proto)
: dummy_conn_(new TestConnection(proto, &sink_)), cmd_cntx_(&sink_, dummy_conn_.get()) {
: dummy_conn_(new TestConnection(proto, &sink_)) {
}
BaseFamilyTest::TestConnWrapper::~TestConnWrapper() {