Skip to content

Commit

Permalink
De-flake test
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkassimo committed Feb 22, 2020
1 parent 60ffdd6 commit ec5e100
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
17 changes: 4 additions & 13 deletions cli/tests/integration_tests.rs
Expand Up @@ -18,25 +18,16 @@ pub fn test_raw_tty() {
if let Ok(mut master) = fork.is_parent() {
let mut obytes: [u8; 100] = [0; 100];
let mut nread = master.read(&mut obytes).unwrap();
assert_eq!(String::from_utf8_lossy(&obytes[0..nread]), "BEGIN\r\n");
assert_eq!(String::from_utf8_lossy(&obytes[0..nread]), "S");
master.write_all(b"a").unwrap();
nread = master.read(&mut obytes).unwrap();
assert_eq!(
String::from_utf8_lossy(&obytes[0..nread]),
"READ 1 byte: a\r\n"
);
assert_eq!(String::from_utf8_lossy(&obytes[0..nread]), "A");
master.write_all(b"b").unwrap();
nread = master.read(&mut obytes).unwrap();
assert_eq!(
String::from_utf8_lossy(&obytes[0..nread]),
"READ 1 byte: b\r\n"
);
assert_eq!(String::from_utf8_lossy(&obytes[0..nread]), "B");
master.write_all(b"c").unwrap();
nread = master.read(&mut obytes).unwrap();
assert_eq!(
String::from_utf8_lossy(&obytes[0..nread]),
"READ 1 byte: c\r\n"
);
assert_eq!(String::from_utf8_lossy(&obytes[0..nread]), "C");
} else {
use deno::test_util::*;
use nix::sys::termios;
Expand Down
10 changes: 4 additions & 6 deletions cli/tests/raw_mode.ts
@@ -1,20 +1,18 @@
Deno.setRaw(0, true);
Deno.setRaw(0, true); // Can be called multiple times

console.log("BEGIN");
Deno.stdout.writeSync(new TextEncoder().encode("S"));

const buf = new Uint8Array(3);
for (let i = 0; i < 3; i++) {
const nread = await Deno.stdin.read(buf);
if (nread === Deno.EOF) {
break;
} else {
console.log(
`READ ${nread} byte:`,
new TextDecoder().decode(buf.subarray(0, nread))
);
const data = new TextDecoder().decode(buf.subarray(0, nread));
Deno.stdout.writeSync(new TextEncoder().encode(data.toUpperCase()));
}
}

Deno.setRaw(0, false); // restores old mode.
Deno.setRaw(0, false); // restores old mode. Can be safely called multiple times
Deno.setRaw(0, false); // Can be safely called multiple times

0 comments on commit ec5e100

Please sign in to comment.