Repository navigation
Keep shared lock for post-hooks - #17030
Conversation
06bb8de to
bd40100
Compare
|
I added some nice unit tests: bd40100#diff-82902132462e0bedddfef05bdebb9373R1373 to cover all operations. But still missing a few like rename, copy, etc. Will continue soon. |
|
Added even more massive unit tests to cover as much as possible regarding locking. But the tests have a problem: some init parts cannot work due to mocked methods. Either this, or mock more methods to remove the need for actual file creation. (ex: mocking "file_exists") |
6a97958 to
fd11d10
Compare
|
Finally! I was able to fix the unit tests to make them work. Next step is to verify if files_versions and co (all apps that use post hooks) can still work properly. |
|
SHIT, there are stray locks from other tests messing up with the new tests... |
|
Should check whether there are still aquired locks in the tearDownAfterClass method in our base class? |
|
Yes, I'm adding a "tearDownAfterClassStrayLocks" method that releases the locks. |
|
Hmm, doesn't help. It looks like the code change breaks sharing API tests. |
|
The problem occurs here: https://github.com/owncloud/core/pull/17030/files#diff-d9747e68e80ce288dcea911cb8607546R698 On master we called: $this->unlockFile($path1, ILockingProvider::LOCK_EXCLUSIVE);and I changed it to $this->changeLockFile($path1, ILockingProvider::LOCK_SHARED);For some reason unlocking an exclusive lock works, but not changing it back to shared ?! |
|
Looks like a bug on master, the paths were always wrong but we never threw exceptions when unlocking non-locked paths, see #17070 |
|
When applying #17070 all tests pass. |
|
Rebased |
|
Not rebasing/jenkinsing-PRing yet, I'll try to add an additional unit test for moveable mount points. |
Instead of unlocking after the file operation, change exclusive locks back to shared locks during post hooks, and unlock after that. Also added unit tests to test locking in pre-hooks, during operation and post-hooks.
|
Added unit test for moveMount. Now still need to find out if files_versions and co still work with their post hooks... |
|
Jenkins PR #17176 |
|
All seem to work fine. |
|
@icewind1991 @nickvergessen @DeepDiver1975 @schiesbn please review |
|
Looks good 👍 |
There was a problem hiding this comment.
Instead of a public internal method, you could also call Test\TestCase::invokePrivate($instance, 'providers', [[]]);
There was a problem hiding this comment.
yes, please no public methods just for unit testing
There was a problem hiding this comment.
The method isn't really public, it's not on the interface.
I thought we recently were against using invokePrivate ?
There was a problem hiding this comment.
Why should we be against invokePrivate? That's also the only way to test protected methods or manipulate internal properties if needed for testing.
There was a problem hiding this comment.
I remember @nickvergessen saying we shouldn't use invokePrivate any more.
There was a problem hiding this comment.
and that call you proposed looks ugly and not very readable.
I'll see if I can find another alternative, probably next week.
There was a problem hiding this comment.
By the way, this practice was approved before: https://github.com/owncloud/core/blob/master/lib/private/files/storage/storagefactory.php#L69
Would removeMountProvider be more acceptable then as internal method ?
There was a problem hiding this comment.
I remember @nickvergessen saying we shouldn't use invokePrivate any more.
\Test_Helper::invokePrivate() should not be used anymore, because it is now part of the base TestCase class we have.
Well you can at least make the method private/protected and use invokePrivate to call the protected method. This avoids anyone using it, but I'd really prefer to just reset the value with invokePrivate
There was a problem hiding this comment.
By the way, this practice was approved before: https://github.com/owncloud/core/blob/master/lib/private/files/storage/storagefactory.php#L69
Probably because it was not known that reflection could be used to achieve the same in the unit test. For example you can also find some old unit tests from me where I created a sub-class with a public method just to call a protected method of the parent in order to test it. But these days I would always use invokePrivate().
Making code testable is a good thing, but imho productive code shouldn't contain code which is needed for testing only.
There was a problem hiding this comment.
I can replace this with a method "removeMountProvider" which can be made public.
This way apps have the possibility to unregister their mount providers when needed.
And tests can too.
|
A new inspection was created. |
|
Now using invokePrivate: 271ef9d |
|
Jenkins PR second edition: #17200 |
|
Still needs a second review @nickvergessen @schiesbn please have a look. |
|
Code looks good, will do a smashbox round against this in a bit, just to be sure. |
|
|
failing basicSync is present on master as well |
Hence the "(no new fails)" |
Keep shared lock for post-hooks

Instead of unlocking after the file operation, change exclusive locks
back to shared locks during post hooks, and unlock after that
Fixes #16829
@icewind1991