Skip to content

Commit

Permalink
Merge branch 'bugfix/pq_mock_event_fd'
Browse files Browse the repository at this point in the history
  • Loading branch information
furmur committed Aug 16, 2023
2 parents 6256b69 + 3cf4d6a commit f15ab5b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
15 changes: 11 additions & 4 deletions apps/postgresql/conn/MockConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>

#include <sys/eventfd.h>

MockConnection::MockConnection(IConnectionHandler* handler)
: Connection("mock", "mock", handler)
Expand All @@ -22,10 +22,16 @@ void MockConnection::check_conn()

if(status == CONNECTION_BAD) {
status = CONNECTION_MADE;
handler->onSock(this, IConnectionHandler::PG_SOCK_READ);
handler->onSock(this, IConnectionHandler::PG_SOCK_WRITE);
} else if(status == CONNECTION_MADE) {
status = CONNECTION_OK;
handler->onConnect(this);
handler->onSock(this, IConnectionHandler::PG_SOCK_READ);
} else if(status == CONNECTION_OK) {
int64_t u;
do {
u = ::read(conn_fd, &u, sizeof(int64_t));
} while(u > 0);
}
}

Expand All @@ -46,7 +52,7 @@ bool MockConnection::reset_conn()
conn_fd = -1;
}

conn_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
conn_fd = eventfd(0, EFD_NONBLOCK);
handler->onSock(this, IConnectionHandler::PG_SOCK_NEW);

return true;
Expand All @@ -70,7 +76,8 @@ bool MockConnection::start_pipe()

bool MockConnection::sync_pipe()
{
return true;
uint64_t u = 1;
return write(conn_fd, &u, sizeof(u)) == sizeof(u);
}

bool MockConnection::exit_pipe()
Expand Down
6 changes: 5 additions & 1 deletion apps/postgresql/query/MockQueryImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ class MockQueryImpl : public IQueryImpl
: IQueryImpl(cmd, single){}
virtual ~MockQueryImpl(){}

int exec() override { is_send = true; return 1; }
int exec() override {
uint64_t u = 1;
is_send = write(conn->getSocket(), &u, sizeof(u)) == sizeof(u);
return 1;
}
};
11 changes: 9 additions & 2 deletions apps/postgresql/trans/MockTransactionImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "MockTransactionImpl.h"

#include "Transaction.h"
#include "../conn/Connection.h"
#include "../query/QueryChain.h"

MockTransactionImpl::MockTransactionImpl(Transaction* h, TransactionType t, TestServer* server_)
Expand Down Expand Up @@ -32,12 +33,17 @@ bool MockTransactionImpl::check_trans()
ERROR("unknown query");
return true;
}

if((status == PQTRANS_IDLE &&
query->is_finished()) ||
status == PQTRANS_ACTIVE) {
status = PQTRANS_ACTIVE;
status = PQTRANS_ACTIVE;
return !server->checkTail(query_);
} if(status == PQTRANS_INERROR && !synced) {
synced = true;
query->set_finished();
} else if(status == PQTRANS_INERROR && synced) {
status = PQTRANS_IDLE;
}

return true;
Expand Down Expand Up @@ -84,6 +90,7 @@ int MockTransactionImpl::fetch_result()
if(!errorcode.empty()) {
parent->handler->onErrorCode(parent, errorcode);
}
status = PQTRANS_INERROR;
} else {
AmArg res;
while(server->getResponse(query_, res)) {
Expand Down

0 comments on commit f15ab5b

Please sign in to comment.