Skip to content

test-logger: Avoid a race condition that would make the test fail

Simon McVittie requested to merge wip/issue128 into main

Previously, we could have this sequence of events:

  1. env subprocess starts
  2. 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.
  3. srt-logger parent process opens log file
  4. srt-logger parent process forks child process to handle logging
  5. srt-logger parent process execs cat
  6. cat reads hello, world\n, writes it to its stdout, and exits
  7. Test waits for cat to exit
  8. Test runs tests/adverb --exclusive-lock which locks the log file
  9. srt-logger child process tries to lock log file, but cannot, so it waits
  10. Test continues, reads empty content from log file, and fails
  11. 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

Merge request reports