Skip to content

Commit

Permalink
flip stderr and stdout writes to ensure streamFlushMillis is doing it…
Browse files Browse the repository at this point in the history
…s job
  • Loading branch information
mceachen committed Feb 27, 2022
1 parent e4fed9d commit 4879a5f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import { Mutex } from "./Mutex"

const newline = process.env.newline === "crlf" ? "\r\n" : "\n"

function write(s: string): boolean {
return process.stdout.write(s + newline)
async function write(s: string) {
return new Promise<void>((res, rej) =>
process.stdout.write(s + newline, (err) => (err == null ? res() : rej(err)))
)
}

const ignoreExit = process.env.ignoreExit === "1"
Expand Down Expand Up @@ -43,11 +45,7 @@ async function onLine(line: string): Promise<void> {
// write(`# ${_p.pid} onLine(${line.trim()}) (newline = ${process.env.newline})`)
const r = rng()
if (r < failrate) {
if (process.env.unluckyfail === "1") {
// Make sure streams get debounced:
write("FAIL")
await delay(1)
}
// stderr isn't buffered, so this should be flushed immediately:
console.error(
"EUNLUCKY: r: " +
r.toFixed(2) +
Expand All @@ -56,7 +54,11 @@ async function onLine(line: string): Promise<void> {
", seed: " +
process.env.rngseed
)

if (process.env.unluckyfail === "1") {
// Wait for a bit to ensure streams get merged thanks to streamFlushMillis:
await delay(5)
await write("FAIL")
}
return
}
line = line.trim()
Expand Down

0 comments on commit 4879a5f

Please sign in to comment.