From 2d524128c5dd29c225ab6b6da32f49512e3ce2eb Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 17 May 2026 10:49:00 -0400 Subject: [PATCH] test(dav): add clarifying comments to testPutLocking test Signed-off-by: Josh --- .../tests/unit/Connector/Sabre/FileTest.php | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index 25b09db1c54..56d5c9fee59 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -800,7 +800,13 @@ class FileTest extends TestCase { } /** - * Test whether locks are set before and after the operation + * Test that PUT keeps hook-time lock semantics compatible: + * - pre-write hooks run while the file is shared-locked + * - post-write hooks also run while the file is shared-locked + * + * Post-write hooks are expected to observe a fully finalized file state, + * but should still be able to access the file without exclusive-lock + * contention. */ public function testPutLocking(): void { $view = new View('/' . $this->user . '/files/'); @@ -832,8 +838,8 @@ class FileTest extends TestCase { $wasLockedPost = false; $eventHandler = $this->createMock(EventHandlerMock::class); - // both pre and post hooks might need access to the file, - // so only shared lock is acceptable + // Pre-write hooks should run under a shared lock so observers can safely + // inspect the target while the write is in progress. $eventHandler->expects($this->once()) ->method('writeCallback') ->willReturnCallback( @@ -842,6 +848,10 @@ class FileTest extends TestCase { $wasLockedPre = $wasLockedPre && !$this->isFileLocked($view, $path, ILockingProvider::LOCK_EXCLUSIVE); } ); + + // Post-write hooks should also run under a shared lock. They are expected to + // see fully finalized metadata/state, but still be able to access the file + // during the callback. $eventHandler->expects($this->once()) ->method('postWriteCallback') ->willReturnCallback( @@ -872,8 +882,8 @@ class FileTest extends TestCase { // afterMethod unlocks $view->unlockFile($path, ILockingProvider::LOCK_SHARED); - $this->assertTrue($wasLockedPre, 'File was locked during pre-hooks'); - $this->assertTrue($wasLockedPost, 'File was locked during post-hooks'); + $this->assertTrue($wasLockedPre, 'File was shared-locked during pre-hooks'); + $this->assertTrue($wasLockedPost, 'File was shared-locked during post-hooks'); $this->assertFalse( $this->isFileLocked($view, $path, ILockingProvider::LOCK_SHARED),