3 final class AphrontIsolatedDatabaseConnectionTestCase
4 extends PhabricatorTestCase
{
6 protected function getPhabricatorTestCaseConfiguration() {
8 // We disable this here because this test is unique (it is testing that
9 // isolation actually occurs) and must establish a live connection to the
10 // database to verify that.
11 self
::PHABRICATOR_TESTCONFIG_ISOLATE_LISK
=> false,
15 public function testIsolation() {
16 // This will fail if the connection isn't isolated.
18 $this->newIsolatedConnection(),
19 'INSERT INVALID SYNTAX');
21 $this->assertTrue(true);
24 public function testInsertGeneratesID() {
25 $conn = $this->newIsolatedConnection();
27 queryfx($conn, 'INSERT');
28 $id1 = $conn->getInsertID();
30 queryfx($conn, 'INSERT');
31 $id2 = $conn->getInsertID();
33 $this->assertTrue((bool)$id1, pht('ID1 exists.'));
34 $this->assertTrue((bool)$id2, pht('ID2 exists.'));
37 pht("IDs '%s' and '%s' are distinct.", $id1, $id2));
40 public function testDeletePermitted() {
41 $conn = $this->newIsolatedConnection();
42 queryfx($conn, 'DELETE');
44 $this->assertTrue(true);
47 public function testTransactionStack() {
48 $conn = $this->newIsolatedConnection();
49 $conn->openTransaction();
50 queryfx($conn, 'INSERT');
51 $conn->saveTransaction();
58 $conn->getQueryTranscript());
60 $conn = $this->newIsolatedConnection();
61 $conn->openTransaction();
62 queryfx($conn, 'INSERT 1');
63 $conn->openTransaction();
64 queryfx($conn, 'INSERT 2');
65 $conn->killTransaction();
66 $conn->openTransaction();
67 queryfx($conn, 'INSERT 3');
68 $conn->openTransaction();
69 queryfx($conn, 'INSERT 4');
70 $conn->saveTransaction();
71 $conn->saveTransaction();
72 $conn->openTransaction();
73 queryfx($conn, 'INSERT 5');
74 $conn->killTransaction();
75 queryfx($conn, 'INSERT 6');
76 $conn->saveTransaction();
82 'SAVEPOINT Aphront_Savepoint_1',
84 'ROLLBACK TO SAVEPOINT Aphront_Savepoint_1',
85 'SAVEPOINT Aphront_Savepoint_1',
87 'SAVEPOINT Aphront_Savepoint_2',
89 'SAVEPOINT Aphront_Savepoint_1',
91 'ROLLBACK TO SAVEPOINT Aphront_Savepoint_1',
95 $conn->getQueryTranscript());
98 public function testTransactionRollback() {
101 $phid = new HarbormasterScratchTable();
102 $phid->openTransaction();
103 for ($ii = 0; $ii < 3; $ii++
) {
104 $key = $this->generateTestData();
106 $obj = new HarbormasterScratchTable();
112 $phid->killTransaction();
114 foreach ($check as $key) {
115 $this->assertNoSuchRow($key);
119 private function newIsolatedConnection() {
121 return new AphrontIsolatedDatabaseConnection($config);
124 private function generateTestData() {
125 return Filesystem
::readRandomCharacters(20);
128 private function assertNoSuchRow($data) {
130 $row = id(new HarbormasterScratchTable())->loadOneWhere(
136 pht('Expect fake row to exist only in isolation.'));
137 } catch (AphrontConnectionQueryException
$ex) {
138 // If we can't connect to the database, conclude that the isolated
139 // connection actually is isolated. Philosophically, this perhaps allows
140 // us to claim this test does not depend on the database?