1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

Clean up 'inspector_break_on_first_line' test and fix its flakiness (#5098)

This commit is contained in:
Bert Belder 2020-05-06 03:50:55 +02:00
parent 2ecdbb62ae
commit e513751ee9
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
2 changed files with 13 additions and 16 deletions

View file

@ -1 +1,4 @@
console.log("hello from the script"); console.log("hello from the script");
// This process will be killed before the timeout is over.
await new Promise((res, _) => setTimeout(res, 1000));

View file

@ -2201,10 +2201,16 @@ async fn inspector_break_on_first_line() {
.expect("Can't connect"); .expect("Can't connect");
assert_eq!(response.status(), 101); // Switching protocols. assert_eq!(response.status(), 101); // Switching protocols.
let (mut socket_tx, mut socket_rx) = socket.split(); let (mut socket_tx, socket_rx) = socket.split();
let mut socket_rx =
socket_rx.map(|msg| msg.unwrap().to_string()).filter(|msg| {
let pass = !msg.starts_with(r#"{"method":"Debugger.scriptParsed","#);
futures::future::ready(pass)
});
let stdout = child.stdout.as_mut().unwrap(); let stdout = child.stdout.as_mut().unwrap();
let mut stdout_lines = std::io::BufReader::new(stdout).lines(); let mut stdout_lines =
std::io::BufReader::new(stdout).lines().map(|r| r.unwrap());
use TestStep::*; use TestStep::*;
let test_steps = vec![ let test_steps = vec![
@ -2230,20 +2236,8 @@ async fn inspector_break_on_first_line() {
for step in test_steps { for step in test_steps {
match step { match step {
StdOut(s) => match stdout_lines.next() { StdOut(s) => assert_eq!(&stdout_lines.next().unwrap(), s),
Some(Ok(line)) => assert_eq!(line, s), WsRecv(s) => assert!(socket_rx.next().await.unwrap().starts_with(s)),
other => panic!(other),
},
WsRecv(s) => loop {
let msg = match socket_rx.next().await {
Some(Ok(msg)) => msg.to_string(),
other => panic!(other),
};
if !msg.starts_with(r#"{"method":"Debugger.scriptParsed","#) {
assert!(msg.starts_with(s));
break;
}
},
WsSend(s) => socket_tx.send(s.into()).await.unwrap(), WsSend(s) => socket_tx.send(s.into()).await.unwrap(),
} }
} }