Skip to content

Commit 32fda16

Browse files
committed
fix(test): stabilise flaky DB and quota tests
- Quota::fopen: when free_space() returns SPACE_NOT_COMPUTED the previous code skipped wrapping the stream entirely, letting unlimited writes through. Now wraps with the full quota as a conservative ceiling, which makes testStreamCopyNotEnoughSpace deterministic regardless of whether the cache has a valid root-size entry. - CleanupShareTargetTest::setUp: call getUserFolder()->getDirectoryListing() for every test user so their home folders are in the filecache before any share operations. tearDown wipes filecache; without this getShareById (which JOINs on filecache) throws ShareNotFound intermittently on the second createUserShare call. - DBConfigServiceTest::setUp: remove any mounts left by a previously failed test run so testSetMountPoint and testGetAllMounts do not see unexpected extra rows. - StoragesServiceTestCase / CleaningDBConfig: add cleanAll() that removes every mount from the DB (not just those tracked by the current instance) and call it at the top of setUp so testGetStoragesBackendNotVisible and testGetStoragesAuthMechanismNotVisible start with an empty external mount table. Signed-off-by: Anna Larch <anna@nextcloud.com> AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fdbd1e0 commit 32fda16

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

apps/files_external/tests/Service/DBConfigServiceTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ protected function setUp(): void {
2626
parent::setUp();
2727
$this->connection = Server::get(IDBConnection::class);
2828
$this->dbConfig = new DBConfigService($this->connection, Server::get(ICrypto::class));
29+
// Remove any mounts left by a previously failed test run
30+
foreach ($this->dbConfig->getAllMounts() as $mount) {
31+
$this->dbConfig->removeMount($mount['mount_id']);
32+
}
2933
}
3034

3135
protected function tearDown(): void {

apps/files_external/tests/Service/StoragesServiceTestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public function clean(): void {
5050
$this->removeMount($id);
5151
}
5252
}
53+
54+
public function cleanAll(): void {
55+
foreach ($this->getAllMounts() as $mount) {
56+
$this->removeMount($mount['mount_id']);
57+
}
58+
$this->mountIds = [];
59+
}
5360
}
5461

5562
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
@@ -65,6 +72,7 @@ abstract class StoragesServiceTestCase extends \Test\TestCase {
6572
protected function setUp(): void {
6673
parent::setUp();
6774
$this->dbConfig = new CleaningDBConfig(Server::get(IDBConnection::class), Server::get(ICrypto::class));
75+
$this->dbConfig->cleanAll(); // Remove any mounts left by previous test runs
6876
self::$hookCalls = [];
6977
$config = Server::get(IConfig::class);
7078
$this->dataDir = $config->getSystemValue(

apps/files_sharing/tests/Repair/CleanupShareTargetTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class CleanupShareTargetTest extends TestCase {
2727
protected function setUp(): void {
2828
parent::setUp();
2929
$this->cleanupShareTarget = Server::get(CleanupShareTarget::class);
30+
// Ensure all test users' home folders are in the filecache before any share
31+
// operations, because tearDown wipes filecache and getShareById JOINs on it.
32+
foreach ([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER3] as $user) {
33+
$this->rootFolder->getUserFolder($user)->getDirectoryListing();
34+
}
3035
}
3136

3237
private function createUserShare(string $by, string $target = self::TEST_FOLDER_NAME): IShare {

lib/private/Files/Storage/Wrapper/Quota.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@ public function fopen(string $path, string $mode) {
132132
}
133133

134134
$source = $this->getWrapperStorage()->fopen($path, $mode);
135-
if ($source && (is_int($free) || is_float($free)) && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
136-
// only apply quota for files, not metadata, trash or others
137-
if ($this->shouldApplyQuota($path)) {
135+
if ($source && $mode !== 'r' && $mode !== 'rb' && $this->shouldApplyQuota($path)) {
136+
if ((is_int($free) || is_float($free)) && $free >= 0) {
138137
return \OC\Files\Stream\Quota::wrap($source, $free);
138+
} elseif ($free === FileInfo::SPACE_NOT_COMPUTED) {
139+
// Used space is unknown; apply full quota as a conservative ceiling
140+
return \OC\Files\Stream\Quota::wrap($source, $this->getQuota());
139141
}
140142
}
141143

0 commit comments

Comments
 (0)