Skip to content

Commit 366e124

Browse files
MorrisJobkeChristophWurst
authored andcommitted
Rollback failed transactions in TestCase.php to not break followup tests
Signed-off-by: Morris Jobke <[email protected]>
1 parent c2bc81e commit 366e124

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tests/lib/DB/MigratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testDuplicateKeyUpgrade() {
142142

143143
try {
144144
$migrator->migrate($endSchema);
145-
} catch(Exception\UniqueConstraintViolationException $e) {
145+
} catch (Exception\UniqueConstraintViolationException $e) {
146146
$this->connection->rollBack();
147147
throw $e;
148148
}

tests/lib/TestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ public static function tearDownAfterClass(): void {
261261
}
262262
$dataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data-autotest');
263263
if (self::$wasDatabaseAllowed && \OC::$server->getDatabaseConnection()) {
264-
$queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
264+
$db = \OC::$server->getDatabaseConnection();
265+
if ($db->inTransaction()) {
266+
$db->rollBack();
267+
throw new \Exception('There was a transaction still in progress and needed to be rolled back. Please fix this in your test.');
268+
}
269+
$queryBuilder = $db->getQueryBuilder();
265270

266271
self::tearDownAfterClassCleanShares($queryBuilder);
267272
self::tearDownAfterClassCleanStorages($queryBuilder);

0 commit comments

Comments
 (0)