diff options
| author | Aram Drevekenin <aram@poor.dev> | 2021-06-30 11:27:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-30 11:27:35 +0200 |
| commit | ed4fd2a8e77df304539ca7f445a78039028eaa8a (patch) | |
| tree | ae48b03370b11f3f0987676584724463ac83460d /zellij-server/src/thread_bus.rs | |
| parent | Merge pull request #590 from a-kenji/clippy-fixes (diff) | |
| download | sl0ppij-ed4fd2a8e77df304539ca7f445a78039028eaa8a.tar.gz sl0ppij-ed4fd2a8e77df304539ca7f445a78039028eaa8a.tar.xz sl0ppij-ed4fd2a8e77df304539ca7f445a78039028eaa8a.zip | |
chore(tests): move all integration tests to be either unit or e2e tests - remove old testing infra (#589)
* tests(integration): move basic integration tests to be unit tests
* fix(tests): silently fail threadbus for tests
* tests(unit): move compatibility tests to become unit tests for grid
* tests(unit): move close_pane tests to become unit tests for grid
* tests(e2e): move basic layout test to e2e
* tests(unit): move move_focus tests to be unit tests
* tests(unit): move resize_down tests to be unit tests
* tests(unit): move resize_left tests to be unit tests
* tests(unit): move resize_right tests to be unit tests
* tests(unit): move resize_up tests to be unit tests
* tests(infra): remove unused infra
* style(fmt): make rustfmt happy
* debug
* debug
* debug
* debug
* chore(test): shift volume mounting around because github actions is a special child
Diffstat (limited to 'zellij-server/src/thread_bus.rs')
| -rw-r--r-- | zellij-server/src/thread_bus.rs | 72 |
1 files changed, 67 insertions, 5 deletions
diff --git a/zellij-server/src/thread_bus.rs b/zellij-server/src/thread_bus.rs index f7c1c1eb..c7262993 100644 --- a/zellij-server/src/thread_bus.rs +++ b/zellij-server/src/thread_bus.rs @@ -7,12 +7,15 @@ use crate::{ use zellij_utils::{channels, channels::SenderWithContext, errors::ErrorContext}; /// A container for senders to the different threads in zellij on the server side -#[derive(Clone)] +#[derive(Default, Clone)] pub(crate) struct ThreadSenders { pub to_screen: Option<SenderWithContext<ScreenInstruction>>, pub to_pty: Option<SenderWithContext<PtyInstruction>>, pub to_plugin: Option<SenderWithContext<PluginInstruction>>, pub to_server: Option<SenderWithContext<ServerInstruction>>, + // this is a convenience for the unit tests + // it's not advisable to set it to true in production code + pub should_silently_fail: bool, } impl ThreadSenders { @@ -20,32 +23,75 @@ impl ThreadSenders { &self, instruction: ScreenInstruction, ) -> Result<(), channels::SendError<(ScreenInstruction, ErrorContext)>> { - self.to_screen.as_ref().unwrap().send(instruction) + if self.should_silently_fail { + let _ = self + .to_screen + .as_ref() + .map(|sender| sender.send(instruction)) + .unwrap_or_else(|| Ok(())); + Ok(()) + } else { + self.to_screen.as_ref().unwrap().send(instruction) + } } pub fn send_to_pty( &self, instruction: PtyInstruction, ) -> Result<(), channels::SendError<(PtyInstruction, ErrorContext)>> { - self.to_pty.as_ref().unwrap().send(instruction) + if self.should_silently_fail { + let _ = self + .to_pty + .as_ref() + .map(|sender| sender.send(instruction)) + .unwrap_or_else(|| Ok(())); + Ok(()) + } else { + self.to_pty.as_ref().unwrap().send(instruction) + } } pub fn send_to_plugin( &self, instruction: PluginInstruction, ) -> Result<(), channels::SendError<(PluginInstruction, ErrorContext)>> { - self.to_plugin.as_ref().unwrap().send(instruction) + if self.should_silently_fail { + let _ = self + .to_plugin + .as_ref() + .map(|sender| sender.send(instruction)) + .unwrap_or_else(|| Ok(())); + Ok(()) + } else { + self.to_plugin.as_ref().unwrap().send(instruction) + } } pub fn send_to_server( &self, instruction: ServerInstruction, ) -> Result<(), channels::SendError<(ServerInstruction, ErrorContext)>> { - self.to_server.as_ref().unwrap().send(instruction) + if self.should_silently_fail { + let _ = self + .to_server + .as_ref() + .map(|sender| sender.send(instruction)) + .unwrap_or_else(|| Ok(())); + Ok(()) + } else { + self.to_server.as_ref().unwrap().send(instruction) + } + } + #[allow(unused)] + pub fn silently_fail_on_send(mut self) -> Self { + // this is mostly used for the tests, see struct + self.should_silently_fail = true; + self } } /// A container for a receiver, OS input and the senders to a given thread +#[derive(Default)] pub(crate) struct Bus<T> { receivers: Vec<channels::Receiver<(T, ErrorContext)>>, pub senders: ThreadSenders, @@ -68,10 +114,26 @@ impl<T> Bus<T> { to_pty: to_pty.cloned(), to_plugin: to_plugin.cloned(), to_server: to_server.cloned(), + should_silently_fail: false, }, os_input: os_input.clone(), } } + #[allow(unused)] + pub fn empty() -> Self { + // this is mostly used for the tests + Bus { + receivers: vec![], + senders: ThreadSenders { + to_screen: None, + to_pty: None, + to_plugin: None, + to_server: None, + should_silently_fail: true, + }, + os_input: None, + } + } pub fn recv(&self) -> Result<(T, ErrorContext), channels::RecvError> { let mut selector = channels::Select::new(); |
