test-logger: Avoid a race condition that would make the test fail
Previously, we could have this sequence of events:
-
env
subprocess starts - Test writes
hello, world\n
to its stdin. Nothing is reading yet, but this string is smaller than the pipe buffer, so the write does not block. -
srt-logger
parent process opens log file -
srt-logger
parent process forks child process to handle logging -
srt-logger
parent process execscat
-
cat
readshello, world\n
, writes it to its stdout, and exits - Test waits for
cat
to exit - Test runs
tests/adverb --exclusive-lock
which locks the log file -
srt-logger
child process tries to lock log file, but cannot, so it waits - Test continues, reads empty content from log file, and fails
-
srt-logger
child process acquires lock and writes out content
By waiting for stdout to close before step 8, we can ensure that the equivalent of step 11 has already happened before step 8, so that by the time step 8 finishes, the log file already has its intended content.
Resolves: #128 (closed)
Edited by Simon McVittie