tests/testlib/wait-on-file
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 49198 a68b37524d50
permissions -rwxr-xr-x
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44780
f727939f3513 tests: use regular POSIX shell
Joerg Sonnenberger <joerg@bec.de>
parents: 44744
diff changeset
     1
#!/bin/sh
44631
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     2
#
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     3
# wait up to TIMEOUT seconds until a WAIT_ON_FILE is created.
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     4
#
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     5
# In addition, this script can create CREATE_FILE once it is ready to wait.
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     6
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
    echo $#
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     9
    echo "USAGE: $0 TIMEOUT WAIT_ON_FILE [CREATE_FILE]"
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    10
fi
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
timer="$1"
44632
82543879b48e testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44631
diff changeset
    13
44818
9d7d53771e5f tests: fix timer scaling in wait-on-file
Joerg Sonnenberger <joerg@bec.de>
parents: 44780
diff changeset
    14
# Scale the timeout to match the sleep steps below, i.e. 1/0.02.
9d7d53771e5f tests: fix timer scaling in wait-on-file
Joerg Sonnenberger <joerg@bec.de>
parents: 44780
diff changeset
    15
timer=$(( 50 * $timer ))
9d7d53771e5f tests: fix timer scaling in wait-on-file
Joerg Sonnenberger <joerg@bec.de>
parents: 44780
diff changeset
    16
# If the test timeout have been extended, also scale the timer relative
9d7d53771e5f tests: fix timer scaling in wait-on-file
Joerg Sonnenberger <joerg@bec.de>
parents: 44780
diff changeset
    17
# to the normal timing.
44632
82543879b48e testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44631
diff changeset
    18
if [ "$HGTEST_TIMEOUT_DEFAULT" -lt "$HGTEST_TIMEOUT" ]; then
44818
9d7d53771e5f tests: fix timer scaling in wait-on-file
Joerg Sonnenberger <joerg@bec.de>
parents: 44780
diff changeset
    19
    timer=$(( ( $timer * $HGTEST_TIMEOUT) / $HGTEST_TIMEOUT_DEFAULT ))
44632
82543879b48e testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44631
diff changeset
    20
fi
82543879b48e testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44631
diff changeset
    21
44631
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    22
wait_on="$2"
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    23
create=""
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    24
if [ $# -eq 3 ]; then
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    25
    create="$3"
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    26
fi
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    27
44780
f727939f3513 tests: use regular POSIX shell
Joerg Sonnenberger <joerg@bec.de>
parents: 44744
diff changeset
    28
if [ -n "$create" ]; then
44631
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    29
    touch "$create"
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    30
    create=""
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    31
fi
49198
a68b37524d50 wait-on-file: properly wait on any files and symlink
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44818
diff changeset
    32
while [ "$timer" -gt 0 ] && !([ -e "$wait_on" ] || [ -L "$wait_on" ]) ; do
44727
694d40416d62 wait-on-file: use proper variable in math
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44726
diff changeset
    33
    timer=$(( $timer - 1))
44818
9d7d53771e5f tests: fix timer scaling in wait-on-file
Joerg Sonnenberger <joerg@bec.de>
parents: 44780
diff changeset
    34
    sleep 0.02
44631
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    35
done
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    36
if [ "$timer" -le 0 ]; then
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    37
    echo "file not created after $1 seconds: $wait_on" >&2
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    38
    exit 1
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    39
fi