Await onClose callback in testTransactionsCallbacksOnDestruct#146
Conversation
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.
|
We obviously don't want to keep a flaky test, thanks! |
|
Thanks @webpatser! I guess server-independent wasn't really correct — rather that I didn't see a reason the test would fail with MariaDB if it passes with MySQL. Having the test be flaky was certainly not my intention. As a heads up, we typically add a |
|
Good catch @trowski, you're right. The I'll send a quick follow-up wrapping it with a |
Follow-up from #144.
@trowski you mentioned in #144 that
testTransactionsCallbacksOnDestructshould be independent of the server. Digging in: the test is environment-independent in intent, but it relies ondelay(0)being long enough for the destructor's async ROLLBACK round-trip to complete. That's a one-tick race, not a deterministic wait, and it's the reason the MariaDB job was tripping.Reproduction
Against MariaDB 12.2.2 via Docker on macOS:
Against MySQL 8.4.9 via Docker on macOS the same test also fails. With instrumentation,
onRollbackandonClosefire 50-80 event loop ticks afterdelay(0)returns on both servers. The test passes in CI only because localhost MySQL on the GitHub Actions runner wins the race within a single tick.So both your read and mine were right: the test is server-independent in spirit, and flaky on every server in practice. Just less visibly on the CI box.
Fix
Replace
delay(0)with awaiting aDeferredFuturecompleted by anonClosecallback. No timeout, no tick counting, deterministic on either server.Verification
MysqlConnectionTest: 62/62 passing against MariaDB 12.2.2 and MySQL 8.4.9, both via Docker.Not a hard sell. If you'd rather keep the
delay(0)form and document this as a known-flaky case, I won't push back.