From 4ed0a95add987576ae6501bffaf1d9c7a369978b Mon Sep 17 00:00:00 2001 From: Christoph Kempen Date: Sun, 17 May 2026 10:53:32 +0200 Subject: [PATCH] Await onClose callback in testTransactionsCallbacksOnDestruct delay(0) only yields a single event loop tick, which is not enough for the async ROLLBACK round-trip triggered by the transaction destructor to complete. The test happens to pass against MySQL on the GitHub Actions runner because that path is fast enough to win the race within one tick, but it fails consistently against MariaDB and against MySQL when the database is reached through a slower transport (e.g. Docker on macOS). Awaiting a DeferredFuture completed by an onClose callback removes the timing dependency and makes the test deterministic on both servers. --- test/MysqlConnectionTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/MysqlConnectionTest.php b/test/MysqlConnectionTest.php index 369e358..cfc48e8 100644 --- a/test/MysqlConnectionTest.php +++ b/test/MysqlConnectionTest.php @@ -4,10 +4,10 @@ use Amp\CancelledException; use Amp\DeferredCancellation; +use Amp\DeferredFuture; use Amp\Mysql\MysqlConnection; use Amp\Mysql\MysqlLink; use Amp\Mysql\SocketMysqlConnector; -use function Amp\delay; use function Amp\Mysql\connect; class MysqlConnectionTest extends MysqlLinkTest @@ -121,12 +121,15 @@ public function testTransactionsCallbacksOnDestruct(): void { $db = $this->getLink(); + $closed = new DeferredFuture(); + $transaction = $db->beginTransaction(); $transaction->onCommit($this->createCallback(0)); $transaction->onRollback($this->createCallback(1)); $transaction->onClose($this->createCallback(1)); + $transaction->onClose($closed->complete(...)); unset($transaction); - delay(0); // Destructor is async, so give control to the loop to invoke callbacks. + $closed->getFuture()->await(); } }