test: cover initial layout cancellation and retained replacement owners
Verify Tessera GUI / verify (push) Failing after 9m18s
Verify Tessera GUI / verify (push) Failing after 9m18s
This commit is contained in:
+96
-21
@@ -128,9 +128,10 @@ fn start_server_observed(
|
||||
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => break,
|
||||
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => {
|
||||
if worker.repl.as_ref().is_some_and(|(epoch, runtime)| {
|
||||
worker_namespace
|
||||
.read()
|
||||
.is_ok_and(|current| current.submission != *epoch && current.runtime_session != runtime.id)
|
||||
worker_namespace.read().is_ok_and(|current| {
|
||||
current.submission != *epoch
|
||||
&& current.runtime_session != runtime.id
|
||||
})
|
||||
}) {
|
||||
worker.repl = None;
|
||||
}
|
||||
@@ -454,11 +455,13 @@ type HttpResponse = Response<std::io::Cursor<Vec<u8>>>;
|
||||
type InputOutcome =
|
||||
std::thread::Result<Result<(endor_host::ReplResult, Vec<crate::window::Command>)>>;
|
||||
|
||||
type CandidateOutcome = std::thread::Result<Result<(
|
||||
endor_host::ReplSession,
|
||||
crate::document::RenderDocument,
|
||||
Vec<crate::window::Command>,
|
||||
)>>;
|
||||
type CandidateOutcome = std::thread::Result<
|
||||
Result<(
|
||||
endor_host::ReplSession,
|
||||
crate::document::RenderDocument,
|
||||
Vec<crate::window::Command>,
|
||||
)>,
|
||||
>;
|
||||
|
||||
struct PendingInput {
|
||||
epoch: u64,
|
||||
@@ -946,7 +949,9 @@ impl Worker {
|
||||
) -> RequestProgress {
|
||||
match pending {
|
||||
PendingRequest::Input(input) => self.resume_input(job, input, namespace, notify),
|
||||
PendingRequest::Candidate(runtime) => self.resume_candidate(job, runtime, namespace, notify),
|
||||
PendingRequest::Candidate(runtime) => {
|
||||
self.resume_candidate(job, runtime, namespace, notify)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1133,24 +1138,40 @@ impl Worker {
|
||||
self.preserve_live_owner(¤t);
|
||||
return RequestProgress::Complete(superseded(job.submission));
|
||||
}
|
||||
Err(_) => return RequestProgress::Complete(error_response(StatusCode(500), "namespace lock poisoned")),
|
||||
Err(_) => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"namespace lock poisoned",
|
||||
));
|
||||
}
|
||||
};
|
||||
self.next_session = match self.next_session.checked_add(1) {
|
||||
Some(id) => id,
|
||||
None => return RequestProgress::Complete(error_response(StatusCode(500), "session identities exhausted")),
|
||||
None => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"session identities exhausted",
|
||||
));
|
||||
}
|
||||
};
|
||||
let id = self.next_session;
|
||||
let started = catch_unwind(AssertUnwindSafe(|| {
|
||||
endor_host::ReplSession::load_incremental(&job.source, &job.namespace, job.submission, id, viewport)
|
||||
endor_host::ReplSession::load_incremental(
|
||||
&job.source,
|
||||
&job.namespace,
|
||||
job.submission,
|
||||
id,
|
||||
viewport,
|
||||
)
|
||||
}));
|
||||
let result = match started {
|
||||
Ok(Ok((runtime, None))) => return RequestProgress::Pending(PendingRequest::Candidate(Box::new(runtime))),
|
||||
Ok(Ok((runtime, Some(document)))) => {
|
||||
match runtime.take_window_commands() {
|
||||
Ok(commands) => Ok(Ok((runtime, document, commands))),
|
||||
Err(error) => Ok(Err(error)),
|
||||
}
|
||||
Ok(Ok((runtime, None))) => {
|
||||
return RequestProgress::Pending(PendingRequest::Candidate(Box::new(runtime)));
|
||||
}
|
||||
Ok(Ok((runtime, Some(document)))) => match runtime.take_window_commands() {
|
||||
Ok(commands) => Ok(Ok((runtime, document, commands))),
|
||||
Err(error) => Ok(Err(error)),
|
||||
},
|
||||
Ok(Err(error)) => Ok(Err(error)),
|
||||
Err(panic) => Err(panic),
|
||||
};
|
||||
@@ -1168,13 +1189,22 @@ impl Worker {
|
||||
Ok(current) if current.submission == job.submission => {
|
||||
// Secondary native resources still belong to the old VM. Only
|
||||
// the primary shell's current viewport applies to a candidate.
|
||||
current.viewport.map(|size| (crate::window::MAIN_WINDOW, size)).into_iter().collect()
|
||||
current
|
||||
.viewport
|
||||
.map(|size| (crate::window::MAIN_WINDOW, size))
|
||||
.into_iter()
|
||||
.collect()
|
||||
}
|
||||
Ok(current) => {
|
||||
self.preserve_live_owner(¤t);
|
||||
return RequestProgress::Complete(superseded(job.submission));
|
||||
}
|
||||
Err(_) => return RequestProgress::Complete(error_response(StatusCode(500), "namespace lock poisoned")),
|
||||
Err(_) => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"namespace lock poisoned",
|
||||
));
|
||||
}
|
||||
};
|
||||
let id = runtime.id;
|
||||
let resumed = catch_unwind(AssertUnwindSafe(|| -> Result<_> {
|
||||
@@ -1182,7 +1212,8 @@ impl Worker {
|
||||
if runtime.has_pending_refresh() {
|
||||
return Ok(None);
|
||||
}
|
||||
let document = document.ok_or_else(|| anyhow::anyhow!("program did not publish a Page"))?;
|
||||
let document =
|
||||
document.ok_or_else(|| anyhow::anyhow!("program did not publish a Page"))?;
|
||||
Ok(Some((document, runtime.take_window_commands()?)))
|
||||
}));
|
||||
let result = match resumed {
|
||||
@@ -1891,6 +1922,50 @@ mod tests {
|
||||
assert_eq!(notifications.load(Ordering::SeqCst), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn queued_candidate_keeps_live_owner_until_delete_revokes_it() {
|
||||
let (runtime, document) = endor_host::ReplSession::load(
|
||||
"retained = ui.state(9)\npage = Page()\npage.render(ui.textOf(retained,\"value\"))",
|
||||
"app.main",
|
||||
1,
|
||||
277,
|
||||
)
|
||||
.unwrap();
|
||||
let namespace = Arc::new(RwLock::new(NamespaceState {
|
||||
document,
|
||||
submission: 2,
|
||||
runtime_session: runtime.id,
|
||||
..NamespaceState::default()
|
||||
}));
|
||||
let mut worker = Worker {
|
||||
repl: Some((1, runtime)),
|
||||
next_session: 277,
|
||||
};
|
||||
let notify: Notify = Arc::new(|| {});
|
||||
worker.refresh_viewport(&namespace, ¬ify);
|
||||
assert_eq!(worker.repl.as_ref().unwrap().0, 2);
|
||||
assert_eq!(
|
||||
worker
|
||||
.repl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.1
|
||||
.execute("retained.value", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"9"
|
||||
);
|
||||
{
|
||||
let mut current = namespace.write().unwrap();
|
||||
current.submission = 3;
|
||||
worker.preserve_live_owner(¤t);
|
||||
}
|
||||
assert_eq!(worker.repl.as_ref().unwrap().0, 3);
|
||||
namespace.write().unwrap().clear().unwrap();
|
||||
worker.refresh_viewport(&namespace, ¬ify);
|
||||
assert!(worker.repl.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_delete_remains_available_and_invalidates_queued_put() {
|
||||
use std::{
|
||||
|
||||
+63
-4
@@ -259,9 +259,12 @@ impl ReplSession {
|
||||
viewport: Option<crate::layout::Size>,
|
||||
) -> Result<(Self, RenderDocument)> {
|
||||
let mut runtime = Self::prepare_program(source, namespace, submission, id, viewport)?;
|
||||
let document = runtime.refresh_document()?
|
||||
let document = runtime
|
||||
.refresh_document()?
|
||||
.ok_or_else(|| anyhow::anyhow!("program did not publish a Page"))?;
|
||||
runtime.bridge.reclaim(&mut runtime.candidate.vm, &mut runtime.candidate.roots)?;
|
||||
runtime
|
||||
.bridge
|
||||
.reclaim(&mut runtime.candidate.vm, &mut runtime.candidate.roots)?;
|
||||
Ok((runtime, document))
|
||||
}
|
||||
|
||||
@@ -273,11 +276,16 @@ impl ReplSession {
|
||||
viewport: Option<crate::layout::Size>,
|
||||
) -> Result<(Self, Option<RenderDocument>)> {
|
||||
let mut runtime = Self::prepare_program(source, namespace, submission, id, viewport)?;
|
||||
let viewports = viewport.map(|size| (crate::window::MAIN_WINDOW, size)).into_iter().collect();
|
||||
let viewports = viewport
|
||||
.map(|size| (crate::window::MAIN_WINDOW, size))
|
||||
.into_iter()
|
||||
.collect();
|
||||
let document = runtime.refresh_after_mutation(Some(&viewports))?;
|
||||
if !runtime.has_pending_refresh() {
|
||||
anyhow::ensure!(document.is_some(), "program did not publish a Page");
|
||||
runtime.bridge.reclaim(&mut runtime.candidate.vm, &mut runtime.candidate.roots)?;
|
||||
runtime
|
||||
.bridge
|
||||
.reclaim(&mut runtime.candidate.vm, &mut runtime.candidate.roots)?;
|
||||
}
|
||||
Ok((runtime, document))
|
||||
}
|
||||
@@ -4262,6 +4270,57 @@ page.render(block)
|
||||
assert_eq!(source_measure_stat(&mut session, "layoutCancels"), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn candidate_initial_layout_retargets_without_reexecuting_program_or_hooks() {
|
||||
let children = std::iter::repeat_n("item", 80)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let source = format!(
|
||||
"class Watched: RectBlock {{\n count: Object\n function onMount(self: Watched, mount: Mount): Unit {{ self.count.increment() }}\n}}\nbuilt = ui.state(0)\nbuilt.increment()\nmounted = ui.state(0)\nitem = Watched(2,20,mounted)\npage = Page()\npage.render(Row(0,0,{children}))"
|
||||
);
|
||||
let (mut candidate, document) =
|
||||
ReplSession::load_incremental(&source, "app.main", 277, 1, None).unwrap();
|
||||
assert!(document.is_none());
|
||||
assert!(candidate.has_pending_refresh());
|
||||
assert!(candidate.documents.is_empty());
|
||||
let initial = std::collections::BTreeMap::new();
|
||||
for _ in 0..20 {
|
||||
candidate
|
||||
.resize_windows_incremental(&initial, false)
|
||||
.unwrap();
|
||||
if candidate.candidate.vm.has_suspended_call() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert!(candidate.candidate.vm.has_suspended_call());
|
||||
assert!(candidate.documents.is_empty());
|
||||
let latest = std::collections::BTreeMap::from([(
|
||||
crate::window::MAIN_WINDOW,
|
||||
crate::layout::Size {
|
||||
width: 900.0,
|
||||
height: 650.0,
|
||||
},
|
||||
)]);
|
||||
candidate
|
||||
.resize_windows_incremental(&latest, false)
|
||||
.unwrap();
|
||||
assert!(!candidate.candidate.vm.has_suspended_call());
|
||||
let settled = candidate.resize_windows(&latest).unwrap().unwrap();
|
||||
assert_eq!(settled.frame.mounts.last().unwrap().x, 158.0);
|
||||
assert_eq!(
|
||||
candidate.execute("built.value", "app.main").unwrap().value,
|
||||
"1"
|
||||
);
|
||||
assert_eq!(
|
||||
candidate
|
||||
.execute("mounted.value", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"80"
|
||||
);
|
||||
assert_eq!(source_measure_stat(&mut candidate, "layoutCancels"), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incremental_input_retains_value_and_never_replays_source_while_retargeting() {
|
||||
let children = std::iter::repeat_n("item", 80)
|
||||
|
||||
Reference in New Issue
Block a user