@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class AphrontMySQLDatabaseConnectionTestCase
4 extends PhabricatorTestCase {
5
6 protected function getPhabricatorTestCaseConfiguration() {
7 return array(
8 // We disable this here because we're testing live MySQL connections.
9 self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK => false,
10 );
11 }
12
13 public function testConnectionFailures() {
14 $conn = id(new HarbormasterScratchTable())->establishConnection('r');
15
16 queryfx($conn, 'SELECT 1');
17
18 // We expect the connection to recover from a 2006 (lost connection) when
19 // outside of a transaction...
20 $conn->simulateErrorOnNextQuery(2006);
21 queryfx($conn, 'SELECT 1');
22
23 // ...but when transactional, we expect the query to throw when the
24 // connection is lost, because it indicates the transaction was aborted.
25 $conn->openTransaction();
26 $conn->simulateErrorOnNextQuery(2006);
27
28 $caught = null;
29 try {
30 queryfx($conn, 'SELECT 1');
31 } catch (AphrontConnectionLostQueryException $ex) {
32 $caught = $ex;
33 }
34 $this->assertTrue($caught instanceof Exception);
35 }
36
37}