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

Non-terminating "test" actions #325

Open
LightAndLight opened this issue Oct 3, 2024 · 1 comment
Open

Non-terminating "test" actions #325

LightAndLight opened this issue Oct 3, 2024 · 1 comment
Labels
linear Created by Linear-GitHub Sync

Comments

@LightAndLight
Copy link

LightAndLight commented Oct 3, 2024

I'd like to run a non-terminating --test-ghci command (a warp web server).

Currently this doesn't work as expected, because ghciwatch waits for the test action to finish before continuing to process events. I want events to be processed while the test action is running, so that the test action can be killed if a reload/restart event comes in.

@github-actions github-actions bot added the linear Created by Linear-GitHub Sync label Oct 3, 2024
@LightAndLight
Copy link
Author

LightAndLight commented Oct 3, 2024

#143 (comment):

I'd really like to hear a proposed design, too, since I'm not sure how I'd implement that.

Abstractly, I want to:

  1. Run the test action concurrently with the rest of the program
  2. On the GHCi session thread, wait for the first of: {watcher event received, test action terminated}
  3. Kill the test action if a watcher event is received before the test action has terminated

I could do this quite easily in Haskell. Much less sure of how to do it in Rust+Tokio. What follows is a sketch of how I'd start, but since I don't know much about the codebase or Tokio I mostly expect it to start the brainstorming.

The first thing I'd try is spawning the test call instead of awaiting it:

self.test(log).await?;

and returning a JoinHandle from finish_compilation and Ghci::initialize. The JoinHandle would be returned from Ghci::initialize in run_ghci:

tokio::select! {
_ = handle.on_shutdown_requested() => {
ghci.stop().await.wrap_err("Failed to quit ghci")?;
}
startup_result = ghci.initialize(&mut log, [LifecycleEvent::Startup(hooks::When::After)]) => {
startup_result?;
}
}

and could then be waited on here:

let event = tokio::select! {
_ = handle.on_shutdown_requested() => {
ghci.lock().await.stop().await.wrap_err("Failed to quit ghci")?;
break;
}
ret = receiver.recv() => {
ret.ok_or_else(|| miette!("ghci event channel closed"))?
}
};

If an event happens before the test action task completes, the JoinHandle can be aborted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear Created by Linear-GitHub Sync
Projects
None yet
Development

No branches or pull requests

1 participant