diff --git a/Cargo.lock b/Cargo.lock index 21a08332c5e08e81c35c0d9d4db343a38983d0d6..91d3b95f47c521bbcc8445247f00f58a58650af5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1181,6 +1181,7 @@ dependencies = [ "font-kit", "foreign-types", "gpui_macros", + "lazy_static", "log", "metal", "num_cpus", diff --git a/gpui/Cargo.toml b/gpui/Cargo.toml index 1eba8612bfa9c2474ca5a0e389bf0824cba6479f..0661ef903c14be8e040ecf0a55911e461c0272c4 100644 --- a/gpui/Cargo.toml +++ b/gpui/Cargo.toml @@ -9,6 +9,7 @@ async-task = "4.0.3" ctor = "0.1" etagere = "0.2" gpui_macros = {path = "../gpui_macros"} +lazy_static = "1.4" log = "0.4" num_cpus = "1.13" ordered-float = "2.1.1" diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 099bf2ec6c958e4bbe1aec4733ec99abf89b108c..a2f556e6deb12eeff41bc2ec219cb09865683315 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -10,6 +10,7 @@ use crate::{ use anyhow::{anyhow, Result}; use async_task::Task; use keymap::MatchResult; +use lazy_static::lazy_static; use parking_lot::{Mutex, RwLock}; use pathfinder_geometry::{rect::RectF, vector::vec2f}; use platform::Event; @@ -2290,17 +2291,12 @@ impl ViewHandle { pub fn condition( &self, ctx: &TestAppContext, - predicate: impl FnMut(&T, &AppContext) -> bool, - ) -> impl Future { - self.condition_with_duration(Duration::from_millis(500), ctx, predicate) - } - - pub fn condition_with_duration( - &self, - duration: Duration, - ctx: &TestAppContext, mut predicate: impl FnMut(&T, &AppContext) -> bool, ) -> impl Future { + lazy_static! { + static ref CI: bool = std::env::var("CI").is_ok(); + } + let (tx, mut rx) = mpsc::channel(1024); let mut ctx = ctx.0.borrow_mut(); @@ -2322,6 +2318,11 @@ impl ViewHandle { let ctx = ctx.weak_self.as_ref().unwrap().upgrade().unwrap(); let handle = self.downgrade(); + let duration = if *CI { + Duration::from_secs(1) + } else { + Duration::from_millis(500) + }; async move { timeout(duration, async move { diff --git a/zed/src/workspace.rs b/zed/src/workspace.rs index 833a74d112dc18d328f8a8ca8310cd3b79477d23..328ebf30e8413f637f7f486f52dca51e0ca5191a 100644 --- a/zed/src/workspace.rs +++ b/zed/src/workspace.rs @@ -759,7 +759,7 @@ mod tests { use super::*; use crate::{editor::BufferView, settings, test::temp_tree}; use serde_json::json; - use std::{collections::HashSet, fs, time::Duration}; + use std::{collections::HashSet, fs}; use tempdir::TempDir; #[gpui::test] @@ -1031,18 +1031,14 @@ mod tests { app.update(|ctx| editor.update(ctx, |editor, ctx| editor.insert(&"x".to_string(), ctx))); fs::write(dir.path().join("a.txt"), "changed").unwrap(); editor - .condition_with_duration(Duration::from_millis(500), &app, |editor, ctx| { - editor.has_conflict(ctx) - }) + .condition(&app, |editor, ctx| editor.has_conflict(ctx)) .await; app.read(|ctx| assert!(editor.is_dirty(ctx))); app.update(|ctx| workspace.update(ctx, |w, ctx| w.save_active_item(&(), ctx))); app.simulate_prompt_answer(window_id, 0); editor - .condition_with_duration(Duration::from_millis(500), &app, |editor, ctx| { - !editor.is_dirty(ctx) - }) + .condition(&app, |editor, ctx| !editor.is_dirty(ctx)) .await; app.read(|ctx| assert!(!editor.has_conflict(ctx))); } @@ -1099,9 +1095,7 @@ mod tests { // When the save completes, the buffer's title is updated. editor - .condition_with_duration(Duration::from_millis(500), &app, |editor, ctx| { - !editor.is_dirty(ctx) - }) + .condition(&app, |editor, ctx| !editor.is_dirty(ctx)) .await; app.read(|ctx| { assert!(!editor.is_dirty(ctx));