tests/testlib/wait-on-file
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 11 Mar 2025 02:29:42 +0100
branchstable
changeset 53042 cdd7bf612c7b
parent 51943 9cfc95e901ec
permissions -rwxr-xr-x
bundle-spec: properly format boolean parameter (issue6960) This was breaking automatic clone bundle generation. This changeset fixes it and add a test to catch it in the future.
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
# 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
    15
# 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
    16
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
    17
    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
    18
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
    19
51943
9cfc95e901ec tests: print the actual timeout value used in `wait-on-file`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49198
diff changeset
    20
max_time=$timer
9cfc95e901ec tests: print the actual timeout value used in `wait-on-file`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49198
diff changeset
    21
9cfc95e901ec tests: print the actual timeout value used in `wait-on-file`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49198
diff changeset
    22
# Scale the timeout to match the sleep steps below, i.e. 1/0.02.
9cfc95e901ec tests: print the actual timeout value used in `wait-on-file`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49198
diff changeset
    23
timer=$(( 50 * $timer ))
9cfc95e901ec tests: print the actual timeout value used in `wait-on-file`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49198
diff changeset
    24
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
    25
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
    26
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
    27
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
    28
    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
    29
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
    30
44780
f727939f3513 tests: use regular POSIX shell
Joerg Sonnenberger <joerg@bec.de>
parents: 44744
diff changeset
    31
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
    32
    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
    33
    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
    34
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
    35
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
    36
    timer=$(( $timer - 1))
44818
9d7d53771e5f tests: fix timer scaling in wait-on-file
Joerg Sonnenberger <joerg@bec.de>
parents: 44780
diff changeset
    37
    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
    38
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
    39
if [ "$timer" -le 0 ]; then
51943
9cfc95e901ec tests: print the actual timeout value used in `wait-on-file`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49198
diff changeset
    40
    echo "file not created after $max_time seconds: $wait_on" >&2
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
    41
    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
    42
fi