Remove condition_with_duration for ModelHandle

Also, use a 2s timeout on CI for both `ModelHandle::condition` and
`ViewHandle::condition`.
This commit is contained in:
Antonio Scandurra
2021-05-19 14:50:28 +02:00
parent 830fc38503
commit 65cf9b7c1d
5 changed files with 15 additions and 38 deletions
Generated
-1
View File
@@ -1181,7 +1181,6 @@ dependencies = [
"font-kit",
"foreign-types",
"gpui_macros",
"lazy_static",
"log",
"metal",
"num_cpus",
-1
View File
@@ -9,7 +9,6 @@ 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"
+7 -16
View File
@@ -10,7 +10,6 @@ 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;
@@ -2083,15 +2082,6 @@ impl<T: Entity> ModelHandle<T> {
pub fn condition(
&self,
ctx: &TestAppContext,
predicate: impl FnMut(&T, &AppContext) -> bool,
) -> impl Future<Output = ()> {
self.condition_with_duration(Duration::from_millis(100), ctx, predicate)
}
pub fn condition_with_duration(
&self,
duration: Duration,
ctx: &TestAppContext,
mut predicate: impl FnMut(&T, &AppContext) -> bool,
) -> impl Future<Output = ()> {
let (tx, mut rx) = mpsc::channel(1024);
@@ -2114,6 +2104,11 @@ impl<T: Entity> ModelHandle<T> {
let ctx = ctx.weak_self.as_ref().unwrap().upgrade().unwrap();
let handle = self.downgrade();
let duration = if std::env::var("CI").is_ok() {
Duration::from_secs(2)
} else {
Duration::from_millis(500)
};
async move {
timeout(duration, async move {
@@ -2293,10 +2288,6 @@ impl<T: View> ViewHandle<T> {
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();
@@ -2318,8 +2309,8 @@ 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)
let duration = if std::env::var("CI").is_ok() {
Duration::from_secs(2)
} else {
Duration::from_millis(500)
};
+4 -12
View File
@@ -3011,9 +3011,7 @@ mod tests {
});
fs::remove_file(dir.path().join("file2")).unwrap();
buffer2
.condition_with_duration(Duration::from_millis(500), &app, |b, _| b.is_dirty())
.await;
buffer2.condition(&app, |b, _| b.is_dirty()).await;
assert_eq!(
*events.borrow(),
&[Event::Dirtied, Event::FileHandleChanged]
@@ -3038,9 +3036,7 @@ mod tests {
events.borrow_mut().clear();
fs::remove_file(dir.path().join("file3")).unwrap();
buffer3
.condition_with_duration(Duration::from_millis(500), &app, |_, _| {
!events.borrow().is_empty()
})
.condition(&app, |_, _| !events.borrow().is_empty())
.await;
assert_eq!(*events.borrow(), &[Event::FileHandleChanged]);
app.read(|ctx| assert!(buffer3.read(ctx).is_dirty()));
@@ -3095,9 +3091,7 @@ mod tests {
// contents are edited according to the diff between the old and new
// file contents.
buffer
.condition_with_duration(Duration::from_millis(500), &app, |buffer, _| {
buffer.text() != initial_contents
})
.condition(&app, |buffer, _| buffer.text() != initial_contents)
.await;
buffer.update(&mut app, |buffer, _| {
@@ -3131,9 +3125,7 @@ mod tests {
// Becaues the buffer is modified, it doesn't reload from disk, but is
// marked as having a conflict.
buffer
.condition_with_duration(Duration::from_millis(500), &app, |buffer, _| {
buffer.has_conflict()
})
.condition(&app, |buffer, _| buffer.has_conflict())
.await;
}
+4 -8
View File
@@ -1276,16 +1276,12 @@ impl WorktreeHandle for ModelHandle<Worktree> {
let tree = self.clone();
async move {
fs::write(root_path.join(filename), "").unwrap();
tree.condition_with_duration(Duration::from_secs(5), &app, |tree, _| {
tree.entry_for_path(filename).is_some()
})
.await;
tree.condition(&app, |tree, _| tree.entry_for_path(filename).is_some())
.await;
fs::remove_file(root_path.join(filename)).unwrap();
tree.condition_with_duration(Duration::from_secs(5), &app, |tree, _| {
tree.entry_for_path(filename).is_none()
})
.await;
tree.condition(&app, |tree, _| tree.entry_for_path(filename).is_none())
.await;
app.read(|ctx| tree.read(ctx).scan_complete()).await;
}