From b16896f22bc70457bf53d48ac71c30e40c2ad660 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 13 Jul 2017 22:54:00 +1200 Subject: [PATCH] FIX Ignore exceptions thrown when deleting test databases This will prevent long runnings builds (e.g. code coverage) from failing when the test database connection is gone (MySQL server has gone away) by the time the shutdown handler runs. --- src/ORM/Connect/TempDatabase.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ORM/Connect/TempDatabase.php b/src/ORM/Connect/TempDatabase.php index fb51295ed..f35165799 100644 --- a/src/ORM/Connect/TempDatabase.php +++ b/src/ORM/Connect/TempDatabase.php @@ -2,6 +2,7 @@ namespace SilverStripe\ORM\Connect; +use Exception; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injector; @@ -92,7 +93,6 @@ class TempDatabase } } - // echo "Deleted temp database " . $dbConn->currentDatabase() . "\n"; $dbConn->dropSelectedDatabase(); } @@ -147,7 +147,11 @@ class TempDatabase // Ensure test db is killed on exit register_shutdown_function(function () { - $this->kill(); + try { + $this->kill(); + } catch (Exception $ex) { + // An exception thrown while trying to remove a test database shouldn't fail a build, ignore + } }); return $dbname;