Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for path contexts + misc improvements and fixes #58

Merged
merged 10 commits into from
Dec 29, 2020

Conversation

mdproctor
Copy link
Contributor

Bug
-Carbon returns real paths, this will not map added paths which are symbolic. To address this it turns the real path back into the user provided path.
-Fixed some tests, by making them await longer

Improvements
-When underlying root paths were deleted, it would not detect and close the Carbon deamon thread or clean up the paths or invalidate the WatchKey. This is now addressed
-Can now check if DirectoryWatcher is open or closed.
-Added pom.xml so maven sort of works, but it's a quick hack and can be improved.-

Feature
-Allow a context value to be associated with a given subtree (i.e. from root path and all child paths), and provided as part of the Event. This avoids having to search for matching roots, to lookup a context value.

Bug
-Carbon returns real paths, this will not map added paths which are symbolic. To address this it turns the real path back into the user provided path.
-Fixed some tests, by making them await longer

Improvements
-When underlying root paths were deleted, it would not detect and close the Carbon deamon thread or clean up the paths or invalidate the WatchKey. This is now addressed
-Can now check if DirectoryWatcher is open or closed.
-Added pom.xml so maven sort of  works, but it's a quick hack and can be improved.-

Feature
-Allow a context value to be associated with a given subtree (i.e. from root path and all child paths), and provided as part of the Event. This avoids having to search for matching roots, to lookup a context value.
@mdproctor
Copy link
Contributor Author

I should add I only checked that the added maven pom.xml and test work. I notice the SBT scala better stuff fails, it probably needs updating.

Copy link
Owner

@gmethvin gmethvin left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request! I like the ideas but I had a few concerns.

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Owner

Choose a reason for hiding this comment

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

Why do we need a maven build?

I'm happy to discuss alternative build systems, but I think it makes more sense to discuss this in a separate issue before we make any changes. Ideally we should choose a single build system and stick with it for everything, and not try to build the project with multiple build systems.

Copy link
Contributor Author

@mdproctor mdproctor Nov 13, 2020

Choose a reason for hiding this comment

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

You don't, you can exclude it. It's just easier for me, as it was what I was familiar with, and works well in my IDE. I put it there, as it may make things easier for other people too, who don't have all the SBT/Scala stuff.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I see your point. It just hard to make sure things are consistent between the maven and sbt builds, so it ultimately ends up creating more issues for us to fix.

I am eventually thinking about splitting out the better-files extension into a completely separate library (with separate release cycle) so maybe that's the right time to consider the maven stuff.

@mdproctor
Copy link
Contributor Author

Btw I'm on gitter, if you want to chat. Left some messages for you there.

Copy link
Owner

@gmethvin gmethvin left a comment

Choose a reason for hiding this comment

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

A few more suggestions that might simplify things

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I see your point. It just hard to make sure things are consistent between the maven and sbt builds, so it ultimately ends up creating more issues for us to fix.

I am eventually thinking about splitting out the better-files extension into a completely separate library (with separate release cycle) so maybe that's the right time to consider the maven stuff.

@mdproctor
Copy link
Contributor Author

mdproctor commented Nov 14, 2020

All suggestions seem reasonable. Rather than reply individually, i'll rework them over next few days and we can re-review them.

Btw one thing I don't think was necessary, was the thread I used to close the Carbon API thread. I only did it, as I wasn't sure if it would deadlock if it was done inplace. If you feel the code won't deadlock, I can do it without needing a thread.

@gmethvin
Copy link
Owner

I don't think the extra thread is necessary based on my understanding of where the locking is happening. Was there a specific place you were concerned it would deadlock?

@mdproctor
Copy link
Contributor Author

OK, so I just removed that thread used to close the carbon API, hopefully it's ok. I wasn't sure how this was working, so was being cautious.

@gmethvin
Copy link
Owner

It looks like there's now a test failing on linux and windows builds:

Any idea what might be causing that?

@@ -145,6 +148,8 @@ public AbstractWatchKey register(
flags);

final CFRunLoopThread thread = new CFRunLoopThread(streamRef, file.toFile());
callback.onClose(() -> {watchKey.watchService().close(thread, callback, file); return null;});
Copy link
Owner

Choose a reason for hiding this comment

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

We don't use the return value, so you can change the type to Runnable to avoid the ugly return null here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mdproctor
Copy link
Contributor Author

It looks like there's now a test failing on linux and windows builds:

Any idea what might be causing that?
I don't have a linux machine, only MacOS, but I'll ask a colleague to look into it.

Copy link
Owner

@gmethvin gmethvin left a comment

Choose a reason for hiding this comment

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

Sorry I've had limited time to look at this. I really appreciate the improvements but I also want to make sure we're confident in the changes, since several major projects rely on this library.

Looking at your tests, I see you have the line:

await().atMost(3, TimeUnit.SECONDS).until(() -> recorder.events.size() == 33);

So you're expecting 33 events from the three calls to createStructure2. But it's not obvious to me why you're expecting that number of events.

You might also want to try with hashing, since some platforms fire duplicate events. The cross-platform guarantees of this library can be relaxed when it comes to duplicate events, as long as they make sense. For example, sometimes you'll get multiple modify events instead of one, as the file is being written out.

Also, my understanding is that registeredContexts is an internal data structure to map each path registered in the WatchService to the root path that was registered in DirectoryWatcher. Actually if that's the case, maybe we should name it something more obvious like registeredPathToRootPath. The term context is actually a little confusing to me because there's something called context on the WatchEvent which only refers to the registered path in the WatchService, which will be different on Linux, for example, or any other platform that doesn't support recursive watching on the WatchService.

If you'd like, you could split off the macOS-only improvements to another PR so we can get those out sooner.

treblereel and others added 3 commits December 19, 2020 19:47
-removed getRegisteredContexts
-changed registeredContexts to registeredPathToRootPath
@gmethvin gmethvin force-pushed the master branch 3 times, most recently from 9cf59fc to 99017cc Compare December 27, 2020 08:09
@gmethvin
Copy link
Owner

gmethvin commented Dec 27, 2020

@mdproctor I made some changes that appear to fix the test failures.

The main change is that I moved the tests that delete the root directory into an isMac conditional, so they will only be run for the macOS watcher. There appears to be an inconsistency between platforms in how delete events are reported for the watched roots, so I created issue #59 to track that.

I also removed uses of assumeTrue on the number of events, since those will skip the rest of the test if the condition isn't true. I don't quite understand why you used assumeTrue there, but it seems like those values were based on observed behavior rather than specific guarantees the library is trying to provide, so they aren't really that useful anyway.

Anyway, let me know if those changes look good. If so I'll merge and release.

@gmethvin gmethvin merged commit 168cd31 into gmethvin:master Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants