mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-29 07:52:19 +03:00
Added a way to change the timeout with state
This commit is contained in:
parent
9c518085ae
commit
02525c5bbe
@ -151,6 +151,7 @@ pub struct AsyncAppContext(Rc<RefCell<MutableAppContext>>);
|
|||||||
pub struct TestAppContext {
|
pub struct TestAppContext {
|
||||||
cx: Rc<RefCell<MutableAppContext>>,
|
cx: Rc<RefCell<MutableAppContext>>,
|
||||||
foreground_platform: Rc<platform::test::ForegroundPlatform>,
|
foreground_platform: Rc<platform::test::ForegroundPlatform>,
|
||||||
|
condition_duration: Option<Duration>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
@ -337,6 +338,7 @@ impl TestAppContext {
|
|||||||
let cx = TestAppContext {
|
let cx = TestAppContext {
|
||||||
cx: Rc::new(RefCell::new(cx)),
|
cx: Rc::new(RefCell::new(cx)),
|
||||||
foreground_platform,
|
foreground_platform,
|
||||||
|
condition_duration: None,
|
||||||
};
|
};
|
||||||
cx.cx.borrow_mut().weak_self = Some(Rc::downgrade(&cx.cx));
|
cx.cx.borrow_mut().weak_self = Some(Rc::downgrade(&cx.cx));
|
||||||
cx
|
cx
|
||||||
@ -612,6 +614,19 @@ impl TestAppContext {
|
|||||||
test_window
|
test_window
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_condition_duration(&mut self, duration: Duration) {
|
||||||
|
self.condition_duration = Some(duration);
|
||||||
|
}
|
||||||
|
pub fn condition_duration(&self) -> Duration {
|
||||||
|
self.condition_duration.unwrap_or_else(|| {
|
||||||
|
if std::env::var("CI").is_ok() {
|
||||||
|
Duration::from_secs(2)
|
||||||
|
} else {
|
||||||
|
Duration::from_millis(500)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncAppContext {
|
impl AsyncAppContext {
|
||||||
@ -4398,6 +4413,7 @@ impl<T: View> ViewHandle<T> {
|
|||||||
use postage::prelude::{Sink as _, Stream as _};
|
use postage::prelude::{Sink as _, Stream as _};
|
||||||
|
|
||||||
let (tx, mut rx) = postage::mpsc::channel(1024);
|
let (tx, mut rx) = postage::mpsc::channel(1024);
|
||||||
|
let timeout_duration = cx.condition_duration();
|
||||||
|
|
||||||
let mut cx = cx.cx.borrow_mut();
|
let mut cx = cx.cx.borrow_mut();
|
||||||
let subscriptions = self.update(&mut *cx, |_, cx| {
|
let subscriptions = self.update(&mut *cx, |_, cx| {
|
||||||
@ -4419,14 +4435,9 @@ impl<T: View> ViewHandle<T> {
|
|||||||
|
|
||||||
let cx = cx.weak_self.as_ref().unwrap().upgrade().unwrap();
|
let cx = cx.weak_self.as_ref().unwrap().upgrade().unwrap();
|
||||||
let handle = self.downgrade();
|
let handle = self.downgrade();
|
||||||
let duration = if std::env::var("CI").is_ok() {
|
|
||||||
Duration::from_secs(2)
|
|
||||||
} else {
|
|
||||||
Duration::from_millis(500)
|
|
||||||
};
|
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
crate::util::timeout(duration, async move {
|
crate::util::timeout(timeout_duration, async move {
|
||||||
loop {
|
loop {
|
||||||
{
|
{
|
||||||
let cx = cx.borrow();
|
let cx = cx.borrow();
|
||||||
|
@ -488,7 +488,7 @@ fn get_working_directory(wt: &LocalWorktree) -> Option<PathBuf> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use std::{path::Path, sync::atomic::AtomicUsize};
|
use std::{path::Path, sync::atomic::AtomicUsize, time::Duration};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use alacritty_terminal::{grid::GridIterator, term::cell::Cell};
|
use alacritty_terminal::{grid::GridIterator, term::cell::Cell};
|
||||||
@ -501,6 +501,8 @@ mod tests {
|
|||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_terminal(cx: &mut TestAppContext) {
|
async fn test_terminal(cx: &mut TestAppContext) {
|
||||||
let terminal = cx.add_view(Default::default(), |cx| Terminal::new(cx, None));
|
let terminal = cx.add_view(Default::default(), |cx| Terminal::new(cx, None));
|
||||||
|
cx.set_condition_duration(Duration::from_secs(2));
|
||||||
|
|
||||||
terminal.update(cx, |terminal, cx| {
|
terminal.update(cx, |terminal, cx| {
|
||||||
terminal.write_to_pty(&Input(("expr 3 + 4".to_string()).to_string()), cx);
|
terminal.write_to_pty(&Input(("expr 3 + 4".to_string()).to_string()), cx);
|
||||||
terminal.carriage_return(&Return, cx);
|
terminal.carriage_return(&Return, cx);
|
||||||
@ -510,7 +512,6 @@ mod tests {
|
|||||||
.condition(cx, |terminal, _cx| {
|
.condition(cx, |terminal, _cx| {
|
||||||
let term = terminal.term.clone();
|
let term = terminal.term.clone();
|
||||||
let content = grid_as_str(term.lock().renderable_content().display_iter);
|
let content = grid_as_str(term.lock().renderable_content().display_iter);
|
||||||
dbg!(&content);
|
|
||||||
content.contains("7")
|
content.contains("7")
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
Loading…
Reference in New Issue
Block a user