diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-28 13:01:29 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-28 13:01:29 +0000 |
commit | 7e4cd6b4e4c67b36ad2091e565aa2a6ee4d9b4f6 (patch) | |
tree | 2932c3b69d1e86c10be7a7ec7e3766755014c545 /crates | |
parent | ce2f0bdac726a34627d5cf14362e7bf14f868d09 (diff) | |
parent | a58fa29dc201f82891f11acb347e363f7cfcbd4e (diff) |
Merge #7472
7472: Easier to debug timeouts in tests r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/tests/rust-analyzer/support.rs | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/crates/rust-analyzer/tests/rust-analyzer/support.rs b/crates/rust-analyzer/tests/rust-analyzer/support.rs index 2658ee185..f59958e8d 100644 --- a/crates/rust-analyzer/tests/rust-analyzer/support.rs +++ b/crates/rust-analyzer/tests/rust-analyzer/support.rs | |||
@@ -188,8 +188,8 @@ impl Server { | |||
188 | } | 188 | } |
189 | fn send_request_(&self, r: Request) -> Value { | 189 | fn send_request_(&self, r: Request) -> Value { |
190 | let id = r.id.clone(); | 190 | let id = r.id.clone(); |
191 | self.client.sender.send(r.into()).unwrap(); | 191 | self.client.sender.send(r.clone().into()).unwrap(); |
192 | while let Some(msg) = self.recv() { | 192 | while let Some(msg) = self.recv().unwrap_or_else(|Timeout| panic!("timeout: {:?}", r)) { |
193 | match msg { | 193 | match msg { |
194 | Message::Request(req) => { | 194 | Message::Request(req) => { |
195 | if req.method == "window/workDoneProgress/create" { | 195 | if req.method == "window/workDoneProgress/create" { |
@@ -216,7 +216,7 @@ impl Server { | |||
216 | } | 216 | } |
217 | } | 217 | } |
218 | } | 218 | } |
219 | panic!("no response"); | 219 | panic!("no response for {:?}", r); |
220 | } | 220 | } |
221 | pub(crate) fn wait_until_workspace_is_loaded(self) -> Server { | 221 | pub(crate) fn wait_until_workspace_is_loaded(self) -> Server { |
222 | self.wait_for_message_cond(1, &|msg: &Message| match msg { | 222 | self.wait_for_message_cond(1, &|msg: &Message| match msg { |
@@ -230,10 +230,15 @@ impl Server { | |||
230 | } | 230 | } |
231 | } | 231 | } |
232 | _ => false, | 232 | _ => false, |
233 | }); | 233 | }) |
234 | .unwrap_or_else(|Timeout| panic!("timeout while waiting for ws to load")); | ||
234 | self | 235 | self |
235 | } | 236 | } |
236 | fn wait_for_message_cond(&self, n: usize, cond: &dyn Fn(&Message) -> bool) { | 237 | fn wait_for_message_cond( |
238 | &self, | ||
239 | n: usize, | ||
240 | cond: &dyn Fn(&Message) -> bool, | ||
241 | ) -> Result<(), Timeout> { | ||
237 | let mut total = 0; | 242 | let mut total = 0; |
238 | for msg in self.messages.borrow().iter() { | 243 | for msg in self.messages.borrow().iter() { |
239 | if cond(msg) { | 244 | if cond(msg) { |
@@ -241,17 +246,20 @@ impl Server { | |||
241 | } | 246 | } |
242 | } | 247 | } |
243 | while total < n { | 248 | while total < n { |
244 | let msg = self.recv().expect("no response"); | 249 | let msg = self.recv()?.expect("no response"); |
245 | if cond(&msg) { | 250 | if cond(&msg) { |
246 | total += 1; | 251 | total += 1; |
247 | } | 252 | } |
248 | } | 253 | } |
254 | Ok(()) | ||
249 | } | 255 | } |
250 | fn recv(&self) -> Option<Message> { | 256 | fn recv(&self) -> Result<Option<Message>, Timeout> { |
251 | recv_timeout(&self.client.receiver).map(|msg| { | 257 | let msg = recv_timeout(&self.client.receiver)?; |
258 | let msg = msg.map(|msg| { | ||
252 | self.messages.borrow_mut().push(msg.clone()); | 259 | self.messages.borrow_mut().push(msg.clone()); |
253 | msg | 260 | msg |
254 | }) | 261 | }); |
262 | Ok(msg) | ||
255 | } | 263 | } |
256 | fn send_notification(&self, not: Notification) { | 264 | fn send_notification(&self, not: Notification) { |
257 | self.client.sender.send(Message::Notification(not)).unwrap(); | 265 | self.client.sender.send(Message::Notification(not)).unwrap(); |
@@ -269,11 +277,13 @@ impl Drop for Server { | |||
269 | } | 277 | } |
270 | } | 278 | } |
271 | 279 | ||
272 | fn recv_timeout(receiver: &Receiver<Message>) -> Option<Message> { | 280 | struct Timeout; |
281 | |||
282 | fn recv_timeout(receiver: &Receiver<Message>) -> Result<Option<Message>, Timeout> { | ||
273 | let timeout = | 283 | let timeout = |
274 | if cfg!(target_os = "macos") { Duration::from_secs(300) } else { Duration::from_secs(120) }; | 284 | if cfg!(target_os = "macos") { Duration::from_secs(300) } else { Duration::from_secs(120) }; |
275 | select! { | 285 | select! { |
276 | recv(receiver) -> msg => msg.ok(), | 286 | recv(receiver) -> msg => Ok(msg.ok()), |
277 | recv(after(timeout)) -> _ => panic!("timed out"), | 287 | recv(after(timeout)) -> _ => Err(Timeout), |
278 | } | 288 | } |
279 | } | 289 | } |