From a2497e503666b86b31a517be58af1f69a5dee161 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 28 Jan 2016 09:52:27 +0000 Subject: [PATCH] MDL-52913 behat: Abort database transactions on exception. --- lib/tests/behat/behat_hooks.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 78ea80959a9..9a17b236ea9 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -375,13 +375,22 @@ class behat_hooks extends behat_base { * @AfterStep */ public function after_step(StepEvent $event) { - global $CFG; + global $CFG, $DB; // Save the page content if the step failed. if (!empty($CFG->behat_faildump_path) && $event->getResult() === StepEvent::FAILED) { $this->take_contentdump($event); } + + // Abort any open transactions to prevent subsequent tests hanging. + // This does the same as abort_all_db_transactions(), but doesn't call error_log() as we don't + // want to see a message in the behat output. + if ($event->hasException()) { + if ($DB && $DB->is_transaction_started()) { + $DB->force_transaction_rollback(); + } + } } /**