Cargo.lock 🔗
@@ -1181,6 +1181,7 @@ dependencies = [
"font-kit",
"foreign-types",
"gpui_macros",
+ "lazy_static",
"log",
"metal",
"num_cpus",
Antonio Scandurra created
`condition_with_duration` wasn't really being used, as the default
timeout was `500ms` and the only places that did use it specified
`500ms` as well.
Cargo.lock | 1 +
gpui/Cargo.toml | 1 +
gpui/src/app.rs | 19 ++++++++++---------
zed/src/workspace.rs | 14 ++++----------
4 files changed, 16 insertions(+), 19 deletions(-)
@@ -1181,6 +1181,7 @@ dependencies = [
"font-kit",
"foreign-types",
"gpui_macros",
+ "lazy_static",
"log",
"metal",
"num_cpus",
@@ -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"
@@ -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<T: View> ViewHandle<T> {
pub fn condition(
&self,
ctx: &TestAppContext,
- predicate: impl FnMut(&T, &AppContext) -> bool,
- ) -> impl Future<Output = ()> {
- 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<Output = ()> {
+ 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<T: View> ViewHandle<T> {
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 {
@@ -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));