Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/checkpoint.bats: fix test hang/failure
Commit a9e15e7 adds a check that stdin/out/err pipes are restored correctly. Commit ec26065 copy/pastes the same code to one more another test. Problem is (as pointed out in commit 5369f9a) these tests sometimes hang. I have also seen them fail. Apparently, the code used to create pipes and open them to fds is racy: ```shell cat $fifo | cat $fifo & pid=$! exec 50</proc/$pid/fd/0 exec 51>/proc/$pid/fd/0 ``` Since `cat | cat` is spawned asynchronously, by the time exec is used, the second cat process (i.e. $pid) is already fork'ed but it might not be exec'ed yet. As a result, we get this (`ls -l /proc/self/fd`): ``` lr-x------. 1 root root 64 Apr 20 02:39 50 -> /dev/pts/1 l-wx------. 1 root root 64 Apr 20 02:39 51 -> /dev/pts/1 ``` or, in some cases: ``` lr-x------. 1 root root 64 Apr 20 02:45 50 -> /dev/pts/1 l-wx------. 1 root root 64 Apr 20 02:45 51 -> 'pipe:[215791]' ``` instead of expected set of pipes: ``` > lr-x------. 1 root root 64 Apr 20 02:45 50 -> 'pipe:[215791]' > l-wx------. 1 root root 64 Apr 20 02:45 51 -> 'pipe:[215791]' ``` One possible workaround is to add `sleep 0.1` or so after cat|cat, but it is outright ugly (besides, we already have one sleep in the test code). The solution is to not use any external processes to create pipes. I admit this still looks not very comprehensible, but at least it is easier than before, and it works. While at it, remove code duplication, moving the setup and check code into a pair of functions. Finally, since the tests are working now, remove the skip. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
- Loading branch information