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

Test appending to file #118

Closed
wants to merge 1 commit into from
Closed

Conversation

davidbrochart
Copy link
Collaborator

Just copying a test here from jupyter-server/jupyter_server#783, where we see it failing on MacOS.

@codecov
Copy link

codecov bot commented Apr 8, 2022

Codecov Report

Merging #118 (a087347) into main (c35fa79) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##              main      #118   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          358       358           
  Branches        73        73           
=========================================
  Hits           358       358           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c35fa79...a087347. Read the comment docs.

@samuelcolvin
Copy link
Owner

I'm afraid this is not going to work.

MacOS filesystem notifications can be significantly delayed, sometimes by seconds. You can also get an "added" or "modified" when you delete a file

The unit tests in test_rust_notify.py have to do a lot to work around this - e.g. instead of using the tmp_path fixture, we have to have a pre-existing path which we reset after tests - otherwise the creation of the directory from tmp_path is received when the watcher starts.

You can see this by enabling debug and running watchfiles on MacOS - events are significantly confused.

@samuelcolvin
Copy link
Owner

We already have some logic to try and clean events which is for macos, but it can't cover all cases.

watchfiles/src/lib.rs

Lines 67 to 76 in c35fa79

// these events sometimes happen when creating files and deleting them, hence these checks
let changes = changes_clone.lock().unwrap();
if changes.contains(&(CHANGE_DELETED, path.clone()))
|| changes.contains(&(CHANGE_ADDED, path.clone()))
{
// file was already deleted or file was added in this batch, ignore this event
return;
} else {
CHANGE_MODIFIED
}

@davidbrochart
Copy link
Collaborator Author

Thanks for the feedback, I think I'll just simplify tests in jupyter-server for now. We don't want to test watchfiles again there. If the PR is merged we'll just trust whatever watchfiles is doing.

@samuelcolvin
Copy link
Owner

I agree that's the best way. You could even mock the rust code like we do in many of these tests.

@samuelcolvin
Copy link
Owner

#113 will also help a lot with tests - avoiding tests hanging if no change is detected.

I implemented that partly to help with the uvicorn tests for watchfiles, see encode/uvicorn#1437.

@davidbrochart
Copy link
Collaborator Author

Great, thanks!

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.

2 participants