tests/testlib/wait-on-file
author Pulkit Goyal <7895pulkit@gmail.com>
Thu, 16 Apr 2020 22:51:09 +0530
branchstable
changeset 44729 26ce8e751503
parent 44727 694d40416d62
child 44739 23dd43d94f50
permissions -rwxr-xr-x
merge default into stable for 5.4 release
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
44726
2789f25fc2b6 wait-on-file: don't quote arithmetic argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44636
diff changeset
    16
    timer=$(( ($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