Skip to content

Conversation

@leandro-lucarella-frequenz
Copy link
Contributor

@leandro-lucarella-frequenz leandro-lucarella-frequenz commented May 5, 2023

This pull request have 2 different but related main changes:

  • The FileWatcher was skipping DELETE events, except on very weird cases where the file was deleted and re-created just before the event was triggered by awatch().

    This also extends the integration test to test both situations (delete events when a file exist and when it doesn't).

    Because there is usually a considerable delay between a change in the filesystem happens and awatch() emits an event it is difficult to decide if we should filter events based on the file existing or not. For example, if a create event is received but before is triggered the file was removed, should we emit the create event or not? Or the other way around, should we emit a delete event if a file was created again before the event was triggered.

    It is probably best to leave this decision to the user, and let them deal with races.

  • FileWatcher tests were rearranged and split between unit and integration tests.

    The existing tests were really integration tests, as they are not only testing FileWatcher, but also Select and PeriodicTimer, which is confusing when there is a bug in any of the other classes as we might get test failures here (this actually happened during the development of Make the timer generic and support periodic timers #79).

    Because of this the current tests were moved to test/util/test_integration.py. We also mark the tests with the pytest mark integration to make it more clear they are integration tests, and to enable an easy way to only run (exclude) integration tests.

    New unit tests were added to the current test file, properly mocking awatch to avoid interactions with the OS.

    There are many more integration tests posing as unit tests, but this PR only takes care of FileWatcher. With time we should move the rest too.

@leandro-lucarella-frequenz leandro-lucarella-frequenz added type:bug Something isn't working type:tech-debt Improves the project without visible changes for users labels May 5, 2023
@leandro-lucarella-frequenz leandro-lucarella-frequenz added this to the v0.15.0 milestone May 5, 2023
@leandro-lucarella-frequenz leandro-lucarella-frequenz requested a review from a team as a code owner May 5, 2023 13:49
@github-actions github-actions bot added part:docs Affects the documentation part:core Affects the core types (`Sender`, `Receiver`, exceptions, etc.) part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) labels May 5, 2023
@leandro-lucarella-frequenz leandro-lucarella-frequenz force-pushed the file-watcher-tests branch 3 times, most recently from 02bfb48 to b9932fe Compare May 8, 2023 13:23
llucax added 3 commits May 9, 2023 09:18
The existing tests are really integration tests, as they are not only
testing `FileWatcher`, but also `Select` and `PeriodicTimer`, which is
confusing when there is a bug in any of the other classes as we might
get test failures here.

This commit adds a a proper unit tests mocking `awatch`.

Signed-off-by: Leandro Lucarella <[email protected]>
Since the integration tests in the `FileWatcher` tests are actually
testing 3 different classes (and interacting with the OS), we move it
to its own file, and we call it more generally.

We also mark the tests with the pytest mark `integration` to make it
more clear they are integration tests, and to enable an easy way to
only run (exclude) integration tests.

Signed-off-by: Leandro Lucarella <[email protected]>
Separate the function to filter events so it is easier to test
separately.

Also remove an unnecessary `type: ignore` whole at it.

Signed-off-by: Leandro Lucarella <[email protected]>
@leandro-lucarella-frequenz
Copy link
Contributor Author

Rebased and added a note on how to test the new timer with async-solipsism now.

I would make a release after this is merged.

Copy link
Contributor

@daniel-zullo-frequenz daniel-zullo-frequenz left a comment

Choose a reason for hiding this comment

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

I have only 2 cosmetic comments to check for, LGTM otherwise

@daniel-zullo-frequenz
Copy link
Contributor

I would make a release after this is merged.

@leandro-lucarella-frequenz can you please wait for a simple PR that addresses #53 which is based on the changes on this PR?

llucax and others added 4 commits May 9, 2023 15:12
The FileWatcher was skipping DELETE events, except on very weird cases
where the file was deleted and re-created just before the event was
triggered by awatch().

This also extends the integration test to test both situations (delete
events when a file exist and when it doesn't).

Because there is usually a considerable delay between a change in the
filesystem happens and awatch() emits an event it is difficult to decide
if we should filter events based on the file existing or not. For
example, if a create event is received but before is triggered the file
was removed, should we emit the create event or not? Or the other way
around, should we emit a delete event if a file was created again before
the event was triggered.

It is probably best to leave this decision to the user, and let them
deal with races.

Signed-off-by: Leandro Lucarella <[email protected]>
Co-authored-by: daniel-zullo-frequenz <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
@leandro-lucarella-frequenz leandro-lucarella-frequenz merged commit 8ae4186 into frequenz-floss:v0.x.x May 9, 2023
@leandro-lucarella-frequenz leandro-lucarella-frequenz deleted the file-watcher-tests branch May 9, 2023 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:core Affects the core types (`Sender`, `Receiver`, exceptions, etc.) part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) type:bug Something isn't working type:tech-debt Improves the project without visible changes for users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants