Skip to content

Commit 6714143

Browse files
claudesinelaw
authored andcommitted
fix(test): use wait_until for async hook dispatch in init_script tests
The plugins_loaded and ready hook tests were racing: fire_hook sends to the plugin thread asynchronously, but a single process_async_messages call may return before the plugin thread finishes executing the handler and sends the SetStatus command back. Switch to wait_until (poll with real sleeps + tick_and_render) which is the established pattern for waiting on async plugin results in the e2e test suite.
1 parent 54c0f27 commit 6714143

1 file changed

Lines changed: 19 additions & 23 deletions

File tree

crates/fresh-editor/tests/e2e/plugins/init_script.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ fn set_setting_updates_effective_config() {
116116
fn editor_on_accepts_a_closure_and_plugins_loaded_fires() {
117117
let (mut harness, _tmp, config_dir) = harness_with_scratch_config_dir();
118118

119-
// init.ts uses the closure form of `editor.on` — this is the DX win
120-
// of M2. The callback sets a status message we can observe.
121119
write_init_ts(
122120
&config_dir,
123121
r#"
@@ -130,18 +128,18 @@ fn editor_on_accepts_a_closure_and_plugins_loaded_fires() {
130128

131129
harness.editor_mut().load_init_script(true);
132130
harness.editor_mut().fire_plugins_loaded_hook();
133-
// Hook dispatch is async; drain it.
134-
harness.editor_mut().process_async_messages();
135131

136-
let status = harness
137-
.editor()
138-
.get_status_message()
139-
.cloned()
140-
.unwrap_or_default();
141-
assert!(
142-
status.contains("plugins_loaded fired"),
143-
"expected plugins_loaded closure to fire: status = {status:?}"
144-
);
132+
// Hook dispatch is async (plugin thread) — poll until the SetStatus
133+
// command arrives rather than hoping a single process_async_messages
134+
// is enough.
135+
harness
136+
.wait_until(|h| {
137+
h.editor()
138+
.get_status_message()
139+
.map(|s| s.contains("plugins_loaded fired"))
140+
.unwrap_or(false)
141+
})
142+
.unwrap();
145143
}
146144

147145
#[test]
@@ -237,17 +235,15 @@ fn ready_hook_fires_and_can_be_observed_with_legacy_on_form() {
237235

238236
harness.editor_mut().load_init_script(true);
239237
harness.editor_mut().fire_ready_hook();
240-
harness.editor_mut().process_async_messages();
241238

242-
let status = harness
243-
.editor()
244-
.get_status_message()
245-
.cloned()
246-
.unwrap_or_default();
247-
assert!(
248-
status.contains("ready fired"),
249-
"expected ready hook to fire with string-handler form: status = {status:?}"
250-
);
239+
harness
240+
.wait_until(|h| {
241+
h.editor()
242+
.get_status_message()
243+
.map(|s| s.contains("ready fired"))
244+
.unwrap_or(false)
245+
})
246+
.unwrap();
251247
}
252248

253249
#[test]

0 commit comments

Comments
 (0)