tests/testlib/wait-on-file
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 16 Apr 2020 22:56:03 +0200
branchstable
changeset 44739 23dd43d94f50
parent 44727 694d40416d62
child 44763 f727939f3513
permissions -rwxr-xr-x
wait-on-file: adjust the timer counter The wait performed in increment of 0.01 second, but the timer was expressed in second. So we did not wait 20s, we waited 0.2 second. Internally we adjust the counter to be expressed in centisecond. This prevent some flackyness in the test. Differential Revision: https://phab.mercurial-scm.org/D8453
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44635
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     1
#!/bin/bash
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"
44636
82543879b48e testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44635
diff changeset
    13
82543879b48e testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44635
diff changeset
    14
# if the test timeout have been extended, explicitly extend the provided timer
82543879b48e testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44635
diff changeset
    15
if [ "$HGTEST_TIMEOUT_DEFAULT" -lt "$HGTEST_TIMEOUT" ]; then
44739
23dd43d94f50 wait-on-file: adjust the timer counter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44727
diff changeset
    16
    timer=$(( ( 100 * $timer * $HGTEST_TIMEOUT) / $HGTEST_TIMEOUT_DEFAULT ))
44636
82543879b48e testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44635
diff changeset
    17
fi
82543879b48e testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44635
diff changeset
    18
44635
1ed6293fc31b testlib: add a small scrip to help process to synchronise using file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    19
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
    20
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
    21
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
    22
    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
    23
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
    24
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
if [ -n "$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
    26
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
    27
    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
    28
    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
    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
while [ "$timer" -gt 0 ] && [ ! -f "$wait_on" ];
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
do
44727
694d40416d62 wait-on-file: use proper variable in math
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44726
diff changeset
    32
    timer=$(( $timer - 1))
44635
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
    sleep 0.01
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
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
    35
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
    36
    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
    37
    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
    38
fi