tests/testlib/wait-on-file
branchstable
changeset 44729 26ce8e751503
parent 44727 694d40416d62
child 44739 23dd43d94f50
equal deleted inserted replaced
44220:539490756a72 44729:26ce8e751503
       
     1 #!/bin/bash
       
     2 #
       
     3 # wait up to TIMEOUT seconds until a WAIT_ON_FILE is created.
       
     4 #
       
     5 # In addition, this script can create CREATE_FILE once it is ready to wait.
       
     6 
       
     7 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
       
     8     echo $#
       
     9     echo "USAGE: $0 TIMEOUT WAIT_ON_FILE [CREATE_FILE]"
       
    10 fi
       
    11 
       
    12 timer="$1"
       
    13 
       
    14 # if the test timeout have been extended, explicitly extend the provided timer
       
    15 if [ "$HGTEST_TIMEOUT_DEFAULT" -lt "$HGTEST_TIMEOUT" ]; then
       
    16     timer=$(( ($timer * $HGTEST_TIMEOUT) / $HGTEST_TIMEOUT_DEFAULT ))
       
    17 fi
       
    18 
       
    19 wait_on="$2"
       
    20 create=""
       
    21 if [ $# -eq 3 ]; then
       
    22     create="$3"
       
    23 fi
       
    24 
       
    25 if [ -n "$create" ];
       
    26 then
       
    27     touch "$create"
       
    28     create=""
       
    29 fi
       
    30 while [ "$timer" -gt 0 ] && [ ! -f "$wait_on" ];
       
    31 do
       
    32     timer=$(( $timer - 1))
       
    33     sleep 0.01
       
    34 done
       
    35 if [ "$timer" -le 0 ]; then
       
    36     echo "file not created after $1 seconds: $wait_on" >&2
       
    37     exit 1
       
    38 fi