// Actual libsql worker + actual SQLFences.h on a dedicated socket-only server. #include "src/server/libsql/AsyncSQL.h" #include "src/server/db/src/SQLFences.h" #include #include #include #include #include int main(int argc,char** argv) { assert(argc==2);const std::string socket=argv[1];struct stat info={}; assert(socket.find("/tmp/ch5-cube-mysql.")==0&&stat(socket.c_str(),&info)==0&&S_ISSOCK(info.st_mode)); // Legacy CAsyncSQL has no socket argument. Set libmysql's explicit default // BEFORE construction/worker launch, then verify server identity read-only. mysql_unix_port=argv[1];CAsyncSQL2 sql; assert(sql.Setup("localhost","root","","cube_batch_test","utf8",false,0)); const auto deadline=std::chrono::steady_clock::now()+std::chrono::seconds(20); while(!sql.IsConnected()&&std::chrono::steady_clock::now()(uintptr_t(ticket))); auto wait=[&](PortSQLFence::Kind kind)->std::unique_ptr{ while(std::chrono::steady_clock::now()(message);std::this_thread::sleep_for(std::chrono::milliseconds(5));} assert(false&&"worker FIFO timeout");return nullptr; }; {auto message=wait(PortSQLFence::Cube);assert(!message->uiSQLErrno&&message->Get()->uiNumRows==1);auto row=mysql_fetch_row(message->Get()->pSQLResult);assert(row&&row[0]&&socket==row[0]);} const auto failures=sql.FailureEpoch(); sql.AsyncQuery("SET @cube_fifo_probe=41"); ticket=PortSQLFence::PlayerRouter().Reserve(PortSQLFence::Cube,77);assert(ticket); sql.ReturnQuery("SELECT @cube_fifo_probe",reinterpret_cast(uintptr_t(ticket))); sql.AsyncQuery("SET @cube_fifo_probe=42"); ticket=PortSQLFence::PlayerRouter().Reserve(PortSQLFence::Economy,77);assert(ticket); sql.ReturnQuery("SELECT @cube_fifo_probe",reinterpret_cast(uintptr_t(ticket))); // Economy polls first and pumps both worker results; Cube must retain its own. {auto message=wait(PortSQLFence::Economy);assert(!message->uiSQLErrno&&reinterpret_cast(message->pvUserData)==77);auto row=mysql_fetch_row(message->Get()->pSQLResult);assert(row&&row[0]&&std::string(row[0])=="42");} {auto message=wait(PortSQLFence::Cube);assert(!message->uiSQLErrno&&reinterpret_cast(message->pvUserData)==77);auto row=mysql_fetch_row(message->Get()->pSQLResult);assert(row&&row[0]&&std::string(row[0])=="41");} assert(sql.FailureEpoch()==failures); sql.AsyncQuery("SELECT * FROM __deliberately_missing_cube_fifo_probe"); assert(PortSQLFence::Queue(&sql,PortSQLFence::Cube,88)); assert(PortSQLFence::Queue(&sql,PortSQLFence::Economy,88)); {auto message=wait(PortSQLFence::Cube);assert(!message->uiSQLErrno);} {auto message=wait(PortSQLFence::Economy);assert(!message->uiSQLErrno);} assert(sql.FailureEpoch()>failures); // successful barriers cannot hide failed writes sql.Quit();PortSQLFence::PlayerRouter().Clear(); puts("PASS actual libsql threaded FIFO: exact isolated socket, interleaved Cube/Economy results, retained session order and failure epoch"); }