fix rejoin after quit (#10100)
Release Notes: - collab: Fixed rejoining channels quickly after a restart
This commit is contained in:
parent
8958c9e10f
commit
fe7b12c444
9 changed files with 124 additions and 49 deletions
|
@ -219,11 +219,17 @@ impl BackgroundExecutor {
|
|||
if let Some(test) = self.dispatcher.as_test() {
|
||||
if !test.parking_allowed() {
|
||||
let mut backtrace_message = String::new();
|
||||
let mut waiting_message = String::new();
|
||||
if let Some(backtrace) = test.waiting_backtrace() {
|
||||
backtrace_message =
|
||||
format!("\nbacktrace of waiting future:\n{:?}", backtrace);
|
||||
}
|
||||
panic!("parked with nothing left to run\n{:?}", backtrace_message)
|
||||
if let Some(waiting_hint) = test.waiting_hint() {
|
||||
waiting_message = format!("\n waiting on: {}\n", waiting_hint);
|
||||
}
|
||||
panic!(
|
||||
"parked with nothing left to run{waiting_message}{backtrace_message}",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,6 +360,12 @@ impl BackgroundExecutor {
|
|||
self.dispatcher.as_test().unwrap().forbid_parking();
|
||||
}
|
||||
|
||||
/// adds detail to the "parked with nothing let to run" message.
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn set_waiting_hint(&self, msg: Option<String>) {
|
||||
self.dispatcher.as_test().unwrap().set_waiting_hint(msg);
|
||||
}
|
||||
|
||||
/// in tests, returns the rng used by the dispatcher and seeded by the `SEED` environment variable
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn rng(&self) -> StdRng {
|
||||
|
|
|
@ -36,6 +36,7 @@ struct TestDispatcherState {
|
|||
is_main_thread: bool,
|
||||
next_id: TestDispatcherId,
|
||||
allow_parking: bool,
|
||||
waiting_hint: Option<String>,
|
||||
waiting_backtrace: Option<Backtrace>,
|
||||
deprioritized_task_labels: HashSet<TaskLabel>,
|
||||
block_on_ticks: RangeInclusive<usize>,
|
||||
|
@ -54,6 +55,7 @@ impl TestDispatcher {
|
|||
is_main_thread: true,
|
||||
next_id: TestDispatcherId(1),
|
||||
allow_parking: false,
|
||||
waiting_hint: None,
|
||||
waiting_backtrace: None,
|
||||
deprioritized_task_labels: Default::default(),
|
||||
block_on_ticks: 0..=1000,
|
||||
|
@ -132,6 +134,14 @@ impl TestDispatcher {
|
|||
self.state.lock().allow_parking = false
|
||||
}
|
||||
|
||||
pub fn set_waiting_hint(&self, msg: Option<String>) {
|
||||
self.state.lock().waiting_hint = msg
|
||||
}
|
||||
|
||||
pub fn waiting_hint(&self) -> Option<String> {
|
||||
self.state.lock().waiting_hint.clone()
|
||||
}
|
||||
|
||||
pub fn start_waiting(&self) {
|
||||
self.state.lock().waiting_backtrace = Some(Backtrace::new_unresolved());
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ impl TestPlatform {
|
|||
.multiple_choice
|
||||
.pop_front()
|
||||
.expect("no pending multiple choice prompt");
|
||||
self.background_executor().set_waiting_hint(None);
|
||||
tx.send(response_ix).ok();
|
||||
}
|
||||
|
||||
|
@ -76,8 +77,10 @@ impl TestPlatform {
|
|||
!self.prompts.borrow().multiple_choice.is_empty()
|
||||
}
|
||||
|
||||
pub(crate) fn prompt(&self) -> oneshot::Receiver<usize> {
|
||||
pub(crate) fn prompt(&self, msg: &str, detail: Option<&str>) -> oneshot::Receiver<usize> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
self.background_executor()
|
||||
.set_waiting_hint(Some(format!("PROMPT: {:?} {:?}", msg, detail)));
|
||||
self.prompts.borrow_mut().multiple_choice.push_back(tx);
|
||||
rx
|
||||
}
|
||||
|
|
|
@ -159,8 +159,8 @@ impl PlatformWindow for TestWindow {
|
|||
fn prompt(
|
||||
&self,
|
||||
_level: crate::PromptLevel,
|
||||
_msg: &str,
|
||||
_detail: Option<&str>,
|
||||
msg: &str,
|
||||
detail: Option<&str>,
|
||||
_answers: &[&str],
|
||||
) -> Option<futures::channel::oneshot::Receiver<usize>> {
|
||||
Some(
|
||||
|
@ -169,7 +169,7 @@ impl PlatformWindow for TestWindow {
|
|||
.platform
|
||||
.upgrade()
|
||||
.expect("platform dropped")
|
||||
.prompt(),
|
||||
.prompt(msg, detail),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue