diff options
| author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-04-04 01:24:46 +0530 |
|---|---|---|
| committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-04 20:48:15 +0530 |
| commit | 2a648187fc8d4afc9b34d322b4f8394dcd39b6dd (patch) | |
| tree | e85afef2b8e03d6e86a85f57c9b9a3da75d823e3 /src/tests | |
| parent | Move screen and plugins to client side. (diff) | |
| download | sl0ppij-2a648187fc8d4afc9b34d322b4f8394dcd39b6dd.tar.gz sl0ppij-2a648187fc8d4afc9b34d322b4f8394dcd39b6dd.tar.xz sl0ppij-2a648187fc8d4afc9b34d322b4f8394dcd39b6dd.zip | |
Fix after rebase
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/fakes.rs | 42 | ||||
| -rw-r--r-- | src/tests/integration/terminal_window_resize.rs | 24 |
2 files changed, 51 insertions, 15 deletions
diff --git a/src/tests/fakes.rs b/src/tests/fakes.rs index f5b03fde..8c608de3 100644 --- a/src/tests/fakes.rs +++ b/src/tests/fakes.rs @@ -3,8 +3,7 @@ use std::collections::{HashMap, VecDeque}; use std::io::Write; use std::os::unix::io::RawFd; use std::path::PathBuf; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::{mpsc, Arc, Mutex}; +use std::sync::{mpsc, Arc, Condvar, Mutex}; use std::time::{Duration, Instant}; use crate::client::ClientInstruction; @@ -13,8 +12,7 @@ use crate::errors::ErrorContext; use crate::os_input_output::{ClientOsApi, ServerOsApi}; use crate::server::ServerInstruction; use crate::tests::possible_tty_inputs::{get_possible_tty_inputs, Bytes}; -use crate::utils::shared::default_palette; -use zellij_tile::data::Palette; +use crate::tests::utils::commands::{QUIT, SLEEP}; const MIN_TIME_BETWEEN_SNAPSHOTS: Duration = Duration::from_millis(150); @@ -76,11 +74,12 @@ pub struct FakeInputOutput { win_sizes: Arc<Mutex<HashMap<RawFd, PositionAndSize>>>, possible_tty_inputs: HashMap<u16, Bytes>, last_snapshot_time: Arc<Mutex<Instant>>, - started_reading_from_pty: Arc<AtomicBool>, client_sender: SenderWithContext<ClientInstruction>, client_receiver: Arc<Mutex<mpsc::Receiver<(ClientInstruction, ErrorContext)>>>, server_sender: SenderWithContext<ServerInstruction>, server_receiver: Arc<Mutex<mpsc::Receiver<(ServerInstruction, ErrorContext)>>>, + should_trigger_sigwinch: Arc<(Mutex<bool>, Condvar)>, + sigwinch_event: Option<PositionAndSize>, } impl FakeInputOutput { @@ -108,11 +107,12 @@ impl FakeInputOutput { io_events: Arc::new(Mutex::new(vec![])), win_sizes: Arc::new(Mutex::new(win_sizes)), possible_tty_inputs: get_possible_tty_inputs(), - started_reading_from_pty: Arc::new(AtomicBool::new(false)), server_receiver: Arc::new(Mutex::new(server_receiver)), server_sender, client_receiver: Arc::new(Mutex::new(client_receiver)), client_sender, + should_trigger_sigwinch: Arc::new((Mutex::new(false), Condvar::new())), + sigwinch_event: None, } } pub fn with_tty_inputs(mut self, tty_inputs: HashMap<u16, Bytes>) -> Self { @@ -171,14 +171,24 @@ impl ClientOsApi for FakeInputOutput { ::std::thread::sleep(MIN_TIME_BETWEEN_SNAPSHOTS - last_snapshot_time.elapsed()); } } - if self.stdin_commands.lock().unwrap().len() == 1 { - std::thread::sleep(Duration::from_millis(100)); - } - self.stdin_commands + let command = self + .stdin_commands .lock() .unwrap() .pop_front() - .unwrap_or(vec![]) + .unwrap_or(vec![]); + if command == SLEEP { + std::thread::sleep(std::time::Duration::from_millis(200)); + } else if command == QUIT && self.sigwinch_event.is_some() { + let (lock, cvar) = &*self.should_trigger_sigwinch; + let mut should_trigger_sigwinch = lock.lock().unwrap(); + *should_trigger_sigwinch = true; + cvar.notify_one(); + ::std::thread::sleep(MIN_TIME_BETWEEN_SNAPSHOTS); // give some time for the app to resize before quitting + } else if command == QUIT { + ::std::thread::sleep(MIN_TIME_BETWEEN_SNAPSHOTS); + } + command } fn get_stdout_writer(&self) -> Box<dyn Write> { Box::new(self.stdout_writer.clone()) @@ -199,6 +209,16 @@ impl ClientOsApi for FakeInputOutput { fn client_recv(&self) -> (ClientInstruction, ErrorContext) { self.client_receiver.lock().unwrap().recv().unwrap() } + fn receive_sigwinch(&self, cb: Box<dyn Fn()>) { + if self.sigwinch_event.is_some() { + let (lock, cvar) = &*self.should_trigger_sigwinch; + let mut should_trigger_sigwinch = lock.lock().unwrap(); + while !*should_trigger_sigwinch { + should_trigger_sigwinch = cvar.wait(should_trigger_sigwinch).unwrap(); + } + cb(); + } + } } impl ServerOsApi for FakeInputOutput { diff --git a/src/tests/integration/terminal_window_resize.rs b/src/tests/integration/terminal_window_resize.rs index ebea82c0..5aa13e15 100644 --- a/src/tests/integration/terminal_window_resize.rs +++ b/src/tests/integration/terminal_window_resize.rs @@ -30,7 +30,11 @@ pub fn window_width_decrease_with_one_pane() { ..Default::default() }); let opts = CliArgs::default(); - start(Box::new(fake_input_output.clone()), opts, Config::default()); + start( + Box::new(fake_input_output.clone()), + opts, + Box::new(fake_input_output.clone()), + ); let output_frames = fake_input_output .stdout_writer .output_frames @@ -61,7 +65,11 @@ pub fn window_width_increase_with_one_pane() { ..Default::default() }); let opts = CliArgs::default(); - start(Box::new(fake_input_output.clone()), opts, Config::default()); + start( + Box::new(fake_input_output.clone()), + opts, + Box::new(fake_input_output.clone()), + ); let output_frames = fake_input_output .stdout_writer .output_frames @@ -92,7 +100,11 @@ pub fn window_height_increase_with_one_pane() { ..Default::default() }); let opts = CliArgs::default(); - start(Box::new(fake_input_output.clone()), opts, Config::default()); + start( + Box::new(fake_input_output.clone()), + opts, + Box::new(fake_input_output.clone()), + ); let output_frames = fake_input_output .stdout_writer .output_frames @@ -123,7 +135,11 @@ pub fn window_width_and_height_decrease_with_one_pane() { ..Default::default() }); let opts = CliArgs::default(); - start(Box::new(fake_input_output.clone()), opts, Config::default()); + start( + Box::new(fake_input_output.clone()), + opts, + Box::new(fake_input_output.clone()), + ); let output_frames = fake_input_output .stdout_writer .output_frames |
