mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
ci: attempt to make repl tests less flaky at startup on the CI (#21291)
This is an attempt to fix this flakiness: ``` ---- integration::repl::assign_underscore stdout ---- deno_exe path /home/runner/work/deno/deno/target/release/deno command /home/runner/work/deno/deno/target/release/deno repl command cwd /tmp/deno-cli-testK3YASC ------ Start Full Text ------ "" ------- End Full Text ------- Next text: "" thread 'integration::repl::assign_underscore' panicked at test_util/src/pty.rs:41:11: Timed out. stack backtrace: ```
This commit is contained in:
parent
32025dca5c
commit
e3e51313f6
1 changed files with 43 additions and 11 deletions
|
@ -38,8 +38,17 @@ impl Pty {
|
||||||
};
|
};
|
||||||
if args.is_empty() || args[0] == "repl" && !args.contains(&"--quiet") {
|
if args.is_empty() || args[0] == "repl" && !args.contains(&"--quiet") {
|
||||||
// wait for the repl to start up before writing to it
|
// wait for the repl to start up before writing to it
|
||||||
pty.expect("exit using ctrl+d, ctrl+c, or close()");
|
pty.read_until_condition_with_timeout(
|
||||||
|
|pty| {
|
||||||
|
pty
|
||||||
|
.all_output()
|
||||||
|
.contains("exit using ctrl+d, ctrl+c, or close()")
|
||||||
|
},
|
||||||
|
// it sometimes takes a while to startup on the CI, so use a longer timeout
|
||||||
|
Duration::from_secs(30),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pty
|
pty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,16 +185,35 @@ impl Pty {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn read_until_condition(
|
fn read_until_condition(&mut self, condition: impl FnMut(&mut Self) -> bool) {
|
||||||
|
self.read_until_condition_with_timeout(condition, Duration::from_secs(15));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
fn read_until_condition_with_timeout(
|
||||||
|
&mut self,
|
||||||
|
condition: impl FnMut(&mut Self) -> bool,
|
||||||
|
timeout_duration: Duration,
|
||||||
|
) {
|
||||||
|
if self.try_read_until_condition_with_timeout(condition, timeout_duration) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
panic!("Timed out.")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reads until the specified condition with a timeout duration returning
|
||||||
|
/// `true` on success or `false` on timeout.
|
||||||
|
fn try_read_until_condition_with_timeout(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut condition: impl FnMut(&mut Self) -> bool,
|
mut condition: impl FnMut(&mut Self) -> bool,
|
||||||
) {
|
timeout_duration: Duration,
|
||||||
let timeout_time =
|
) -> bool {
|
||||||
Instant::now().checked_add(Duration::from_secs(15)).unwrap();
|
let timeout_time = Instant::now().checked_add(timeout_duration).unwrap();
|
||||||
while Instant::now() < timeout_time {
|
while Instant::now() < timeout_time {
|
||||||
self.fill_more_bytes();
|
self.fill_more_bytes();
|
||||||
if condition(self) {
|
if condition(self) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +223,8 @@ impl Pty {
|
||||||
String::from_utf8_lossy(&self.read_bytes)
|
String::from_utf8_lossy(&self.read_bytes)
|
||||||
);
|
);
|
||||||
eprintln!("Next text: {:?}", text);
|
eprintln!("Next text: {:?}", text);
|
||||||
panic!("Timed out.")
|
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_text(&self) -> String {
|
fn next_text(&self) -> String {
|
||||||
|
@ -206,10 +235,13 @@ impl Pty {
|
||||||
|
|
||||||
fn fill_more_bytes(&mut self) {
|
fn fill_more_bytes(&mut self) {
|
||||||
let mut buf = [0; 256];
|
let mut buf = [0; 256];
|
||||||
if let Ok(count) = self.pty.read(&mut buf) {
|
match self.pty.read(&mut buf) {
|
||||||
|
Ok(count) if count > 0 => {
|
||||||
self.read_bytes.extend(&buf[..count]);
|
self.read_bytes.extend(&buf[..count]);
|
||||||
} else {
|
}
|
||||||
std::thread::sleep(Duration::from_millis(10));
|
_ => {
|
||||||
|
std::thread::sleep(Duration::from_millis(15));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue