Own asynchronous timer tasks in the managed object lifecycle
Verify Tessera GUI / verify (push) Failing after 7m26s
Verify Tessera GUI / verify (push) Failing after 7m26s
This commit is contained in:
@@ -604,6 +604,37 @@ impl ReplSession {
|
||||
result
|
||||
}
|
||||
|
||||
/// Deliver ready work on the owning VM worker, never from the GUI or a
|
||||
/// provider thread. A failed callback stops the same shared fault domain.
|
||||
pub fn poll_tasks(&mut self) -> Result<Option<RenderDocument>> {
|
||||
if self.faulted {
|
||||
if self.bridge.cancel_tasks(&mut self.candidate.vm)? > 0 {
|
||||
self.bridge
|
||||
.reclaim(&mut self.candidate.vm, &mut self.candidate.roots)?;
|
||||
}
|
||||
return Ok(None);
|
||||
}
|
||||
let mut completed = false;
|
||||
let result = (|| {
|
||||
if self.bridge.poll_tasks(&mut self.candidate.vm)? == 0 {
|
||||
return Ok(None);
|
||||
}
|
||||
completed = true;
|
||||
self.refresh_document()
|
||||
})();
|
||||
if result.is_err() {
|
||||
self.faulted = true;
|
||||
self.bridge.cancel_tasks(&mut self.candidate.vm)?;
|
||||
self.take_window_commands()?;
|
||||
self.bridge.discard_pending(&mut self.candidate.vm)?;
|
||||
}
|
||||
if completed || result.is_err() {
|
||||
self.bridge
|
||||
.reclaim(&mut self.candidate.vm, &mut self.candidate.roots)?;
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
pub fn take_window_commands(&self) -> Result<Vec<crate::window::Command>> {
|
||||
self.bridge.take_window_commands(&self.candidate.vm)
|
||||
}
|
||||
@@ -955,6 +986,183 @@ mod tests {
|
||||
const EXAMPLE: &str = include_str!("../examples/hello.endor");
|
||||
const PAGE: &str = include_str!("../examples/page.endor");
|
||||
|
||||
#[test]
|
||||
fn owned_tasks_replace_cancel_and_update_unmounted_objects() {
|
||||
let source = r#"class Action {
|
||||
state: Object
|
||||
value: Number
|
||||
function apply(self: Action): Unit { self.state.value = self.value }
|
||||
}
|
||||
state = ui.state(0)
|
||||
hidden = TextBlock("not mounted")
|
||||
first = Action(state, 1)
|
||||
latest = Action(state, 2)
|
||||
page = Page()
|
||||
page.render(ui.textOf(state,"value"))
|
||||
old = ui.after(hidden,"load",0,first.apply)
|
||||
next = ui.after(hidden,"load",0,latest.apply)"#;
|
||||
let (mut session, _) = ReplSession::load(source, "app.main", 1, 190).unwrap();
|
||||
assert_eq!(
|
||||
session.execute("old.status()", "app.main").unwrap().value,
|
||||
"\"cancelled\""
|
||||
);
|
||||
assert_eq!(
|
||||
session.execute("state.value", "app.main").unwrap().value,
|
||||
"0"
|
||||
);
|
||||
assert!(session.poll_tasks().unwrap().is_some());
|
||||
assert_eq!(
|
||||
session.execute("state.value", "app.main").unwrap().value,
|
||||
"2"
|
||||
);
|
||||
assert_eq!(
|
||||
session.execute("next.status()", "app.main").unwrap().value,
|
||||
"\"completed\""
|
||||
);
|
||||
session
|
||||
.execute(
|
||||
"cancelled=ui.after(ui,\"cancel\",0,first.apply) cancelled.cancel()",
|
||||
"app.main",
|
||||
)
|
||||
.unwrap();
|
||||
session.poll_tasks().unwrap();
|
||||
assert_eq!(
|
||||
session.execute("state.value", "app.main").unwrap().value,
|
||||
"2"
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("cancelled.active()", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"false"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_and_mount_tasks_cancel_while_block_and_app_owners_continue() {
|
||||
let source = r#"class Action {
|
||||
state: Object
|
||||
function apply(self: Action): Unit { self.state.increment() }
|
||||
}
|
||||
state=ui.state(0)
|
||||
action=Action(state)
|
||||
leaf=TextBlock("owner")
|
||||
page=Page()
|
||||
page.render(leaf)"#;
|
||||
let (mut session, _) = ReplSession::load(source, "app.main", 1, 191).unwrap();
|
||||
session
|
||||
.execute(
|
||||
r#"held=leaf.mounts().at(0)
|
||||
pageTask=ui.after(page,"page",0,action.apply)
|
||||
mountTask=ui.after(held,"mount",0,action.apply)
|
||||
blockTask=ui.after(leaf,"block",0,action.apply)
|
||||
appTask=ui.after(ui,"app",0,action.apply)
|
||||
page.close()
|
||||
page.open()"#,
|
||||
"app.main",
|
||||
)
|
||||
.unwrap();
|
||||
for name in ["pageTask", "mountTask"] {
|
||||
assert_eq!(
|
||||
session
|
||||
.execute(&format!("{name}.status()"), "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"\"cancelled\""
|
||||
);
|
||||
}
|
||||
session.poll_tasks().unwrap();
|
||||
assert_eq!(
|
||||
session.execute("state.value", "app.main").unwrap().value,
|
||||
"2"
|
||||
);
|
||||
// Moving a Page preserves its scope; the replaced Mount is cancelled.
|
||||
session
|
||||
.execute(
|
||||
r#"moving=ui.after(page,"move",0,action.apply)
|
||||
oldMount=leaf.mounts().at(0)
|
||||
oldMountTask=ui.after(oldMount,"move",0,action.apply)
|
||||
other=page.detachToWindow()"#,
|
||||
"app.main",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("oldMountTask.status()", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"\"cancelled\""
|
||||
);
|
||||
session.poll_tasks().unwrap();
|
||||
assert_eq!(
|
||||
session.execute("state.value", "app.main").unwrap().value,
|
||||
"3"
|
||||
);
|
||||
session
|
||||
.execute(
|
||||
"closing=ui.after(other,\"close\",0,action.apply) other.close()",
|
||||
"app.main",
|
||||
)
|
||||
.unwrap();
|
||||
session.poll_tasks().unwrap();
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("closing.status()", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"\"cancelled\""
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn orphan_task_scope_is_collectable_and_callback_failure_stops_remaining_work() {
|
||||
let source = r#"class Action {
|
||||
state: Object
|
||||
function apply(self: Action): Unit { self.state.increment() }
|
||||
function fail(self: Action): Unit { ui.window().resize(0,600) }
|
||||
}
|
||||
function orphan(): Task {
|
||||
let owner=TextBlock("temporary")
|
||||
return ui.after(owner,"temporary",0,ui.window().focus)
|
||||
}
|
||||
state=ui.state(0)
|
||||
action=Action(state)
|
||||
page=Page()
|
||||
page.render(TextBlock("preserve"))
|
||||
token=orphan()"#;
|
||||
let (mut session, _) = ReplSession::load(source, "app.main", 1, 192).unwrap();
|
||||
assert_eq!(
|
||||
session.execute("token.active()", "app.main").unwrap().value,
|
||||
"false"
|
||||
);
|
||||
session.poll_tasks().unwrap();
|
||||
assert_eq!(
|
||||
session.execute("token.status()", "app.main").unwrap().value,
|
||||
"\"cancelled\""
|
||||
);
|
||||
session.execute("broken=ui.after(ui,\"fail\",0,action.fail) later=ui.after(ui,\"later\",0,action.apply)","app.main").unwrap();
|
||||
assert!(session.poll_tasks().is_err());
|
||||
assert!(session.is_faulted());
|
||||
let globals = session.candidate.globals.unwrap();
|
||||
let state = match session
|
||||
.candidate
|
||||
.vm
|
||||
.dict_get(globals, &Value::Text("state".into()))
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
{
|
||||
Value::Object(state) => state,
|
||||
_ => panic!("state object"),
|
||||
};
|
||||
assert_eq!(
|
||||
session.candidate.vm.get_attr(state, "value").unwrap(),
|
||||
Value::Number(0.into())
|
||||
);
|
||||
assert!(session.poll_tasks().unwrap().is_none());
|
||||
assert!(session.execute("42", "app.main").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_annotations_classify_functions_and_reject_before_body() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
|
||||
Reference in New Issue
Block a user