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

Passive watch mode for tests #4678

Merged
merged 31 commits into from
Jun 10, 2021
Merged

Conversation

aalekseyev
Copy link
Collaborator

@aalekseyev aalekseyev commented Jun 1, 2021

This PR makes the following changes:

  1. Add a new dune flag:
       --passive-watch-mode
           Do not automatically start or re-start a build. Only do it when a
           build RPC is received.

This is much better for dune automation than the vanilla watching mode itself because it lets the automation harness decide when to proceed with the build. We'll use it for tests now, but it can also be useful for the CI.

  1. Implement dune rpc build command which sends the build rpc to dune, to interact with the passive watch mode. I re-purposed a stub of an existing build rpc which already existed, but was not usable and behaved strangely.

  2. To implement (dune rpc build) in a race-free way, added an inotify Sync mechanism to the filesystem watcher. By doing an inotify sync you're making sure that you've consumed all inotify events generated so far before proceeding with the build.

  3. Add the beginning of watching mode test suite that makes use of this functionality.

@aalekseyev aalekseyev force-pushed the dune-build-rpc-for-tests branch from 9eab063 to edf1cd8 Compare June 1, 2021 18:26
@aalekseyev

This comment has been minimized.

@aalekseyev

This comment has been minimized.

@rgrinberg

This comment has been minimized.

rgrinberg and others added 11 commits June 1, 2021 23:34
Remove clients from session set after disconnect

Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
@aalekseyev aalekseyev force-pushed the dune-build-rpc-for-tests branch from f13fb5f to 0627881 Compare June 2, 2021 16:09
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
@aalekseyev aalekseyev marked this pull request as ready for review June 7, 2021 09:38
@aalekseyev aalekseyev requested a review from a user June 7, 2021 09:38
bin/common.ml Outdated Show resolved Hide resolved
Signed-off-by: Jeremie Dimino <[email protected]>
( report_error:(Exn_with_backtrace.t -> unit)
-> unit
-> [ `Continue | `Stop ] Fiber.t)
(report_error:(Exn_with_backtrace.t -> unit) -> [ `Continue ] Fiber.t)
Copy link

Choose a reason for hiding this comment

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

Could we make poll and poll_passive have a more similar API? I find it odd that one takes a "one step" function, while the other takes a get_build_request that returns a "one step" function. The fact that get_build_request is blocking on the RPC is an implementation detail that is not very interesting from the point of view the scheduler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm thinking of the RPC as not being the part of the build because including RPCs into build seems weird (breaks some intuitions about the build being deterministic).
But there are also practical reasons related to scheduler:

  • The build can be cancelled by a filesystem event, while the wait for the RPC can not.
  • The inotify sync needs to happen after the rpc, but before the build.

I'm not sure how to abstract that away.
Overall, I feel like polling loop is inherently going to interact with these concerns, but the scheduler does not have to. Having polling loop integrated with the scheduler is what seems weird to me.

I took a bite at one step in what seems the right direction to me in:
aalekseyev@dbf0c25

This moves the filesystem event notifications into a separate variable (Invalidation_accumulator_var.t), but it's not really achieving enough to claim any separation.

Copy link

Choose a reason for hiding this comment

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

Yeah, I'm not arguing for having a single function, but at least similar APIs to learn to work with. The two run_... functions in build_cmd.ml end up having pretty different structure, which makes the code harder to review. If the two poll function had a similar API, then the two functions in build_cmd.ml should be more similar as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, got it. I'd argue build_cmd.ml is messy for a different reason: because I wrote it badly.
I just pushed a commit that simplifies code in build_cmd.ml.

As for the scheduler.mli, my initial desire was to move the entire implementation of poll_passive into build_cmd.ml, but I couldn't do it without exposing details of the state machine. Any ideas for any specific improvements are very welcome!

Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
@aalekseyev aalekseyev changed the title Dune build rpc for tests Passive watch mode for tests Jun 10, 2021
Signed-off-by: Arseniy Alekseyev <[email protected]>
Signed-off-by: Arseniy Alekseyev <[email protected]>
@aalekseyev
Copy link
Collaborator Author

aalekseyev commented Jun 10, 2021

@jeremiedimino, OK, I merged and the types in scheduler.mli look nicer now.

The error handling unification also let me unify the Hooks.End_of_build.run here in bin/build_cmd.ml, so it's done both in polling and in non-polling mode.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Looks good. I didn't check the changes to the RPC, but the other changes look good to me.

@aalekseyev aalekseyev force-pushed the dune-build-rpc-for-tests branch from 88ac915 to 5f7424a Compare June 10, 2021 13:43
Signed-off-by: Arseniy Alekseyev <[email protected]>
@aalekseyev
Copy link
Collaborator Author

@rgrinberg, I made some changes to rpc code in this PR (mainly: factor pieces out to be able to support the --wait flag in dune rpc build).
Would you like to look at them before I merge, or should I just go ahead?

@aalekseyev
Copy link
Collaborator Author

By the way, @rgrinberg, I never tested if Sync events actually work with fswatch. Our CI does not have fswatch installed. If we can install it, we could try to enable the tests on a mac (preferably in a separate PR).

@aalekseyev aalekseyev merged commit 6698257 into ocaml:main Jun 10, 2021
@ghost ghost mentioned this pull request Jun 14, 2021
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