Skip to content

Keep shared lock for post-hooks - #17030

Merged
nickvergessen merged 3 commits into
masterfrom
lock-posthooks
Jun 29, 2015
Merged

nickvergessen merged 3 commits into
masterfrom
lock-posthooks

Conversation

@PVince81

Copy link
Copy Markdown
Contributor

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

Fixes #16829

@icewind1991

  • properly regression test the affected code paths
  • check with versions and other apps that use post hooks

@PVince81 PVince81 added this to the 8.1-current milestone Jun 18, 2015
Comment thread lib/private/files/view.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOPE

@PVince81
PVince81 force-pushed the lock-posthooks branch 2 times, most recently from 06bb8de to bd40100 Compare June 19, 2015 12:58
@PVince81

Copy link
Copy Markdown
Contributor Author

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.

@PVince81 PVince81 changed the title [WIP] Keep shared lock for post-hooks Keep shared lock for post-hooks Jun 19, 2015
@PVince81

Copy link
Copy Markdown
Contributor Author

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.
So instead of mounting the mocked storage to the root, I should try using the regular user's home, and then mount the mock in a subdir instead.

Either this, or mock more methods to remove the need for actual file creation. (ex: mocking "file_exists")

@PVince81
PVince81 force-pushed the lock-posthooks branch 2 times, most recently from 6a97958 to fd11d10 Compare June 22, 2015 09:45
@PVince81

Copy link
Copy Markdown
Contributor Author

Finally! I was able to fix the unit tests to make them work.
It is nice to have them.

Next step is to verify if files_versions and co (all apps that use post hooks) can still work properly.

@PVince81

Copy link
Copy Markdown
Contributor Author

SHIT, there are stray locks from other tests messing up with the new tests...

@nickvergessen

Copy link
Copy Markdown
Contributor

Should check whether there are still aquired locks in the tearDownAfterClass method in our base class?

@PVince81

Copy link
Copy Markdown
Contributor Author

Yes, I'm adding a "tearDownAfterClassStrayLocks" method that releases the locks.
Normally locks are released at the end of a PHP request.

@PVince81

Copy link
Copy Markdown
Contributor Author

Hmm, doesn't help.

It looks like the code change breaks sharing API tests.
Will try and debug it.

@PVince81

Copy link
Copy Markdown
Contributor Author

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 ?!

@PVince81

Copy link
Copy Markdown
Contributor Author

Looks like a bug on master, the paths were always wrong but we never threw exceptions when unlocking non-locked paths, see #17070

@PVince81

Copy link
Copy Markdown
Contributor Author

When applying #17070 all tests pass.

@PVince81

Copy link
Copy Markdown
Contributor Author

Rebased

@PVince81

Copy link
Copy Markdown
Contributor Author

Not rebasing/jenkinsing-PRing yet, I'll try to add an additional unit test for moveable mount points.
Wish me luck! (already tried 2 times and failed)

Vincent Petry added 2 commits June 25, 2015 16:33
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.
@PVince81

Copy link
Copy Markdown
Contributor Author

Added unit test for moveMount.

Now still need to find out if files_versions and co still work with their post hooks...

@PVince81

Copy link
Copy Markdown
Contributor Author

Jenkins PR #17176

@PVince81

Copy link
Copy Markdown
Contributor Author
  • TEST: create versions
  • TEST: sharing + versions
  • TEST: trashbin + restore

@PVince81

Copy link
Copy Markdown
Contributor Author
  • TEST: unshareChildren on post-delete
  • TEST: webdav copy (post-copy for versions)
  • TEST: encryption post-rename

All seem to work fine.

@PVince81

Copy link
Copy Markdown
Contributor Author

@icewind1991 @nickvergessen @DeepDiver1975 @schiesbn please review

@icewind1991

Copy link
Copy Markdown
Contributor

Looks good 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a public internal method, you could also call Test\TestCase::invokePrivate($instance, 'providers', [[]]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, please no public methods just for unit testing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method isn't really public, it's not on the interface.
I thought we recently were against using invokePrivate ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we be against invokePrivate? That's also the only way to test protected methods or manipulate internal properties if needed for testing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember @nickvergessen saying we shouldn't use invokePrivate any more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and that call you proposed looks ugly and not very readable.

I'll see if I can find another alternative, probably next week.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@scrutinizer-notifier

Copy link
Copy Markdown

A new inspection was created.

@PVince81

Copy link
Copy Markdown
Contributor Author

Now using invokePrivate: 271ef9d

@PVince81

Copy link
Copy Markdown
Contributor Author

Jenkins PR second edition: #17200

@MorrisJobke

Copy link
Copy Markdown
Contributor

Jenkins succeeded:

🚀 Test PASSed.🚀
chuck

@PVince81

Copy link
Copy Markdown
Contributor Author

Still needs a second review @nickvergessen @schiesbn please have a look.

@nickvergessen

Copy link
Copy Markdown
Contributor

Code looks good, will do a smashbox round against this in a bit, just to be sure.

@nickvergessen

Copy link
Copy Markdown
Contributor
Test Result
reshareDir ✅
shareDir ✅
shareFile ✅
shareGroup ✅
sharePermissions ✅
uploadFiles ✅
basicSync ✖️ (no new fails)

@DeepDiver1975

Copy link
Copy Markdown
Contributor

failing basicSync is present on master as well

@nickvergessen

Copy link
Copy Markdown
Contributor

failing basicSync is present on master as well

Hence the "(no new fails)"

nickvergessen added a commit that referenced this pull request Jun 29, 2015
Keep shared lock for post-hooks
@nickvergessen
nickvergessen merged commit 70eb20e into master Jun 29, 2015
@nickvergessen
nickvergessen deleted the lock-posthooks branch June 29, 2015 12:17
@PVince81 PVince81 mentioned this pull request Jul 1, 2015
36 of 46 tasks
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Acquire locks before post-hooks, release afterwards

7 participants