Skip to content

fix(test): remove order-dependent assertions in CacheTest::testExtended#60533

Open
miaulalala wants to merge 2 commits into
masterfrom
fix/cache-test-order-dependency
Open

fix(test): remove order-dependent assertions in CacheTest::testExtended#60533
miaulalala wants to merge 2 commits into
masterfrom
fix/cache-test-order-dependency

Conversation

@miaulalala
Copy link
Copy Markdown
Contributor

@miaulalala miaulalala commented May 19, 2026

Summary

Fixes several intermittently failing PHPUnit tests spotted while reviewing #60453.

CacheTest::testExtended

CacheTest::testExtended (and its subclass CachePermissionsMaskTest::testExtended) calls getFolderContents('') and then asserts against $entries[0]--$entries[3] by position. getFolderContentsById has no ORDER BY, so the result order is non-deterministic across DB engines and under parallel test execution:

Failed asserting that two strings are equal.
Expected: 'foo1'
Actual:   'foo4'

Fix: index the returned entries by name before asserting.

QuotaTest::testStreamCopyNotEnoughSpace

When free_space() cannot compute used disk size it returns SPACE_NOT_COMPUTED (-1). The old Quota::fopen code only wrapped the stream when $free >= 0, so a -1 result caused the raw, unwrapped stream to be returned, allowing unlimited writes. stream_copy_to_stream then returned the full byte count instead of false, breaking the assertion.

Fix: when space usage is unknown, wrap with the full quota value as a conservative ceiling.

CleanupShareTargetTest::testRepairMultipleConflicting

tearDown truncates the entire filecache table. DefaultShareProvider::getShareById JOINs share with filecache -- if a test user's home folder entry was wiped and not yet recreated before updateShare is called, the JOIN finds nothing and throws ShareNotFound.

Fix: call getUserFolder()->getDirectoryListing() for all three test users in setUp to ensure their home folders are in the filecache before any share operations.

DBConfigServiceTest::testSetMountPoint / testGetAllMounts

Mounts left over from a previously crashed test run remain in the DB and are returned by getAllMounts(), causing count mismatches and unexpected nulls.

Fix: delete all existing mounts in setUp before each test.

StoragesServiceTestCase::testGetStoragesBackendNotVisible / testGetStoragesAuthMechanismNotVisible

Same root cause as above: leftover mounts from a previous run inflate the results of getAllStorages().

Fix: added cleanAll() to CleaningDBConfig (removes all mounts regardless of whether they were created by the current instance) and call it at the top of setUp.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

AI-Assisted-By: Claude Sonnet 4.6 noreply@anthropic.com

@miaulalala miaulalala requested a review from a team as a code owner May 19, 2026 13:02
@miaulalala miaulalala requested review from Altahrim, ArtificialOwl, icewind1991 and salmart-dev and removed request for a team May 19, 2026 13:02
@miaulalala miaulalala self-assigned this May 19, 2026
@miaulalala miaulalala added this to the Nextcloud 35 milestone May 19, 2026
@miaulalala
Copy link
Copy Markdown
Contributor Author

/backport to stable34

@miaulalala
Copy link
Copy Markdown
Contributor Author

/backport to stable33

@miaulalala
Copy link
Copy Markdown
Contributor Author

/backport to stable32

@susnux susnux added the bug label May 19, 2026
getFolderContentsById has no ORDER BY, so getFolderContents returns
rows in an arbitrary order that varies across DB engines and parallel
runs. Index the result by name instead of relying on array position.

AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Anna Larch <anna@nextcloud.com>
- 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>
@miaulalala miaulalala force-pushed the fix/cache-test-order-dependency branch from 92809c3 to 32fda16 Compare May 20, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants